Skip to content

Commit da0090a

Browse files
committed
Fix ast view and command registration
Two small bugs: 1. The AST view command was viewing the wrong ast when the command was selected from the context menu. It was always selecting the active editor instead of the item selected in the file menu. 2. The `codeql.showLogs` command was not being registered properly. With this change, there is uniform error handling, telemetry, and disposal.
1 parent 66c9879 commit da0090a

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

extensions/ql-vscode/src/contextual/templateProvider.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TextDocument,
1111
Uri
1212
} from 'vscode';
13+
import * as path from 'path';
1314

1415
import { decodeSourceArchiveUri, encodeArchiveBasePath, zipArchiveScheme } from '../archive-filesystem-provider';
1516
import { CodeQLCliServer } from '../cli';
@@ -142,19 +143,19 @@ export class TemplatePrintAstProvider {
142143
async provideAst(
143144
progress: ProgressCallback,
144145
token: CancellationToken,
145-
document?: TextDocument
146+
fileUri?: Uri
146147
): Promise<AstBuilder | undefined> {
147-
if (!document) {
148+
if (!fileUri) {
148149
throw new Error('Cannot view the AST. Please select a valid source file inside a CodeQL database.');
149150
}
150151
const { query, dbUri } = this.shouldCache()
151-
? await this.cache.get(document.uri.toString(), progress, token)
152-
: await this.getAst(document.uri.toString(), progress, token);
152+
? await this.cache.get(fileUri.toString(), progress, token)
153+
: await this.getAst(fileUri.toString(), progress, token);
153154

154155
return new AstBuilder(
155156
query, this.cli,
156157
this.dbm.findDatabaseItem(dbUri)!,
157-
document.fileName
158+
path.basename(fileUri.fsPath),
158159
);
159160
}
160161

extensions/ql-vscode/src/extension.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,11 @@ async function activateWithInstalledDistribution(
974974
}
975975
));
976976

977-
commands.registerCommand('codeQL.showLogs', () => {
978-
logger.show();
979-
});
977+
ctx.subscriptions.push(
978+
commandRunner('codeQL.showLogs', async () => {
979+
logger.show();
980+
})
981+
);
980982

981983
void logger.log('Starting language server.');
982984
ctx.subscriptions.push(client.start());
@@ -999,12 +1001,14 @@ async function activateWithInstalledDistribution(
9991001
ctx.subscriptions.push(astViewer);
10001002
ctx.subscriptions.push(commandRunnerWithProgress('codeQL.viewAst', async (
10011003
progress: ProgressCallback,
1002-
token: CancellationToken
1004+
token: CancellationToken,
1005+
selectedFile: Uri,
10031006
) => {
1007+
10041008
const ast = await templateProvider.provideAst(
10051009
progress,
10061010
token,
1007-
window.activeTextEditor?.document,
1011+
selectedFile ?? window.activeTextEditor?.document.uri,
10081012
);
10091013
if (ast) {
10101014
astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName);

0 commit comments

Comments
 (0)