Skip to content

Commit e380c78

Browse files
committed
Add openQueryText message
This will allow the webview to send a `openQueryText` message, which will open a virtual file to show the query text.
1 parent cd67ce9 commit e380c78

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

extensions/ql-vscode/src/pure/interface-types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ export interface OpenQueryFileMessage {
468468
t: 'openQueryFile';
469469
}
470470

471+
export interface OpenQueryTextMessage {
472+
t: 'openQueryText';
473+
}
474+
471475
export type ToVariantAnalysisMessage =
472476
| SetVariantAnalysisMessage
473477
| SetRepoResultsMessage
@@ -477,4 +481,5 @@ export type FromVariantAnalysisMessage =
477481
| ViewLoadedMsg
478482
| StopVariantAnalysisMessage
479483
| RequestRepositoryResultsMessage
480-
| OpenQueryFileMessage;
484+
| OpenQueryFileMessage
485+
| OpenQueryTextMessage;

extensions/ql-vscode/src/remote-queries/variant-analysis-view.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { commands, ExtensionContext, ViewColumn, window as Window, workspace } from 'vscode';
1+
import { commands, ExtensionContext, Uri, ViewColumn, window as Window, workspace } from 'vscode';
2+
import { URLSearchParams } from 'url';
23
import { AbstractWebview, WebviewPanelConfig } from '../abstract-webview';
34
import { logger } from '../logging';
45
import { FromVariantAnalysisMessage, ToVariantAnalysisMessage } from '../pure/interface-types';
@@ -92,6 +93,9 @@ export class VariantAnalysisView extends AbstractWebview<ToVariantAnalysisMessag
9293
case 'openQueryFile':
9394
await this.openQueryFile();
9495
break;
96+
case 'openQueryText':
97+
await this.openQueryText();
98+
break;
9599
default:
96100
assertNever(msg);
97101
}
@@ -130,4 +134,29 @@ export class VariantAnalysisView extends AbstractWebview<ToVariantAnalysisMessag
130134
void showAndLogWarningMessage(`Could not open file: ${variantAnalysis.query.filePath}`);
131135
}
132136
}
137+
138+
private async openQueryText(): Promise<void> {
139+
const variantAnalysis = await this.manager.getVariantAnalysis(this.variantAnalysisId);
140+
if (!variantAnalysis) {
141+
void showAndLogWarningMessage('Could not open variant analysis query text');
142+
return;
143+
}
144+
145+
const filename = variantAnalysis.query.filePath;
146+
147+
try {
148+
const params = new URLSearchParams({
149+
variantAnalysisId: variantAnalysis.id.toString(),
150+
});
151+
const uri = Uri.from({
152+
scheme: 'codeql-variant-analysis',
153+
path: filename,
154+
query: params.toString(),
155+
});
156+
const doc = await workspace.openTextDocument(uri);
157+
await Window.showTextDocument(doc, { preview: false });
158+
} catch (error) {
159+
void showAndLogWarningMessage('Could not open query text');
160+
}
161+
}
133162
}

0 commit comments

Comments
 (0)