Add openQueryText message
This will allow the webview to send a `openQueryText` message, which will open a virtual file to show the query text.
This commit is contained in:
@@ -468,6 +468,10 @@ export interface OpenQueryFileMessage {
|
||||
t: 'openQueryFile';
|
||||
}
|
||||
|
||||
export interface OpenQueryTextMessage {
|
||||
t: 'openQueryText';
|
||||
}
|
||||
|
||||
export type ToVariantAnalysisMessage =
|
||||
| SetVariantAnalysisMessage
|
||||
| SetRepoResultsMessage
|
||||
@@ -477,4 +481,5 @@ export type FromVariantAnalysisMessage =
|
||||
| ViewLoadedMsg
|
||||
| StopVariantAnalysisMessage
|
||||
| RequestRepositoryResultsMessage
|
||||
| OpenQueryFileMessage;
|
||||
| OpenQueryFileMessage
|
||||
| OpenQueryTextMessage;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { commands, ExtensionContext, ViewColumn, window as Window, workspace } from 'vscode';
|
||||
import { commands, ExtensionContext, Uri, ViewColumn, window as Window, workspace } from 'vscode';
|
||||
import { URLSearchParams } from 'url';
|
||||
import { AbstractWebview, WebviewPanelConfig } from '../abstract-webview';
|
||||
import { logger } from '../logging';
|
||||
import { FromVariantAnalysisMessage, ToVariantAnalysisMessage } from '../pure/interface-types';
|
||||
@@ -92,6 +93,9 @@ export class VariantAnalysisView extends AbstractWebview<ToVariantAnalysisMessag
|
||||
case 'openQueryFile':
|
||||
await this.openQueryFile();
|
||||
break;
|
||||
case 'openQueryText':
|
||||
await this.openQueryText();
|
||||
break;
|
||||
default:
|
||||
assertNever(msg);
|
||||
}
|
||||
@@ -130,4 +134,29 @@ export class VariantAnalysisView extends AbstractWebview<ToVariantAnalysisMessag
|
||||
void showAndLogWarningMessage(`Could not open file: ${variantAnalysis.query.filePath}`);
|
||||
}
|
||||
}
|
||||
|
||||
private async openQueryText(): Promise<void> {
|
||||
const variantAnalysis = await this.manager.getVariantAnalysis(this.variantAnalysisId);
|
||||
if (!variantAnalysis) {
|
||||
void showAndLogWarningMessage('Could not open variant analysis query text');
|
||||
return;
|
||||
}
|
||||
|
||||
const filename = variantAnalysis.query.filePath;
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
variantAnalysisId: variantAnalysis.id.toString(),
|
||||
});
|
||||
const uri = Uri.from({
|
||||
scheme: 'codeql-variant-analysis',
|
||||
path: filename,
|
||||
query: params.toString(),
|
||||
});
|
||||
const doc = await workspace.openTextDocument(uri);
|
||||
await Window.showTextDocument(doc, { preview: false });
|
||||
} catch (error) {
|
||||
void showAndLogWarningMessage('Could not open query text');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user