Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion extensions/ql-vscode/src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export type SingleSelectionCommandFunction<Item> = (
* the implementation in the corresponding `getCommands` function.
*/

// Builtin commands where the implementation is provided by VS Code and not by this extension.
// See https://code.visualstudio.com/api/references/commands
export type BuiltInVsCodeCommands = {
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
"workbench.action.reloadWindow": () => Promise<void>;
};

// Base commands not tied directly to a module like e.g. variant analysis.
export type BaseCommands = {
"codeQL.openDocumentation": () => Promise<void>;
Expand Down Expand Up @@ -230,7 +237,8 @@ export type MockGitHubApiServerCommands = {
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
};

export type AllCommands = BaseCommands &
// All commands where the implementation is provided by this extension.
export type AllExtensionCommands = BaseCommands &
QueryEditorCommands &
ResultsViewCommands &
QueryHistoryCommands &
Expand All @@ -245,6 +253,8 @@ export type AllCommands = BaseCommands &
Partial<TestUICommands> &
MockGitHubApiServerCommands;

export type AllCommands = AllExtensionCommands & BuiltInVsCodeCommands;

export type AppCommandManager = CommandManager<AllCommands>;

// Separate command manager because it uses a different logger
Expand Down
27 changes: 18 additions & 9 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "source-map-support/register";
import {
CancellationToken,
commands,
Disposable,
env,
ExtensionContext,
Expand Down Expand Up @@ -111,7 +110,7 @@ import { DbModule } from "./databases/db-module";
import { redactableError } from "./pure/errors";
import { QueryHistoryDirs } from "./query-history/query-history-dirs";
import {
AllCommands,
AllExtensionCommands,
BaseCommands,
QueryServerCommands,
TestUICommands,
Expand Down Expand Up @@ -266,6 +265,8 @@ export async function activate(
addUnhandledRejectionListener();
install();

const app = new ExtensionApp(ctx);

const codelensProvider = new QuickEvalCodeLensProvider();
languages.registerCodeLensProvider(
{ scheme: "file", language: "ql" },
Expand All @@ -292,6 +293,7 @@ export async function activate(
distributionConfigListener.onDidChangeConfiguration(() =>
installOrUpdateThenTryActivate(
ctx,
app,
distributionManager,
distributionConfigListener,
{
Expand All @@ -306,6 +308,7 @@ export async function activate(
commandRunner(checkForUpdatesCommand, () =>
installOrUpdateThenTryActivate(
ctx,
app,
distributionManager,
distributionConfigListener,
{
Expand All @@ -325,6 +328,7 @@ export async function activate(

const codeQlExtension = await installOrUpdateThenTryActivate(
ctx,
app,
distributionManager,
distributionConfigListener,
{
Expand All @@ -346,6 +350,7 @@ export async function activate(

async function installOrUpdateDistributionWithProgressTitle(
ctx: ExtensionContext,
app: ExtensionApp,
distributionManager: DistributionManager,
progressTitle: string,
config: DistributionUpdateConfig,
Expand Down Expand Up @@ -390,7 +395,7 @@ async function installOrUpdateDistributionWithProgressTitle(
"Restart and Upgrade",
)
) {
await commands.executeCommand("workbench.action.reloadWindow");
await app.commands.execute("workbench.action.reloadWindow");
}
} else {
await withProgress(
Expand All @@ -417,6 +422,7 @@ async function installOrUpdateDistributionWithProgressTitle(

async function installOrUpdateDistribution(
ctx: ExtensionContext,
app: ExtensionApp,
distributionManager: DistributionManager,
config: DistributionUpdateConfig,
): Promise<void> {
Expand All @@ -437,6 +443,7 @@ async function installOrUpdateDistribution(
try {
await installOrUpdateDistributionWithProgressTitle(
ctx,
app,
distributionManager,
messageText,
config,
Expand Down Expand Up @@ -522,11 +529,12 @@ async function getDistributionDisplayingDistributionWarnings(

async function installOrUpdateThenTryActivate(
ctx: ExtensionContext,
app: ExtensionApp,
distributionManager: DistributionManager,
distributionConfigListener: DistributionConfigListener,
config: DistributionUpdateConfig,
): Promise<CodeQLExtensionInterface | Record<string, never>> {
await installOrUpdateDistribution(ctx, distributionManager, config);
await installOrUpdateDistribution(ctx, app, distributionManager, config);

try {
await prepareCodeTour();
Expand All @@ -546,6 +554,7 @@ async function installOrUpdateThenTryActivate(
) {
extensionInterface = await activateWithInstalledDistribution(
ctx,
app,
distributionManager,
distributionConfigListener,
);
Expand All @@ -563,6 +572,7 @@ async function installOrUpdateThenTryActivate(
if (chosenAction === installActionName) {
await installOrUpdateThenTryActivate(
ctx,
app,
distributionManager,
distributionConfigListener,
{
Expand All @@ -589,6 +599,7 @@ const PACK_GLOBS = [

async function activateWithInstalledDistribution(
ctx: ExtensionContext,
app: ExtensionApp,
distributionManager: DistributionManager,
distributionConfigListener: DistributionConfigListener,
): Promise<CodeQLExtensionInterface> {
Expand All @@ -597,8 +608,6 @@ async function activateWithInstalledDistribution(
// of activation.
errorStubs.forEach((stub) => stub.dispose());

const app = new ExtensionApp(ctx);

void extLogger.log("Initializing configuration listener...");
const qlConfigurationListener =
await QueryServerConfigListener.createQueryServerConfigListener(
Expand Down Expand Up @@ -831,7 +840,7 @@ async function activateWithInstalledDistribution(

void extLogger.log("Registering top-level command palette commands.");

const allCommands: AllCommands = {
const allCommands: AllExtensionCommands = {
...getCommands(cliServer, qs),
...getQueryEditorCommands({
queryRunner: qs,
Expand Down Expand Up @@ -864,7 +873,7 @@ async function activateWithInstalledDistribution(
};

for (const [commandName, command] of Object.entries(allCommands)) {
app.commands.register(commandName as keyof AllCommands, command);
app.commands.register(commandName as keyof AllExtensionCommands, command);
}

const queryServerCommands: QueryServerCommands = {
Expand Down Expand Up @@ -955,7 +964,7 @@ async function activateWithInstalledDistribution(
),
);

await commands.executeCommand("codeQLDatabases.removeOrphanedDatabases");
await app.commands.execute("codeQLDatabases.removeOrphanedDatabases");

void extLogger.log("Reading query history");
await qhm.readQueryHistory();
Expand Down