Make query text and file commands consistent
We were using two different implementations for opening the query file and query text between the query history and the results view. This moves the better implementation in the view to a command and uses these commands for opening the query text/file in the query history and view. This results in consistent error messages and behaviour between the two different views.
This commit is contained in:
@@ -1273,6 +1273,24 @@ async function activateWithInstalledDistribution(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ctx.subscriptions.push(
|
||||||
|
commandRunner(
|
||||||
|
"codeQL.openVariantAnalysisQueryText",
|
||||||
|
async (variantAnalysisId: number) => {
|
||||||
|
await variantAnalysisManager.openQueryText(variantAnalysisId);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.subscriptions.push(
|
||||||
|
commandRunner(
|
||||||
|
"codeQL.openVariantAnalysisQueryFile",
|
||||||
|
async (variantAnalysisId: number) => {
|
||||||
|
await variantAnalysisManager.openQueryFile(variantAnalysisId);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
ctx.subscriptions.push(
|
ctx.subscriptions.push(
|
||||||
commandRunner("codeQL.openReferencedFile", openReferencedFile),
|
commandRunner("codeQL.openReferencedFile", openReferencedFile),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -826,6 +826,14 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (finalSingleItem.t === "variant-analysis") {
|
||||||
|
await commands.executeCommand(
|
||||||
|
"codeQL.openVariantAnalysisQueryFile",
|
||||||
|
finalSingleItem.variantAnalysis.id,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let queryPath: string;
|
let queryPath: string;
|
||||||
switch (finalSingleItem.t) {
|
switch (finalSingleItem.t) {
|
||||||
case "local":
|
case "local":
|
||||||
@@ -834,9 +842,6 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
case "remote":
|
case "remote":
|
||||||
queryPath = finalSingleItem.remoteQuery.queryFilePath;
|
queryPath = finalSingleItem.remoteQuery.queryFilePath;
|
||||||
break;
|
break;
|
||||||
case "variant-analysis":
|
|
||||||
queryPath = finalSingleItem.variantAnalysis.query.filePath;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
assertNever(finalSingleItem);
|
assertNever(finalSingleItem);
|
||||||
}
|
}
|
||||||
@@ -1340,6 +1345,14 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (finalSingleItem.t === "variant-analysis") {
|
||||||
|
await commands.executeCommand(
|
||||||
|
"codeQL.openVariantAnalysisQueryText",
|
||||||
|
finalSingleItem.variantAnalysis.id,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
isQuickEval: String(
|
isQuickEval: String(
|
||||||
!!(
|
!!(
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import {
|
|||||||
EventEmitter,
|
EventEmitter,
|
||||||
ExtensionContext,
|
ExtensionContext,
|
||||||
Uri,
|
Uri,
|
||||||
|
ViewColumn,
|
||||||
|
window as Window,
|
||||||
|
workspace,
|
||||||
} from "vscode";
|
} from "vscode";
|
||||||
import { DisposableObject } from "../pure/disposable-object";
|
import { DisposableObject } from "../pure/disposable-object";
|
||||||
import { Credentials } from "../authentication";
|
import { Credentials } from "../authentication";
|
||||||
@@ -43,6 +46,7 @@ import {
|
|||||||
createTimestampFile,
|
createTimestampFile,
|
||||||
showAndLogErrorMessage,
|
showAndLogErrorMessage,
|
||||||
showAndLogInformationMessage,
|
showAndLogInformationMessage,
|
||||||
|
showAndLogWarningMessage,
|
||||||
} from "../helpers";
|
} from "../helpers";
|
||||||
import { readFile, readJson, remove, pathExists, outputJson } from "fs-extra";
|
import { readFile, readJson, remove, pathExists, outputJson } from "fs-extra";
|
||||||
import { EOL } from "os";
|
import { EOL } from "os";
|
||||||
@@ -54,6 +58,7 @@ import {
|
|||||||
filterAndSortRepositoriesWithResults,
|
filterAndSortRepositoriesWithResults,
|
||||||
RepositoriesFilterSortStateWithIds,
|
RepositoriesFilterSortStateWithIds,
|
||||||
} from "../pure/variant-analysis-filter-sort";
|
} from "../pure/variant-analysis-filter-sort";
|
||||||
|
import { URLSearchParams } from "url";
|
||||||
|
|
||||||
export class VariantAnalysisManager
|
export class VariantAnalysisManager
|
||||||
extends DisposableObject
|
extends DisposableObject
|
||||||
@@ -267,6 +272,57 @@ export class VariantAnalysisManager
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async openQueryText(variantAnalysisId: number): Promise<void> {
|
||||||
|
const variantAnalysis = await this.getVariantAnalysis(variantAnalysisId);
|
||||||
|
if (!variantAnalysis) {
|
||||||
|
void showAndLogWarningMessage(
|
||||||
|
"Could not open variant analysis query text. Variant analysis not found.",
|
||||||
|
);
|
||||||
|
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 variant analysis query text. Failed to open text document.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async openQueryFile(variantAnalysisId: number): Promise<void> {
|
||||||
|
const variantAnalysis = await this.getVariantAnalysis(variantAnalysisId);
|
||||||
|
|
||||||
|
if (!variantAnalysis) {
|
||||||
|
void showAndLogWarningMessage(
|
||||||
|
"Could not open variant analysis query file",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const textDocument = await workspace.openTextDocument(
|
||||||
|
variantAnalysis.query.filePath,
|
||||||
|
);
|
||||||
|
await Window.showTextDocument(textDocument, ViewColumn.One);
|
||||||
|
} catch (error) {
|
||||||
|
void showAndLogWarningMessage(
|
||||||
|
`Could not open file: ${variantAnalysis.query.filePath}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public registerView(view: VariantAnalysisView): void {
|
public registerView(view: VariantAnalysisView): void {
|
||||||
if (this.views.has(view.variantAnalysisId)) {
|
if (this.views.has(view.variantAnalysisId)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
@@ -1,12 +1,4 @@
|
|||||||
import {
|
import { commands, ExtensionContext, Uri, ViewColumn } from "vscode";
|
||||||
commands,
|
|
||||||
ExtensionContext,
|
|
||||||
Uri,
|
|
||||||
ViewColumn,
|
|
||||||
window as Window,
|
|
||||||
workspace,
|
|
||||||
} from "vscode";
|
|
||||||
import { URLSearchParams } from "url";
|
|
||||||
import { AbstractWebview, WebviewPanelConfig } from "../abstract-webview";
|
import { AbstractWebview, WebviewPanelConfig } from "../abstract-webview";
|
||||||
import { extLogger } from "../common";
|
import { extLogger } from "../common";
|
||||||
import {
|
import {
|
||||||
@@ -129,10 +121,16 @@ export class VariantAnalysisView
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "openQueryFile":
|
case "openQueryFile":
|
||||||
await this.openQueryFile();
|
void commands.executeCommand(
|
||||||
|
"codeQL.openVariantAnalysisQueryFile",
|
||||||
|
this.variantAnalysisId,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "openQueryText":
|
case "openQueryText":
|
||||||
await this.openQueryText();
|
void commands.executeCommand(
|
||||||
|
"codeQL.openVariantAnalysisQueryText",
|
||||||
|
this.variantAnalysisId,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "copyRepositoryList":
|
case "copyRepositoryList":
|
||||||
void commands.executeCommand(
|
void commands.executeCommand(
|
||||||
@@ -186,61 +184,6 @@ export class VariantAnalysisView
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async openQueryFile(): Promise<void> {
|
|
||||||
const variantAnalysis = await this.manager.getVariantAnalysis(
|
|
||||||
this.variantAnalysisId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!variantAnalysis) {
|
|
||||||
void showAndLogWarningMessage(
|
|
||||||
"Could not open variant analysis query file",
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const textDocument = await workspace.openTextDocument(
|
|
||||||
variantAnalysis.query.filePath,
|
|
||||||
);
|
|
||||||
await Window.showTextDocument(textDocument, ViewColumn.One);
|
|
||||||
} catch (error) {
|
|
||||||
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. Variant analysis not found.",
|
|
||||||
);
|
|
||||||
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 variant analysis query text. Failed to open text document.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async openLogs(): Promise<void> {
|
private async openLogs(): Promise<void> {
|
||||||
const variantAnalysis = await this.manager.getVariantAnalysis(
|
const variantAnalysis = await this.manager.getVariantAnalysis(
|
||||||
this.variantAnalysisId,
|
this.variantAnalysisId,
|
||||||
|
|||||||
Reference in New Issue
Block a user