Skip to content
Permalink
Browse files
Lint Checking (#102)
* Create typescript github action. Create lint rule for indents

* Fix lint issues
  • Loading branch information
Shanedell committed Aug 25, 2021
1 parent e7e3045 commit ae9d6acd93f9b71d4782e0416831fb4fe17ec0e7
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 346 deletions.
@@ -0,0 +1,5 @@
# Ignore artifacts
build
coverage
out
dist
@@ -14,6 +14,7 @@
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
"semi": "off",
"indent": [2, "tab", {"SwitchCase": 1}]
}
}
@@ -28,7 +28,8 @@
"vscode:prepublish": "yarn run package-ext",
"precompile": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
"compile": "tsc -p ./",
"lint": "eslint src --ext ts",
"lint": "eslint src --ext .ts",
"fix-lint": "eslint src --ext .ts --fix",
"watch": "webpack --watch --devtool nosources-source-map --info-verbosity verbose --config ./build/extension.webpack.config.js",
"watch2": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
@@ -254,4 +255,4 @@
}
]
}
}
}
@@ -48,18 +48,18 @@ function createDebugRunFileConfigs(resource: vscode.Uri, runOrDebug: String) {
let infosetFile = `${path.basename(targetResource.fsPath).split(".")[0]}-infoset.xml`;

vscode.debug.startDebugging(undefined, {
type: 'dfdl',
name: 'Run File',
request: 'launch',
program: targetResource.fsPath,
data: "${command:AskForDataName}",
debugServer: 4711,
infosetOutput: {
type: "file",
path: infosetFile
}
},
{ noDebug: noDebug }
type: 'dfdl',
name: 'Run File',
request: 'launch',
program: targetResource.fsPath,
data: "${command:AskForDataName}",
debugServer: 4711,
infosetOutput: {
type: "file",
path: infosetFile
}
},
{ noDebug: noDebug }
);

vscode.debug.onDidTerminateDebugSession(async () => {
@@ -91,17 +91,17 @@ export function activateDaffodilDebug(context: vscode.ExtensionContext, factory?
context.subscriptions.push(vscode.commands.registerCommand('extension.dfdl-debug.getProgramName', async (config) => {
// Open native file explorer to allow user to select data file from anywhere on their machine
let programFile = await vscode.window.showOpenDialog({
canSelectMany: false, openLabel: "Select DFDL schema to debug",
canSelectFiles: true, canSelectFolders: false,
canSelectMany: false, openLabel: "Select DFDL schema to debug",
canSelectFiles: true, canSelectFolders: false,
title: "Select DFDL schema to debug"
})
.then(fileUri => {
if (fileUri && fileUri[0]) {
return fileUri[0].fsPath;
}
})
.then(fileUri => {
if (fileUri && fileUri[0]) {
return fileUri[0].fsPath;
}

return "";
});
return "";
});

// Create file that holds path to program file used
await fs.writeFile(`${xdgAppPaths.data()}/.programFile`, programFile, function(err){
@@ -128,17 +128,17 @@ export function activateDaffodilDebug(context: vscode.ExtensionContext, factory?

// Open native file explorer to allow user to select data file from anywhere on their machine
let dataFile = await vscode.window.showOpenDialog({
canSelectMany: false, openLabel: "Select input data file to debug",
canSelectFiles: true, canSelectFolders: false,
canSelectMany: false, openLabel: "Select input data file to debug",
canSelectFiles: true, canSelectFolders: false,
title: "Select input data file to debug"
})
.then(fileUri => {
if (fileUri && fileUri[0]) {
return fileUri[0].fsPath;
}
})
.then(fileUri => {
if (fileUri && fileUri[0]) {
return fileUri[0].fsPath;
}

return "";
});
return "";
});

// If data file not selected stop launch
if (dataFile === "") {
@@ -552,11 +552,11 @@ export class DaffodilDebugSession extends LoggingDebugSession {
protected dataBreakpointInfoRequest(response: DebugProtocol.DataBreakpointInfoResponse, args: DebugProtocol.DataBreakpointInfoArguments): void {

response.body = {
dataId: null,
description: "cannot break on data access",
accessTypes: undefined,
canPersist: false
};
dataId: null,
description: "cannot break on data access",
accessTypes: undefined,
canPersist: false
};

if (args.variablesReference && args.name) {
const id = this._variableHandles.get(args.variablesReference);
@@ -10,11 +10,11 @@ import XDGAppPaths from 'xdg-app-paths';
const xdgAppPaths = XDGAppPaths({ "name": "dapodil" });

class Backend {
constructor(readonly owner: string, readonly repo: string) { }
constructor(readonly owner: string, readonly repo: string) { }
}

class Artifact {
constructor(readonly daffodilVersion: string, readonly version: string = LIB_VERSION) { }
constructor(readonly daffodilVersion: string, readonly version: string = LIB_VERSION) { }

name = `daffodil-debugger-${this.daffodilVersion}-${this.version}`;
archive = `${this.name}.zip`;
@@ -35,98 +35,98 @@ export class Release {
nodeId: string;

constructor(name: string, zipballUrl: string, tarballUrl: string, commit: JSON, nodeId: string) {
this.name = name;
this.zipballUrl = zipballUrl;
this.tarballUrl = tarballUrl;
this.commit = commit;
this.nodeId = nodeId;
this.name = name;
this.zipballUrl = zipballUrl;
this.tarballUrl = tarballUrl;
this.commit = commit;
this.nodeId = nodeId;
}
}

// Function to get data file given a folder
export async function getDataFileFromFolder(dataFolder: string) {
return await vscode.window.showOpenDialog({
canSelectMany: false, openLabel: 'Select',
canSelectFiles: true, canSelectFolders: false, defaultUri: vscode.Uri.parse(dataFolder)
})
.then(fileUri => {
if (fileUri && fileUri[0]) {
return fileUri[0].fsPath;
}
});
return await vscode.window.showOpenDialog({
canSelectMany: false, openLabel: 'Select',
canSelectFiles: true, canSelectFolders: false, defaultUri: vscode.Uri.parse(dataFolder)
})
.then(fileUri => {
if (fileUri && fileUri[0]) {
return fileUri[0].fsPath;
}
});
}

// Function for getting the daffodil-debugger
export async function getDebugger(config: vscode.DebugConfiguration) {
// If useExistingServer var set to false make sure version of debugger entered is downloaded then ran
if (!config.useExistingServer) {
const delay = ms => new Promise(res => setTimeout(res, ms));

if (vscode.workspace.workspaceFolders !== undefined) {
let rootPath = xdgAppPaths.data();

// If directory for storing debugger does exist create it
if (!fs.existsSync(rootPath)) {
fs.mkdirSync(rootPath);
}

// Code for downloading and setting up daffodil-debugger files
if (!fs.existsSync(`${rootPath}/${artifact.name}`)) {
// Get daffodil-debugger of version entered using http client
const client = new HttpClient("client"); // TODO: supply daffodil version from config
const artifactUrl = artifact.archiveUrl(backend);
const response = await client.get(artifactUrl);

if (response.message.statusCode !== 200) {
const err: Error = new Error(`Couldn't download the Daffodil debugger backend from ${artifactUrl}.`);
err["httpStatusCode"] = response.message.statusCode;
throw err;
}

// Create zip from rest call
const filePath = `${rootPath}/${artifact.archive}}`;
const file = fs.createWriteStream(filePath);

await new Promise((res, rej) => {
file.on("error", (err) => function () { throw err; });
const stream = response.message.pipe(file);
stream.on("close", () => {
try { res(filePath); } catch (err) { rej(err); }
});
});

// Unzip file and remove zip file
await new Promise((res, rej) => {
let stream = fs.createReadStream(filePath).pipe(unzip.Extract({ path: `${rootPath}` }));
stream.on("close", () => {
try { res(filePath); } catch (err) { rej(err); }
});
});
fs.unlinkSync(filePath);
}

// Stop debugger if running
if (os.platform() === 'win32') {
// Windows stop debugger if already running
child_process.execSync('tskill java 2>nul 1>nul || echo "Java not running"');
}
else {
// Linux/Mac stop debugger if already running and make sure script is executable
child_process.exec("kill -9 $(ps -ef | grep 'daffodil' | grep 'jar' | awk '{ print $2 }') || return 0"); // ensure debugger server not running and
child_process.execSync(`chmod +x ${rootPath.replace(" ", "\\ ")}/${artifact.name}/bin/${artifact.scriptName}`); // make sure debugger is executable
}

// Start debugger in terminal based on scriptName
let terminal = vscode.window.createTerminal({
name: artifact.scriptName,
cwd: `${rootPath}/daffodil-debugger-${daffodilVersion}-${LIB_VERSION}/bin/`,
hideFromUser: false,
shellPath: artifact.scriptName,
});
terminal.show();

// Wait for 5000 ms to make sure debugger is running before the extension tries to connect to it
await delay(5000);
}
}
// If useExistingServer var set to false make sure version of debugger entered is downloaded then ran
if (!config.useExistingServer) {
const delay = ms => new Promise(res => setTimeout(res, ms));

if (vscode.workspace.workspaceFolders !== undefined) {
let rootPath = xdgAppPaths.data();

// If directory for storing debugger does exist create it
if (!fs.existsSync(rootPath)) {
fs.mkdirSync(rootPath);
}

// Code for downloading and setting up daffodil-debugger files
if (!fs.existsSync(`${rootPath}/${artifact.name}`)) {
// Get daffodil-debugger of version entered using http client
const client = new HttpClient("client"); // TODO: supply daffodil version from config
const artifactUrl = artifact.archiveUrl(backend);
const response = await client.get(artifactUrl);

if (response.message.statusCode !== 200) {
const err: Error = new Error(`Couldn't download the Daffodil debugger backend from ${artifactUrl}.`);
err["httpStatusCode"] = response.message.statusCode;
throw err;
}

// Create zip from rest call
const filePath = `${rootPath}/${artifact.archive}}`;
const file = fs.createWriteStream(filePath);

await new Promise((res, rej) => {
file.on("error", (err) => function () { throw err; });
const stream = response.message.pipe(file);
stream.on("close", () => {
try { res(filePath); } catch (err) { rej(err); }
});
});

// Unzip file and remove zip file
await new Promise((res, rej) => {
let stream = fs.createReadStream(filePath).pipe(unzip.Extract({ path: `${rootPath}` }));
stream.on("close", () => {
try { res(filePath); } catch (err) { rej(err); }
});
});
fs.unlinkSync(filePath);
}

// Stop debugger if running
if (os.platform() === 'win32') {
// Windows stop debugger if already running
child_process.execSync('tskill java 2>nul 1>nul || echo "Java not running"');
}
else {
// Linux/Mac stop debugger if already running and make sure script is executable
child_process.exec("kill -9 $(ps -ef | grep 'daffodil' | grep 'jar' | awk '{ print $2 }') || return 0"); // ensure debugger server not running and
child_process.execSync(`chmod +x ${rootPath.replace(" ", "\\ ")}/${artifact.name}/bin/${artifact.scriptName}`); // make sure debugger is executable
}

// Start debugger in terminal based on scriptName
let terminal = vscode.window.createTerminal({
name: artifact.scriptName,
cwd: `${rootPath}/daffodil-debugger-${daffodilVersion}-${LIB_VERSION}/bin/`,
hideFromUser: false,
shellPath: artifact.scriptName,
});
terminal.show();

// Wait for 5000 ms to make sure debugger is running before the extension tries to connect to it
await delay(5000);
}
}
}

0 comments on commit ae9d6ac

Please sign in to comment.