Merge pull request #2217 from github/robertbrignull/use_app_commands_1
Convert call sites to use typed commands (part 1)
This commit is contained in:
@@ -9,7 +9,7 @@ import { Readable } from "stream";
|
|||||||
import { StringDecoder } from "string_decoder";
|
import { StringDecoder } from "string_decoder";
|
||||||
import tk from "tree-kill";
|
import tk from "tree-kill";
|
||||||
import { promisify } from "util";
|
import { promisify } from "util";
|
||||||
import { CancellationToken, commands, Disposable, Uri } from "vscode";
|
import { CancellationToken, Disposable, Uri } from "vscode";
|
||||||
|
|
||||||
import { BQRSInfo, DecodedBqrsChunk } from "./pure/bqrs-cli-types";
|
import { BQRSInfo, DecodedBqrsChunk } from "./pure/bqrs-cli-types";
|
||||||
import { allowCanaryQueryServer, CliConfig } from "./config";
|
import { allowCanaryQueryServer, CliConfig } from "./config";
|
||||||
@@ -1375,7 +1375,7 @@ export class CodeQLCliServer implements Disposable {
|
|||||||
if (!this._version) {
|
if (!this._version) {
|
||||||
this._version = this.refreshVersion();
|
this._version = this.refreshVersion();
|
||||||
// this._version is only undefined upon config change, so we reset CLI-based context key only when necessary.
|
// this._version is only undefined upon config change, so we reset CLI-based context key only when necessary.
|
||||||
await commands.executeCommand(
|
await this.app.commands.execute(
|
||||||
"setContext",
|
"setContext",
|
||||||
"codeql.supportsEvalLog",
|
"codeql.supportsEvalLog",
|
||||||
await this.cliConstraints.supportsPerQueryEvalLog(),
|
await this.cliConstraints.supportsPerQueryEvalLog(),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { CommandManager } from "../packages/commands";
|
import type { CommandManager } from "../packages/commands";
|
||||||
import type { Uri, Range } from "vscode";
|
import type { Uri, Range, TextDocumentShowOptions } from "vscode";
|
||||||
import type { AstItem } from "../astViewer";
|
import type { AstItem } from "../astViewer";
|
||||||
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
|
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
|
||||||
import type { DatabaseItem } from "../local-databases";
|
import type { DatabaseItem } from "../local-databases";
|
||||||
@@ -35,12 +35,22 @@ export type SingleSelectionCommandFunction<Item> = (
|
|||||||
// Builtin commands where the implementation is provided by VS Code and not by this extension.
|
// Builtin commands where the implementation is provided by VS Code and not by this extension.
|
||||||
// See https://code.visualstudio.com/api/references/commands
|
// See https://code.visualstudio.com/api/references/commands
|
||||||
export type BuiltInVsCodeCommands = {
|
export type BuiltInVsCodeCommands = {
|
||||||
|
// The codeQLDatabases.focus command is provided by VS Code because we've registered the custom view
|
||||||
|
"codeQLDatabases.focus": () => Promise<void>;
|
||||||
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
|
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
|
||||||
setContext: (
|
setContext: (
|
||||||
key: `${"codeql" | "codeQL"}${string}`,
|
key: `${"codeql" | "codeQL"}${string}`,
|
||||||
value: unknown,
|
value: unknown,
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
"workbench.action.reloadWindow": () => Promise<void>;
|
"workbench.action.reloadWindow": () => Promise<void>;
|
||||||
|
"vscode.diff": (
|
||||||
|
leftSideResource: Uri,
|
||||||
|
rightSideResource: Uri,
|
||||||
|
title?: string,
|
||||||
|
columnOrOptions?: TextDocumentShowOptions,
|
||||||
|
) => Promise<void>;
|
||||||
|
"vscode.open": (uri: Uri) => Promise<void>;
|
||||||
|
"vscode.openFolder": (uri: Uri) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Commands that are available before the extension is fully activated.
|
// Commands that are available before the extension is fully activated.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetch, { Response } from "node-fetch";
|
import fetch, { Response } from "node-fetch";
|
||||||
import { zip } from "zip-a-folder";
|
import { zip } from "zip-a-folder";
|
||||||
import { Open } from "unzipper";
|
import { Open } from "unzipper";
|
||||||
import { Uri, CancellationToken, commands, window } from "vscode";
|
import { Uri, CancellationToken, window } from "vscode";
|
||||||
import { CodeQLCliServer } from "./cli";
|
import { CodeQLCliServer } from "./cli";
|
||||||
import {
|
import {
|
||||||
ensureDir,
|
ensureDir,
|
||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
isValidGitHubNwo,
|
isValidGitHubNwo,
|
||||||
} from "./common/github-url-identifier-helper";
|
} from "./common/github-url-identifier-helper";
|
||||||
import { Credentials } from "./common/authentication";
|
import { Credentials } from "./common/authentication";
|
||||||
|
import { AppCommandManager } from "./common/commands";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
|
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
|
||||||
@@ -34,6 +35,7 @@ import { Credentials } from "./common/authentication";
|
|||||||
* @param storagePath where to store the unzipped database.
|
* @param storagePath where to store the unzipped database.
|
||||||
*/
|
*/
|
||||||
export async function promptImportInternetDatabase(
|
export async function promptImportInternetDatabase(
|
||||||
|
commandManager: AppCommandManager,
|
||||||
databaseManager: DatabaseManager,
|
databaseManager: DatabaseManager,
|
||||||
storagePath: string,
|
storagePath: string,
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
@@ -61,7 +63,7 @@ export async function promptImportInternetDatabase(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (item) {
|
if (item) {
|
||||||
await commands.executeCommand("codeQLDatabases.focus");
|
await commandManager.execute("codeQLDatabases.focus");
|
||||||
void showAndLogInformationMessage(
|
void showAndLogInformationMessage(
|
||||||
"Database downloaded and imported successfully.",
|
"Database downloaded and imported successfully.",
|
||||||
);
|
);
|
||||||
@@ -78,6 +80,7 @@ export async function promptImportInternetDatabase(
|
|||||||
* @param storagePath where to store the unzipped database.
|
* @param storagePath where to store the unzipped database.
|
||||||
*/
|
*/
|
||||||
export async function promptImportGithubDatabase(
|
export async function promptImportGithubDatabase(
|
||||||
|
commandManager: AppCommandManager,
|
||||||
databaseManager: DatabaseManager,
|
databaseManager: DatabaseManager,
|
||||||
storagePath: string,
|
storagePath: string,
|
||||||
credentials: Credentials | undefined,
|
credentials: Credentials | undefined,
|
||||||
@@ -141,7 +144,7 @@ export async function promptImportGithubDatabase(
|
|||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
if (item) {
|
if (item) {
|
||||||
await commands.executeCommand("codeQLDatabases.focus");
|
await commandManager.execute("codeQLDatabases.focus");
|
||||||
void showAndLogInformationMessage(
|
void showAndLogInformationMessage(
|
||||||
"Database downloaded and imported successfully.",
|
"Database downloaded and imported successfully.",
|
||||||
);
|
);
|
||||||
@@ -158,6 +161,7 @@ export async function promptImportGithubDatabase(
|
|||||||
* @param storagePath where to store the unzipped database.
|
* @param storagePath where to store the unzipped database.
|
||||||
*/
|
*/
|
||||||
export async function importArchiveDatabase(
|
export async function importArchiveDatabase(
|
||||||
|
commandManager: AppCommandManager,
|
||||||
databaseUrl: string,
|
databaseUrl: string,
|
||||||
databaseManager: DatabaseManager,
|
databaseManager: DatabaseManager,
|
||||||
storagePath: string,
|
storagePath: string,
|
||||||
@@ -177,7 +181,7 @@ export async function importArchiveDatabase(
|
|||||||
cli,
|
cli,
|
||||||
);
|
);
|
||||||
if (item) {
|
if (item) {
|
||||||
await commands.executeCommand("codeQLDatabases.focus");
|
await commandManager.execute("codeQLDatabases.focus");
|
||||||
void showAndLogInformationMessage(
|
void showAndLogInformationMessage(
|
||||||
"Database unzipped and imported successfully.",
|
"Database unzipped and imported successfully.",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export class DbModule extends DisposableObject {
|
|||||||
|
|
||||||
await this.dbConfigStore.initialize();
|
await this.dbConfigStore.initialize();
|
||||||
|
|
||||||
this.dbPanel = new DbPanel(this.dbManager, app.credentials);
|
this.dbPanel = new DbPanel(app, this.dbManager);
|
||||||
|
|
||||||
this.push(this.dbPanel);
|
this.push(this.dbPanel);
|
||||||
this.push(this.dbConfigStore);
|
this.push(this.dbConfigStore);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
commands,
|
|
||||||
QuickPickItem,
|
QuickPickItem,
|
||||||
TreeView,
|
TreeView,
|
||||||
TreeViewExpansionEvent,
|
TreeViewExpansionEvent,
|
||||||
@@ -31,8 +30,8 @@ import { DbTreeViewItem } from "./db-tree-view-item";
|
|||||||
import { getGitHubUrl } from "./db-tree-view-item-action";
|
import { getGitHubUrl } from "./db-tree-view-item-action";
|
||||||
import { getControllerRepo } from "../../variant-analysis/run-remote-query";
|
import { getControllerRepo } from "../../variant-analysis/run-remote-query";
|
||||||
import { getErrorMessage } from "../../pure/helpers-pure";
|
import { getErrorMessage } from "../../pure/helpers-pure";
|
||||||
import { Credentials } from "../../common/authentication";
|
|
||||||
import { DatabasePanelCommands } from "../../common/commands";
|
import { DatabasePanelCommands } from "../../common/commands";
|
||||||
|
import { App } from "../../common/app";
|
||||||
|
|
||||||
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
|
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
|
||||||
kind: string;
|
kind: string;
|
||||||
@@ -47,8 +46,8 @@ export class DbPanel extends DisposableObject {
|
|||||||
private readonly treeView: TreeView<DbTreeViewItem>;
|
private readonly treeView: TreeView<DbTreeViewItem>;
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
|
private readonly app: App,
|
||||||
private readonly dbManager: DbManager,
|
private readonly dbManager: DbManager,
|
||||||
private readonly credentials: Credentials,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -369,13 +368,13 @@ export class DbPanel extends DisposableObject {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await commands.executeCommand("vscode.open", Uri.parse(githubUrl));
|
await this.app.commands.execute("vscode.open", Uri.parse(githubUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setupControllerRepository(): Promise<void> {
|
private async setupControllerRepository(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// This will also validate that the controller repository is valid
|
// This will also validate that the controller repository is valid
|
||||||
await getControllerRepo(this.credentials);
|
await getControllerRepo(this.app.credentials);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
if (e instanceof UserCancellationException) {
|
if (e instanceof UserCancellationException) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ async function installOrUpdateThenTryActivate(
|
|||||||
await installOrUpdateDistribution(ctx, app, distributionManager, config);
|
await installOrUpdateDistribution(ctx, app, distributionManager, config);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prepareCodeTour();
|
await prepareCodeTour(app.commands);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
void extLogger.log(
|
void extLogger.log(
|
||||||
`Could not open tutorial workspace automatically: ${getErrorMessage(e)}`,
|
`Could not open tutorial workspace automatically: ${getErrorMessage(e)}`,
|
||||||
@@ -669,7 +669,12 @@ async function activateWithInstalledDistribution(
|
|||||||
ctx.subscriptions.push(statusBar);
|
ctx.subscriptions.push(statusBar);
|
||||||
|
|
||||||
void extLogger.log("Initializing query server client.");
|
void extLogger.log("Initializing query server client.");
|
||||||
const qs = await createQueryServer(qlConfigurationListener, cliServer, ctx);
|
const qs = await createQueryServer(
|
||||||
|
app,
|
||||||
|
qlConfigurationListener,
|
||||||
|
cliServer,
|
||||||
|
ctx,
|
||||||
|
);
|
||||||
|
|
||||||
for (const glob of PACK_GLOBS) {
|
for (const glob of PACK_GLOBS) {
|
||||||
const fsWatcher = workspace.createFileSystemWatcher(glob);
|
const fsWatcher = workspace.createFileSystemWatcher(glob);
|
||||||
@@ -680,7 +685,7 @@ async function activateWithInstalledDistribution(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void extLogger.log("Initializing database manager.");
|
void extLogger.log("Initializing database manager.");
|
||||||
const dbm = new DatabaseManager(ctx, qs, cliServer, extLogger);
|
const dbm = new DatabaseManager(ctx, app, qs, cliServer, extLogger);
|
||||||
|
|
||||||
// Let this run async.
|
// Let this run async.
|
||||||
void dbm.loadPersistedState();
|
void dbm.loadPersistedState();
|
||||||
@@ -853,7 +858,7 @@ async function activateWithInstalledDistribution(
|
|||||||
);
|
);
|
||||||
ctx.subscriptions.push(testAdapterFactory);
|
ctx.subscriptions.push(testAdapterFactory);
|
||||||
|
|
||||||
const testUIService = new TestUIService(testHub);
|
const testUIService = new TestUIService(app, testHub);
|
||||||
ctx.subscriptions.push(testUIService);
|
ctx.subscriptions.push(testUIService);
|
||||||
|
|
||||||
testUiCommands = testUIService.getCommands();
|
testUiCommands = testUIService.getCommands();
|
||||||
@@ -881,6 +886,7 @@ async function activateWithInstalledDistribution(
|
|||||||
const allCommands: AllExtensionCommands = {
|
const allCommands: AllExtensionCommands = {
|
||||||
...getCommands(app, cliServer, qs),
|
...getCommands(app, cliServer, qs),
|
||||||
...getQueryEditorCommands({
|
...getQueryEditorCommands({
|
||||||
|
commandManager: app.commands,
|
||||||
queryRunner: qs,
|
queryRunner: qs,
|
||||||
cliServer,
|
cliServer,
|
||||||
qhelpTmpDir: qhelpTmpDir.name,
|
qhelpTmpDir: qhelpTmpDir.name,
|
||||||
@@ -1046,6 +1052,7 @@ function addUnhandledRejectionListener() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createQueryServer(
|
async function createQueryServer(
|
||||||
|
app: ExtensionApp,
|
||||||
qlConfigurationListener: QueryServerConfigListener,
|
qlConfigurationListener: QueryServerConfigListener,
|
||||||
cliServer: CodeQLCliServer,
|
cliServer: CodeQLCliServer,
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
@@ -1076,6 +1083,7 @@ async function createQueryServer(
|
|||||||
return new NewQueryRunner(qs);
|
return new NewQueryRunner(qs);
|
||||||
} else {
|
} else {
|
||||||
const qs = new LegacyQueryServerClient(
|
const qs = new LegacyQueryServerClient(
|
||||||
|
app,
|
||||||
qlConfigurationListener,
|
qlConfigurationListener,
|
||||||
cliServer,
|
cliServer,
|
||||||
qsOpts,
|
qsOpts,
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
window as Window,
|
window as Window,
|
||||||
workspace,
|
workspace,
|
||||||
env,
|
env,
|
||||||
commands,
|
|
||||||
} from "vscode";
|
} from "vscode";
|
||||||
import { CodeQLCliServer, QlpacksInfo } from "./cli";
|
import { CodeQLCliServer, QlpacksInfo } from "./cli";
|
||||||
import { UserCancellationException } from "./progress";
|
import { UserCancellationException } from "./progress";
|
||||||
@@ -27,6 +26,7 @@ import { RedactableError } from "./pure/errors";
|
|||||||
import { getQlPackPath } from "./pure/ql";
|
import { getQlPackPath } from "./pure/ql";
|
||||||
import { dbSchemeToLanguage } from "./common/query-language";
|
import { dbSchemeToLanguage } from "./common/query-language";
|
||||||
import { isCodespacesTemplate } from "./config";
|
import { isCodespacesTemplate } from "./config";
|
||||||
|
import { AppCommandManager } from "./common/commands";
|
||||||
|
|
||||||
// Shared temporary folder for the extension.
|
// Shared temporary folder for the extension.
|
||||||
export const tmpDir = dirSync({
|
export const tmpDir = dirSync({
|
||||||
@@ -271,7 +271,9 @@ export function isFolderAlreadyInWorkspace(folderName: string) {
|
|||||||
/** Check if the current workspace is the CodeTour and open the workspace folder.
|
/** Check if the current workspace is the CodeTour and open the workspace folder.
|
||||||
* Without this, we can't run the code tour correctly.
|
* Without this, we can't run the code tour correctly.
|
||||||
**/
|
**/
|
||||||
export async function prepareCodeTour(): Promise<void> {
|
export async function prepareCodeTour(
|
||||||
|
commandManager: AppCommandManager,
|
||||||
|
): Promise<void> {
|
||||||
if (workspace.workspaceFolders?.length) {
|
if (workspace.workspaceFolders?.length) {
|
||||||
const currentFolder = workspace.workspaceFolders[0].uri.fsPath;
|
const currentFolder = workspace.workspaceFolders[0].uri.fsPath;
|
||||||
|
|
||||||
@@ -308,7 +310,7 @@ export async function prepareCodeTour(): Promise<void> {
|
|||||||
`In prepareCodeTour() method, going to open the tutorial workspace file: ${tutorialWorkspacePath}`,
|
`In prepareCodeTour() method, going to open the tutorial workspace file: ${tutorialWorkspacePath}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
await commands.executeCommand("vscode.openFolder", tutorialWorkspaceUri);
|
await commandManager.execute("vscode.openFolder", tutorialWorkspaceUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ensureFile } from "fs-extra";
|
import { ensureFile } from "fs-extra";
|
||||||
|
|
||||||
import { DisposableObject } from "../pure/disposable-object";
|
import { DisposableObject } from "../pure/disposable-object";
|
||||||
import { CancellationToken, commands } from "vscode";
|
import { CancellationToken } from "vscode";
|
||||||
import { createMessageConnection, RequestType } from "vscode-jsonrpc/node";
|
import { createMessageConnection, RequestType } from "vscode-jsonrpc/node";
|
||||||
import * as cli from "../cli";
|
import * as cli from "../cli";
|
||||||
import { QueryServerConfig } from "../config";
|
import { QueryServerConfig } from "../config";
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
} from "../pure/legacy-messages";
|
} from "../pure/legacy-messages";
|
||||||
import { ProgressCallback, ProgressTask } from "../progress";
|
import { ProgressCallback, ProgressTask } from "../progress";
|
||||||
import { ServerProcess } from "../json-rpc-server";
|
import { ServerProcess } from "../json-rpc-server";
|
||||||
|
import { App } from "../common/app";
|
||||||
|
|
||||||
type WithProgressReporting = (
|
type WithProgressReporting = (
|
||||||
task: (
|
task: (
|
||||||
@@ -56,6 +57,7 @@ export class QueryServerClient extends DisposableObject {
|
|||||||
public activeQueryLogger: Logger;
|
public activeQueryLogger: Logger;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
app: App,
|
||||||
readonly config: QueryServerConfig,
|
readonly config: QueryServerConfig,
|
||||||
readonly cliServer: cli.CodeQLCliServer,
|
readonly cliServer: cli.CodeQLCliServer,
|
||||||
readonly opts: ServerOpts,
|
readonly opts: ServerOpts,
|
||||||
@@ -69,7 +71,7 @@ export class QueryServerClient extends DisposableObject {
|
|||||||
if (config.onDidChangeConfiguration !== undefined) {
|
if (config.onDidChangeConfiguration !== undefined) {
|
||||||
this.push(
|
this.push(
|
||||||
config.onDidChangeConfiguration(() =>
|
config.onDidChangeConfiguration(() =>
|
||||||
commands.executeCommand("codeQL.restartQueryServer"),
|
app.commands.execute("codeQL.restartQueryServer"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -451,6 +451,7 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
return withProgress(
|
return withProgress(
|
||||||
async (progress, token) => {
|
async (progress, token) => {
|
||||||
await promptImportInternetDatabase(
|
await promptImportInternetDatabase(
|
||||||
|
this.app.commands,
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.storagePath,
|
this.storagePath,
|
||||||
progress,
|
progress,
|
||||||
@@ -470,6 +471,7 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||||
|
|
||||||
await promptImportGithubDatabase(
|
await promptImportGithubDatabase(
|
||||||
|
this.app.commands,
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.storagePath,
|
this.storagePath,
|
||||||
credentials,
|
credentials,
|
||||||
@@ -607,6 +609,7 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
// Assume user has selected an archive if the file has a .zip extension
|
// Assume user has selected an archive if the file has a .zip extension
|
||||||
if (uri.path.endsWith(".zip")) {
|
if (uri.path.endsWith(".zip")) {
|
||||||
await importArchiveDatabase(
|
await importArchiveDatabase(
|
||||||
|
this.app.commands,
|
||||||
uri.toString(true),
|
uri.toString(true),
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.storagePath,
|
this.storagePath,
|
||||||
@@ -762,6 +765,7 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
// we are selecting a database archive. Must unzip into a workspace-controlled area
|
// we are selecting a database archive. Must unzip into a workspace-controlled area
|
||||||
// before importing.
|
// before importing.
|
||||||
return await importArchiveDatabase(
|
return await importArchiveDatabase(
|
||||||
|
this.app.commands,
|
||||||
uri.toString(true),
|
uri.toString(true),
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.storagePath,
|
this.storagePath,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { redactableError } from "./pure/errors";
|
|||||||
import { isCodespacesTemplate } from "./config";
|
import { isCodespacesTemplate } from "./config";
|
||||||
import { QlPackGenerator } from "./qlpack-generator";
|
import { QlPackGenerator } from "./qlpack-generator";
|
||||||
import { QueryLanguage } from "./common/query-language";
|
import { QueryLanguage } from "./common/query-language";
|
||||||
|
import { App } from "./common/app";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* databases.ts
|
* databases.ts
|
||||||
@@ -593,6 +594,7 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly ctx: ExtensionContext,
|
private readonly ctx: ExtensionContext,
|
||||||
|
private readonly app: App,
|
||||||
private readonly qs: QueryRunner,
|
private readonly qs: QueryRunner,
|
||||||
private readonly cli: cli.CodeQLCliServer,
|
private readonly cli: cli.CodeQLCliServer,
|
||||||
public logger: Logger,
|
public logger: Logger,
|
||||||
@@ -875,7 +877,7 @@ export class DatabaseManager extends DisposableObject {
|
|||||||
this._currentDatabaseItem = item;
|
this._currentDatabaseItem = item;
|
||||||
this.updatePersistedCurrentDatabaseItem();
|
this.updatePersistedCurrentDatabaseItem();
|
||||||
|
|
||||||
await vscode.commands.executeCommand(
|
await this.app.commands.execute(
|
||||||
"setContext",
|
"setContext",
|
||||||
"codeQL.currentDatabaseItem",
|
"codeQL.currentDatabaseItem",
|
||||||
item?.name,
|
item?.name,
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import { commands, Uri, window } from "vscode";
|
import { Uri, window } from "vscode";
|
||||||
import { CodeQLCliServer } from "./cli";
|
import { CodeQLCliServer } from "./cli";
|
||||||
import { QueryRunner } from "./queryRunner";
|
import { QueryRunner } from "./queryRunner";
|
||||||
import { basename, join } from "path";
|
import { basename, join } from "path";
|
||||||
import { getErrorMessage } from "./pure/helpers-pure";
|
import { getErrorMessage } from "./pure/helpers-pure";
|
||||||
import { redactableError } from "./pure/errors";
|
import { redactableError } from "./pure/errors";
|
||||||
import { showAndLogExceptionWithTelemetry } from "./helpers";
|
import { showAndLogExceptionWithTelemetry } from "./helpers";
|
||||||
import { QueryEditorCommands } from "./common/commands";
|
import { AppCommandManager, QueryEditorCommands } from "./common/commands";
|
||||||
|
|
||||||
type QueryEditorOptions = {
|
type QueryEditorOptions = {
|
||||||
|
commandManager: AppCommandManager;
|
||||||
|
|
||||||
queryRunner: QueryRunner;
|
queryRunner: QueryRunner;
|
||||||
cliServer: CodeQLCliServer;
|
cliServer: CodeQLCliServer;
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ type QueryEditorOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function getQueryEditorCommands({
|
export function getQueryEditorCommands({
|
||||||
|
commandManager,
|
||||||
queryRunner,
|
queryRunner,
|
||||||
cliServer,
|
cliServer,
|
||||||
qhelpTmpDir,
|
qhelpTmpDir,
|
||||||
@@ -29,11 +32,17 @@ export function getQueryEditorCommands({
|
|||||||
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
|
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
|
||||||
"codeQL.openReferencedFileContextExplorer": openReferencedFileCommand,
|
"codeQL.openReferencedFileContextExplorer": openReferencedFileCommand,
|
||||||
"codeQL.previewQueryHelp": async (selectedQuery: Uri) =>
|
"codeQL.previewQueryHelp": async (selectedQuery: Uri) =>
|
||||||
await previewQueryHelp(cliServer, qhelpTmpDir, selectedQuery),
|
await previewQueryHelp(
|
||||||
|
commandManager,
|
||||||
|
cliServer,
|
||||||
|
qhelpTmpDir,
|
||||||
|
selectedQuery,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function previewQueryHelp(
|
async function previewQueryHelp(
|
||||||
|
commandManager: AppCommandManager,
|
||||||
cliServer: CodeQLCliServer,
|
cliServer: CodeQLCliServer,
|
||||||
qhelpTmpDir: string,
|
qhelpTmpDir: string,
|
||||||
selectedQuery: Uri,
|
selectedQuery: Uri,
|
||||||
@@ -49,7 +58,7 @@ async function previewQueryHelp(
|
|||||||
const uri = Uri.file(absolutePathToMd);
|
const uri = Uri.file(absolutePathToMd);
|
||||||
try {
|
try {
|
||||||
await cliServer.generateQueryHelp(pathToQhelp, absolutePathToMd);
|
await cliServer.generateQueryHelp(pathToQhelp, absolutePathToMd);
|
||||||
await commands.executeCommand("markdown.showPreviewToSide", uri);
|
await commandManager.execute("markdown.showPreviewToSide", uri);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorMessage = getErrorMessage(e).includes(
|
const errorMessage = getErrorMessage(e).includes(
|
||||||
"Generating qhelp in markdown",
|
"Generating qhelp in markdown",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { lstat, copy, pathExists, createFile } from "fs-extra";
|
import { lstat, copy, pathExists, createFile } from "fs-extra";
|
||||||
import { basename } from "path";
|
import { basename } from "path";
|
||||||
import { Uri, TextDocumentShowOptions, commands, window } from "vscode";
|
import { Uri, TextDocumentShowOptions, window } from "vscode";
|
||||||
import {
|
import {
|
||||||
TestHub,
|
TestHub,
|
||||||
TestController,
|
TestController,
|
||||||
@@ -16,6 +16,7 @@ import { TestTreeNode } from "./test-tree-node";
|
|||||||
import { DisposableObject } from "./pure/disposable-object";
|
import { DisposableObject } from "./pure/disposable-object";
|
||||||
import { QLTestAdapter, getExpectedFile, getActualFile } from "./test-adapter";
|
import { QLTestAdapter, getExpectedFile, getActualFile } from "./test-adapter";
|
||||||
import { TestUICommands } from "./common/commands";
|
import { TestUICommands } from "./common/commands";
|
||||||
|
import { App } from "./common/app";
|
||||||
|
|
||||||
type VSCodeTestEvent =
|
type VSCodeTestEvent =
|
||||||
| TestRunStartedEvent
|
| TestRunStartedEvent
|
||||||
@@ -44,7 +45,7 @@ class QLTestListener extends DisposableObject {
|
|||||||
export class TestUIService extends DisposableObject implements TestController {
|
export class TestUIService extends DisposableObject implements TestController {
|
||||||
private readonly listeners: Map<TestAdapter, QLTestListener> = new Map();
|
private readonly listeners: Map<TestAdapter, QLTestListener> = new Map();
|
||||||
|
|
||||||
constructor(private readonly testHub: TestHub) {
|
constructor(private readonly app: App, private readonly testHub: TestHub) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
testHub.registerTestController(this);
|
testHub.registerTestController(this);
|
||||||
@@ -105,7 +106,7 @@ export class TestUIService extends DisposableObject implements TestController {
|
|||||||
|
|
||||||
if (await pathExists(actualPath)) {
|
if (await pathExists(actualPath)) {
|
||||||
const actualUri = Uri.file(actualPath);
|
const actualUri = Uri.file(actualPath);
|
||||||
await commands.executeCommand<void>(
|
await this.app.commands.execute(
|
||||||
"vscode.diff",
|
"vscode.diff",
|
||||||
expectedUri,
|
expectedUri,
|
||||||
actualUri,
|
actualUri,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
promptImportInternetDatabase,
|
promptImportInternetDatabase,
|
||||||
} from "../../../src/databaseFetcher";
|
} from "../../../src/databaseFetcher";
|
||||||
import { cleanDatabases, dbLoc, DB_URL, storagePath } from "../global.helper";
|
import { cleanDatabases, dbLoc, DB_URL, storagePath } from "../global.helper";
|
||||||
|
import { createMockCommandManager } from "../../__mocks__/commandsMock";
|
||||||
|
|
||||||
jest.setTimeout(60_000);
|
jest.setTimeout(60_000);
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ describe("DatabaseFetcher", () => {
|
|||||||
it("should add a database from a folder", async () => {
|
it("should add a database from a folder", async () => {
|
||||||
const uri = Uri.file(dbLoc);
|
const uri = Uri.file(dbLoc);
|
||||||
let dbItem = await importArchiveDatabase(
|
let dbItem = await importArchiveDatabase(
|
||||||
|
createMockCommandManager(),
|
||||||
uri.toString(true),
|
uri.toString(true),
|
||||||
databaseManager,
|
databaseManager,
|
||||||
storagePath,
|
storagePath,
|
||||||
@@ -75,6 +77,7 @@ describe("DatabaseFetcher", () => {
|
|||||||
inputBoxStub.mockResolvedValue(DB_URL);
|
inputBoxStub.mockResolvedValue(DB_URL);
|
||||||
|
|
||||||
let dbItem = await promptImportInternetDatabase(
|
let dbItem = await promptImportInternetDatabase(
|
||||||
|
createMockCommandManager(),
|
||||||
databaseManager,
|
databaseManager,
|
||||||
storagePath,
|
storagePath,
|
||||||
progressCallback,
|
progressCallback,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { CodeQLExtensionInterface } from "../../../src/extension";
|
|||||||
import { describeWithCodeQL } from "../cli";
|
import { describeWithCodeQL } from "../cli";
|
||||||
import { QueryServerClient } from "../../../src/legacy-query-server/queryserver-client";
|
import { QueryServerClient } from "../../../src/legacy-query-server/queryserver-client";
|
||||||
import { extLogger, ProgressReporter } from "../../../src/common";
|
import { extLogger, ProgressReporter } from "../../../src/common";
|
||||||
|
import { createMockApp } from "../../__mocks__/appMock";
|
||||||
|
|
||||||
const baseDir = join(__dirname, "../../../test/data");
|
const baseDir = join(__dirname, "../../../test/data");
|
||||||
|
|
||||||
@@ -121,6 +122,7 @@ describeWithCodeQL()("using the legacy query server", () => {
|
|||||||
cliServer.quiet = true;
|
cliServer.quiet = true;
|
||||||
|
|
||||||
qs = new QueryServerClient(
|
qs = new QueryServerClient(
|
||||||
|
createMockApp({}),
|
||||||
{
|
{
|
||||||
codeQlPath:
|
codeQlPath:
|
||||||
(await extension.distributionManager.getCodeQlPathWithoutVersionCheck()) ||
|
(await extension.distributionManager.getCodeQlPathWithoutVersionCheck()) ||
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { extLogger, ProgressReporter } from "../../../src/common";
|
|||||||
import { QueryResultType } from "../../../src/pure/new-messages";
|
import { QueryResultType } from "../../../src/pure/new-messages";
|
||||||
import { cleanDatabases, dbLoc, storagePath } from "../global.helper";
|
import { cleanDatabases, dbLoc, storagePath } from "../global.helper";
|
||||||
import { importArchiveDatabase } from "../../../src/databaseFetcher";
|
import { importArchiveDatabase } from "../../../src/databaseFetcher";
|
||||||
|
import { createMockCommandManager } from "../../__mocks__/commandsMock";
|
||||||
|
|
||||||
const baseDir = join(__dirname, "../../../test/data");
|
const baseDir = join(__dirname, "../../../test/data");
|
||||||
|
|
||||||
@@ -147,6 +148,7 @@ describeWithCodeQL()("using the new query server", () => {
|
|||||||
await cleanDatabases(extension.databaseManager);
|
await cleanDatabases(extension.databaseManager);
|
||||||
const uri = Uri.file(dbLoc);
|
const uri = Uri.file(dbLoc);
|
||||||
const maybeDbItem = await importArchiveDatabase(
|
const maybeDbItem = await importArchiveDatabase(
|
||||||
|
createMockCommandManager(),
|
||||||
uri.toString(true),
|
uri.toString(true),
|
||||||
extension.databaseManager,
|
extension.databaseManager,
|
||||||
storagePath,
|
storagePath,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { createInitialQueryInfo } from "../../../src/run-queries-shared";
|
|||||||
import { QueryRunner } from "../../../src/queryRunner";
|
import { QueryRunner } from "../../../src/queryRunner";
|
||||||
import { CompletedQueryInfo } from "../../../src/query-results";
|
import { CompletedQueryInfo } from "../../../src/query-results";
|
||||||
import { SELECT_QUERY_NAME } from "../../../src/contextual/locationFinder";
|
import { SELECT_QUERY_NAME } from "../../../src/contextual/locationFinder";
|
||||||
|
import { createMockCommandManager } from "../../__mocks__/commandsMock";
|
||||||
|
|
||||||
jest.setTimeout(20_000);
|
jest.setTimeout(20_000);
|
||||||
|
|
||||||
@@ -78,6 +79,7 @@ describeWithCodeQL()("Queries", () => {
|
|||||||
await cleanDatabases(databaseManager);
|
await cleanDatabases(databaseManager);
|
||||||
const uri = Uri.file(dbLoc);
|
const uri = Uri.file(dbLoc);
|
||||||
const maybeDbItem = await importArchiveDatabase(
|
const maybeDbItem = await importArchiveDatabase(
|
||||||
|
createMockCommandManager(),
|
||||||
uri.toString(true),
|
uri.toString(true),
|
||||||
databaseManager,
|
databaseManager,
|
||||||
storagePath,
|
storagePath,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import * as helpers from "../../../src/helpers";
|
|||||||
import { Setting } from "../../../src/config";
|
import { Setting } from "../../../src/config";
|
||||||
import { QlPackGenerator } from "../../../src/qlpack-generator";
|
import { QlPackGenerator } from "../../../src/qlpack-generator";
|
||||||
import { mockedObject } from "../utils/mocking.helpers";
|
import { mockedObject } from "../utils/mocking.helpers";
|
||||||
|
import { createMockApp } from "../../__mocks__/appMock";
|
||||||
|
|
||||||
describe("local databases", () => {
|
describe("local databases", () => {
|
||||||
const MOCK_DB_OPTIONS: FullDatabaseOptions = {
|
const MOCK_DB_OPTIONS: FullDatabaseOptions = {
|
||||||
@@ -87,6 +88,7 @@ describe("local databases", () => {
|
|||||||
|
|
||||||
databaseManager = new DatabaseManager(
|
databaseManager = new DatabaseManager(
|
||||||
extensionContext,
|
extensionContext,
|
||||||
|
createMockApp({}),
|
||||||
mockedObject<QueryRunner>({
|
mockedObject<QueryRunner>({
|
||||||
registerDatabase: registerSpy,
|
registerDatabase: registerSpy,
|
||||||
deregisterDatabase: deregisterSpy,
|
deregisterDatabase: deregisterSpy,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
commands,
|
|
||||||
EnvironmentVariableCollection,
|
EnvironmentVariableCollection,
|
||||||
EnvironmentVariableMutator,
|
EnvironmentVariableMutator,
|
||||||
Event,
|
Event,
|
||||||
@@ -41,6 +40,7 @@ import {
|
|||||||
import { reportStreamProgress } from "../../../src/progress";
|
import { reportStreamProgress } from "../../../src/progress";
|
||||||
import { QueryLanguage } from "../../../src/common/query-language";
|
import { QueryLanguage } from "../../../src/common/query-language";
|
||||||
import { Setting } from "../../../src/config";
|
import { Setting } from "../../../src/config";
|
||||||
|
import { createMockCommandManager } from "../../__mocks__/commandsMock";
|
||||||
|
|
||||||
describe("helpers", () => {
|
describe("helpers", () => {
|
||||||
describe("Invocation rate limiter", () => {
|
describe("Invocation rate limiter", () => {
|
||||||
@@ -612,13 +612,11 @@ describe("prepareCodeTour", () => {
|
|||||||
await mkdir(tourDirPath);
|
await mkdir(tourDirPath);
|
||||||
|
|
||||||
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
||||||
const commandSpy = jest.spyOn(commands, "executeCommand");
|
const executeCommand = jest.fn();
|
||||||
commandSpy.mockImplementation(() => Promise.resolve());
|
await prepareCodeTour(createMockCommandManager({ executeCommand }));
|
||||||
|
|
||||||
await prepareCodeTour();
|
|
||||||
|
|
||||||
expect(showInformationMessageSpy).toHaveBeenCalled();
|
expect(showInformationMessageSpy).toHaveBeenCalled();
|
||||||
expect(commandSpy).toHaveBeenCalledWith(
|
expect(executeCommand).toHaveBeenCalledWith(
|
||||||
"vscode.openFolder",
|
"vscode.openFolder",
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
path: Uri.parse(tutorialWorkspacePath).fsPath,
|
path: Uri.parse(tutorialWorkspacePath).fsPath,
|
||||||
@@ -641,12 +639,10 @@ describe("prepareCodeTour", () => {
|
|||||||
await mkdir(tourDirPath);
|
await mkdir(tourDirPath);
|
||||||
|
|
||||||
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
||||||
const commandSpy = jest.spyOn(commands, "executeCommand");
|
const executeCommand = jest.fn();
|
||||||
commandSpy.mockImplementation(() => Promise.resolve());
|
await prepareCodeTour(createMockCommandManager({ executeCommand }));
|
||||||
|
|
||||||
await prepareCodeTour();
|
expect(executeCommand).not.toHaveBeenCalled();
|
||||||
|
|
||||||
expect(commandSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -658,24 +654,20 @@ describe("prepareCodeTour", () => {
|
|||||||
await mkdir(tourDirPath);
|
await mkdir(tourDirPath);
|
||||||
|
|
||||||
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
||||||
const commandSpy = jest.spyOn(commands, "executeCommand");
|
const executeCommand = jest.fn();
|
||||||
commandSpy.mockImplementation(() => Promise.resolve());
|
await prepareCodeTour(createMockCommandManager({ executeCommand }));
|
||||||
|
|
||||||
await prepareCodeTour();
|
expect(executeCommand).not.toHaveBeenCalled();
|
||||||
|
|
||||||
expect(commandSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("if we're in a different repo with no tour", () => {
|
describe("if we're in a different repo with no tour", () => {
|
||||||
it("should not open the tutorial workspace", async () => {
|
it("should not open the tutorial workspace", async () => {
|
||||||
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
||||||
const commandSpy = jest.spyOn(commands, "executeCommand");
|
const executeCommand = jest.fn();
|
||||||
commandSpy.mockImplementation(() => Promise.resolve());
|
await prepareCodeTour(createMockCommandManager({ executeCommand }));
|
||||||
|
|
||||||
await prepareCodeTour();
|
expect(executeCommand).not.toHaveBeenCalled();
|
||||||
|
|
||||||
expect(commandSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user