From 3d8843f64b901e5bb08a75335e39ab37d2b14a72 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Thu, 12 Mar 2020 16:13:33 -0700 Subject: [PATCH 1/2] fix: Readable error message for invalid file Display an understandable error message when trying to Run Query on a qll file. Closes 201 --- extensions/ql-vscode/src/extension.ts | 8 ++++---- extensions/ql-vscode/src/run-queries.ts | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 847c2e9e8fe..b69938b5c5b 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -56,7 +56,7 @@ let isInstallingOrUpdatingDistribution = false; * * @param excludedCommands List of commands for which we should not register error stubs. */ -function registerErrorStubs(excludedCommands: string[], stubGenerator: (command: string) => () => void) { +function registerErrorStubs(excludedCommands: string[], stubGenerator: (command: string) => () => void): void { // Remove existing stubs errorStubs.forEach(stub => stub.dispose()); @@ -229,7 +229,7 @@ export async function activate(ctx: ExtensionContext): Promise { }); } -async function activateWithInstalledDistribution(ctx: ExtensionContext, distributionManager: DistributionManager) { +async function activateWithInstalledDistribution(ctx: ExtensionContext, distributionManager: DistributionManager): Promise { beganMainExtensionActivation = true; // Remove any error stubs command handlers left over from first part // of activation. @@ -270,7 +270,7 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu await intm.showResults(query, forceReveal, false); } - async function compileAndRunQuery(quickEval: boolean, selectedQuery: Uri | undefined) { + async function compileAndRunQuery(quickEval: boolean, selectedQuery: Uri | undefined): Promise { if (qs !== undefined) { try { const dbItem = await databaseUI.getDatabaseItem(); @@ -294,7 +294,7 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu ctx.subscriptions.push(tmpDirDisposal); - let client = new LanguageClient('CodeQL Language Server', () => spawnIdeServer(qlConfigurationListener), { + const client = new LanguageClient('CodeQL Language Server', () => spawnIdeServer(qlConfigurationListener), { documentSelector: [ { language: 'ql', scheme: 'file' }, { language: 'yaml', scheme: 'file', pattern: '**/qlpack.yml' } diff --git a/extensions/ql-vscode/src/run-queries.ts b/extensions/ql-vscode/src/run-queries.ts index af337ab9b2f..a4ad96ef6aa 100644 --- a/extensions/ql-vscode/src/run-queries.ts +++ b/extensions/ql-vscode/src/run-queries.ts @@ -334,7 +334,11 @@ async function determineSelectedQuery(selectedResourceUri: vscode.Uri | undefine if (queryUri.scheme !== 'file') { throw new Error('Can only run queries that are on disk.'); } - const queryPath = queryUri.fsPath; + const queryPath = queryUri.fsPath || ''; + + if (!queryPath.endsWith('.ql')) { + throw new Error('The selected resource is not a QL file.'); + } // Whether we chose the file from the active editor or from a context menu, // if the same file is open with unsaved changes in the active editor, From a72b22cd61ad02f782b9f2c2b767079adccf71e6 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Tue, 17 Mar 2020 08:54:35 -0700 Subject: [PATCH 2/2] Change error message Co-Authored-By: jcreedcmu --- extensions/ql-vscode/src/run-queries.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ql-vscode/src/run-queries.ts b/extensions/ql-vscode/src/run-queries.ts index a4ad96ef6aa..b999694cd47 100644 --- a/extensions/ql-vscode/src/run-queries.ts +++ b/extensions/ql-vscode/src/run-queries.ts @@ -337,7 +337,7 @@ async function determineSelectedQuery(selectedResourceUri: vscode.Uri | undefine const queryPath = queryUri.fsPath || ''; if (!queryPath.endsWith('.ql')) { - throw new Error('The selected resource is not a QL file.'); + throw new Error('The selected resource is not a CodeQL query file; It should have the extension ".ql".'); } // Whether we chose the file from the active editor or from a context menu,