Skip to content

Commit d4a8eb9

Browse files
Merge pull request #2229 from github/robertbrignull/use_app_commands_3
Convert call sites to use typed commands (part 3)
2 parents cd03002 + 3bdf6c5 commit d4a8eb9

9 files changed

Lines changed: 77 additions & 142 deletions

File tree

extensions/ql-vscode/src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,10 @@ async function activateWithInstalledDistribution(
877877

878878
ctx.subscriptions.push(astViewer);
879879

880-
const summaryLanguageSupport = new SummaryLanguageSupport();
880+
const summaryLanguageSupport = new SummaryLanguageSupport(app);
881881
ctx.subscriptions.push(summaryLanguageSupport);
882882

883-
const mockServer = new VSCodeMockGitHubApiServer(ctx);
883+
const mockServer = new VSCodeMockGitHubApiServer(app);
884884
ctx.subscriptions.push(mockServer);
885885

886886
void extLogger.log("Registering top-level command palette commands.");
@@ -1075,6 +1075,7 @@ async function createQueryServer(
10751075
);
10761076
if (await cliServer.cliConstraints.supportsNewQueryServer()) {
10771077
const qs = new QueryServerClient(
1078+
app,
10781079
qlConfigurationListener,
10791080
cliServer,
10801081
qsOpts,

extensions/ql-vscode/src/log-insights/summary-language-support.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { readFile } from "fs-extra";
22
import { RawSourceMap, SourceMapConsumer } from "source-map";
33
import {
4-
commands,
54
Position,
65
Selection,
76
TextDocument,
@@ -16,6 +15,7 @@ import { DisposableObject } from "../pure/disposable-object";
1615
import { extLogger } from "../common";
1716
import { getErrorMessage } from "../pure/helpers-pure";
1817
import { SummaryLanguageSupportCommands } from "../common/commands";
18+
import { App } from "../common/app";
1919

2020
/** A `Position` within a specified file on disk. */
2121
interface PositionInFile {
@@ -55,7 +55,7 @@ export class SummaryLanguageSupport extends DisposableObject {
5555
*/
5656
private sourceMap: SourceMapConsumer | undefined = undefined;
5757

58-
constructor() {
58+
constructor(private readonly app: App) {
5959
super();
6060

6161
this.push(
@@ -160,7 +160,7 @@ export class SummaryLanguageSupport extends DisposableObject {
160160
private async updateContext(): Promise<void> {
161161
const position = await this.getQLSourceLocation();
162162

163-
await commands.executeCommand(
163+
await this.app.commands.execute(
164164
"setContext",
165165
"codeql.hasQLSource",
166166
position !== undefined,

extensions/ql-vscode/src/mocks/vscode-mock-gh-api-server.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import { pathExists } from "fs-extra";
2-
import {
3-
commands,
4-
env,
5-
ExtensionContext,
6-
ExtensionMode,
7-
QuickPickItem,
8-
Uri,
9-
window,
10-
} from "vscode";
2+
import { env, QuickPickItem, Uri, window } from "vscode";
113

124
import {
135
getMockGitHubApiServerScenariosPath,
@@ -16,6 +8,8 @@ import {
168
import { DisposableObject } from "../pure/disposable-object";
179
import { MockGitHubApiServer } from "./mock-gh-api-server";
1810
import { MockGitHubApiServerCommands } from "../common/commands";
11+
import { App, AppMode } from "../common/app";
12+
import path from "path";
1913

2014
/**
2115
* "Interface" to the mock GitHub API server which implements VSCode interactions, such as
@@ -27,7 +21,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
2721
private readonly server: MockGitHubApiServer;
2822
private readonly config: MockGitHubApiConfigListener;
2923

30-
constructor(private readonly ctx: ExtensionContext) {
24+
constructor(private readonly app: App) {
3125
super();
3226
this.server = new MockGitHubApiServer();
3327
this.config = new MockGitHubApiConfigListener();
@@ -55,12 +49,12 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
5549
public async stopServer(): Promise<void> {
5650
this.server.stopServer();
5751

58-
await commands.executeCommand(
52+
await this.app.commands.execute(
5953
"setContext",
6054
"codeQL.mockGitHubApiServer.scenarioLoaded",
6155
false,
6256
);
63-
await commands.executeCommand(
57+
await this.app.commands.execute(
6458
"setContext",
6559
"codeQL.mockGitHubApiServer.recording",
6660
false,
@@ -92,7 +86,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
9286

9387
// Set a value in the context to track whether we have a scenario loaded.
9488
// This allows us to use this to show/hide commands (see package.json)
95-
await commands.executeCommand(
89+
await this.app.commands.execute(
9690
"setContext",
9791
"codeQL.mockGitHubApiServer.scenarioLoaded",
9892
true,
@@ -106,7 +100,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
106100
await window.showInformationMessage("No scenario currently loaded");
107101
} else {
108102
await this.server.unloadScenario();
109-
await commands.executeCommand(
103+
await this.app.commands.execute(
110104
"setContext",
111105
"codeQL.mockGitHubApiServer.scenarioLoaded",
112106
false,
@@ -125,7 +119,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
125119

126120
if (this.server.isScenarioLoaded) {
127121
await this.server.unloadScenario();
128-
await commands.executeCommand(
122+
await this.app.commands.execute(
129123
"setContext",
130124
"codeQL.mockGitHubApiServer.scenarioLoaded",
131125
false,
@@ -137,7 +131,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
137131

138132
await this.server.startRecording();
139133
// Set a value in the context to track whether we are recording. This allows us to use this to show/hide commands (see package.json)
140-
await commands.executeCommand(
134+
await this.app.commands.execute(
141135
"setContext",
142136
"codeQL.mockGitHubApiServer.recording",
143137
true,
@@ -155,7 +149,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
155149
}
156150

157151
// Set a value in the context to track whether we are recording. This allows us to use this to show/hide commands (see package.json)
158-
await commands.executeCommand(
152+
await this.app.commands.execute(
159153
"setContext",
160154
"codeQL.mockGitHubApiServer.recording",
161155
false,
@@ -210,7 +204,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
210204

211205
private async stopRecording(): Promise<void> {
212206
// Set a value in the context to track whether we are recording. This allows us to use this to show/hide commands (see package.json)
213-
await commands.executeCommand(
207+
await this.app.commands.execute(
214208
"setContext",
215209
"codeQL.mockGitHubApiServer.recording",
216210
false,
@@ -225,11 +219,11 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
225219
return scenariosPath;
226220
}
227221

228-
if (this.ctx.extensionMode === ExtensionMode.Development) {
229-
const developmentScenariosPath = Uri.joinPath(
230-
this.ctx.extensionUri,
222+
if (this.app.mode === AppMode.Development) {
223+
const developmentScenariosPath = path.join(
224+
this.app.extensionPath,
231225
"src/mocks/scenarios",
232-
).fsPath.toString();
226+
);
233227
if (await pathExists(developmentScenariosPath)) {
234228
return developmentScenariosPath;
235229
}

extensions/ql-vscode/src/query-server/queryserver-client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ensureFile } from "fs-extra";
22

33
import { DisposableObject } from "../pure/disposable-object";
4-
import { CancellationToken, commands } from "vscode";
4+
import { CancellationToken } from "vscode";
55
import { createMessageConnection, RequestType } from "vscode-jsonrpc/node";
66
import * as cli from "../cli";
77
import { QueryServerConfig } from "../config";
@@ -13,6 +13,7 @@ import {
1313
} from "../pure/new-messages";
1414
import { ProgressCallback, ProgressTask } from "../progress";
1515
import { ServerProcess } from "../json-rpc-server";
16+
import { App } from "../common/app";
1617

1718
type ServerOpts = {
1819
logger: Logger;
@@ -53,6 +54,7 @@ export class QueryServerClient extends DisposableObject {
5354
public activeQueryLogger: Logger;
5455

5556
constructor(
57+
app: App,
5658
readonly config: QueryServerConfig,
5759
readonly cliServer: cli.CodeQLCliServer,
5860
readonly opts: ServerOpts,
@@ -66,7 +68,7 @@ export class QueryServerClient extends DisposableObject {
6668
if (config.onDidChangeConfiguration !== undefined) {
6769
this.push(
6870
config.onDidChangeConfiguration(() =>
69-
commands.executeCommand("codeQL.restartQueryServer"),
71+
app.commands.execute("codeQL.restartQueryServer"),
7072
),
7173
);
7274
}

extensions/ql-vscode/src/variant-analysis/export-results.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { join } from "path";
22
import { ensureDir, writeFile } from "fs-extra";
33

4-
import {
5-
CancellationToken,
6-
commands,
7-
Uri,
8-
ViewColumn,
9-
window,
10-
workspace,
11-
} from "vscode";
4+
import { CancellationToken, Uri, ViewColumn, window, workspace } from "vscode";
125
import {
136
ProgressCallback,
147
UserCancellationException,
@@ -35,6 +28,7 @@ import {
3528
RepositoriesFilterSortStateWithIds,
3629
} from "../pure/variant-analysis-filter-sort";
3730
import { Credentials } from "../common/authentication";
31+
import { AppCommandManager } from "../common/commands";
3832

3933
const MAX_VARIANT_ANALYSIS_EXPORT_PROGRESS_STEPS = 2;
4034

@@ -46,6 +40,7 @@ export async function exportVariantAnalysisResults(
4640
variantAnalysisManager: VariantAnalysisManager,
4741
variantAnalysisId: number,
4842
filterSort: RepositoriesFilterSortStateWithIds | undefined,
43+
commandManager: AppCommandManager,
4944
credentials: Credentials,
5045
): Promise<void> {
5146
await withProgress(
@@ -149,6 +144,7 @@ export async function exportVariantAnalysisResults(
149144
getAnalysesResults(),
150145
repositories?.length ?? 0,
151146
exportFormat,
147+
commandManager,
152148
credentials,
153149
progress,
154150
token,
@@ -169,6 +165,7 @@ export async function exportVariantAnalysisAnalysisResults(
169165
>,
170166
expectedAnalysesResultsCount: number,
171167
exportFormat: "gist" | "local",
168+
commandManager: AppCommandManager,
172169
credentials: Credentials,
173170
progress: ProgressCallback,
174171
token: CancellationToken,
@@ -199,6 +196,7 @@ export async function exportVariantAnalysisAnalysisResults(
199196
description,
200197
markdownFiles,
201198
exportFormat,
199+
commandManager,
202200
credentials,
203201
progress,
204202
token,
@@ -243,6 +241,7 @@ export async function exportResults(
243241
description: string,
244242
markdownFiles: MarkdownFile[],
245243
exportFormat: "gist" | "local",
244+
commandManager: AppCommandManager,
246245
credentials: Credentials,
247246
progress?: ProgressCallback,
248247
token?: CancellationToken,
@@ -255,6 +254,7 @@ export async function exportResults(
255254
await exportToGist(
256255
description,
257256
markdownFiles,
257+
commandManager,
258258
credentials,
259259
progress,
260260
token,
@@ -263,6 +263,7 @@ export async function exportResults(
263263
await exportToLocalMarkdown(
264264
exportedResultsPath,
265265
markdownFiles,
266+
commandManager,
266267
progress,
267268
token,
268269
);
@@ -272,6 +273,7 @@ export async function exportResults(
272273
export async function exportToGist(
273274
description: string,
274275
markdownFiles: MarkdownFile[],
276+
commandManager: AppCommandManager,
275277
credentials: Credentials,
276278
progress?: ProgressCallback,
277279
token?: CancellationToken,
@@ -303,7 +305,7 @@ export async function exportToGist(
303305
if (!shouldOpenGist) {
304306
return;
305307
}
306-
return commands.executeCommand("vscode.open", Uri.parse(gistUrl));
308+
return commandManager.execute("vscode.open", Uri.parse(gistUrl));
307309
});
308310
}
309311
}
@@ -334,6 +336,7 @@ const buildVariantAnalysisGistDescription = (
334336
async function exportToLocalMarkdown(
335337
exportedResultsPath: string,
336338
markdownFiles: MarkdownFile[],
339+
commandManager: AppCommandManager,
337340
progress?: ProgressCallback,
338341
token?: CancellationToken,
339342
) {
@@ -366,6 +369,6 @@ async function exportToLocalMarkdown(
366369
const summaryFilePath = join(exportedResultsPath, "_summary.md");
367370
const summaryFile = await workspace.openTextDocument(summaryFilePath);
368371
await window.showTextDocument(summaryFile, ViewColumn.One);
369-
await commands.executeCommand("revealFileInOS", Uri.file(summaryFilePath));
372+
await commandManager.execute("revealFileInOS", Uri.file(summaryFilePath));
370373
});
371374
}

extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
} from "./gh-api/gh-api-client";
77
import {
88
CancellationToken,
9-
commands,
109
env,
1110
EventEmitter,
1211
ExtensionContext,
@@ -116,6 +115,7 @@ export class VariantAnalysisManager
116115
super();
117116
this.variantAnalysisMonitor = this.push(
118117
new VariantAnalysisMonitor(
118+
app,
119119
this.shouldCancelMonitorVariantAnalysis.bind(this),
120120
),
121121
);
@@ -239,11 +239,11 @@ export class VariantAnalysisManager
239239
`Variant analysis ${processedVariantAnalysis.query.name} submitted for processing`,
240240
);
241241

242-
void commands.executeCommand(
242+
void this.app.commands.execute(
243243
"codeQL.openVariantAnalysisView",
244244
processedVariantAnalysis.id,
245245
);
246-
void commands.executeCommand(
246+
void this.app.commands.execute(
247247
"codeQL.monitorVariantAnalysis",
248248
processedVariantAnalysis,
249249
);
@@ -273,7 +273,7 @@ export class VariantAnalysisManager
273273
this.makeResultDownloadChecker(variantAnalysis),
274274
))
275275
) {
276-
void commands.executeCommand(
276+
void this.app.commands.execute(
277277
"codeQL.monitorVariantAnalysis",
278278
variantAnalysis,
279279
);
@@ -502,10 +502,7 @@ export class VariantAnalysisManager
502502
public async monitorVariantAnalysis(
503503
variantAnalysis: VariantAnalysis,
504504
): Promise<void> {
505-
await this.variantAnalysisMonitor.monitorVariantAnalysis(
506-
variantAnalysis,
507-
this.app.credentials,
508-
);
505+
await this.variantAnalysisMonitor.monitorVariantAnalysis(variantAnalysis);
509506
}
510507

511508
public async autoDownloadVariantAnalysisResult(
@@ -641,7 +638,7 @@ export class VariantAnalysisManager
641638

642639
const actionsWorkflowRunUrl = getActionsWorkflowRunUrl(variantAnalysis);
643640

644-
await commands.executeCommand(
641+
await this.app.commands.execute(
645642
"vscode.open",
646643
Uri.parse(actionsWorkflowRunUrl),
647644
);
@@ -689,6 +686,7 @@ export class VariantAnalysisManager
689686
this,
690687
variantAnalysisId,
691688
filterSort,
689+
this.app.commands,
692690
this.app.credentials,
693691
);
694692
}

0 commit comments

Comments
 (0)