Skip to content

Commit 788bb4c

Browse files
committed
notify language client of updated packages from cli.ts
1 parent 94434f4 commit 788bb4c

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

extensions/ql-vscode/src/codeql-cli/cli.ts

+29-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import type { Log } from "sarif";
88
import { SemVer } from "semver";
99
import type { Readable } from "stream";
1010
import tk from "tree-kill";
11-
import type { CancellationToken, Disposable, Uri } from "vscode";
11+
import type { CancellationToken, Disposable } from "vscode";
12+
import { Uri } from "vscode";
1213

1314
import type {
1415
BqrsInfo,
@@ -37,6 +38,11 @@ import { LOGGING_FLAGS } from "./cli-command";
3738
import type { CliFeatures, VersionAndFeatures } from "./cli-version";
3839
import { ExitCodeError, getCliError } from "./cli-errors";
3940
import { UserCancellationException } from "../common/vscode/progress";
41+
import type { LanguageClient } from "vscode-languageclient/node";
42+
import {
43+
DidChangeWatchedFilesNotification,
44+
FileChangeType,
45+
} from "vscode-languageclient/node";
4046

4147
/**
4248
* The version of the SARIF format that we are using.
@@ -277,6 +283,7 @@ export class CodeQLCliServer implements Disposable {
277283

278284
constructor(
279285
private readonly app: App,
286+
private readonly languageClient: LanguageClient,
280287
private distributionProvider: DistributionProvider,
281288
private cliConfig: CliConfig,
282289
public readonly logger: Logger,
@@ -1584,11 +1591,13 @@ export class CodeQLCliServer implements Disposable {
15841591
async packAdd(dir: string, queryLanguage: QueryLanguage) {
15851592
const args = ["--dir", dir];
15861593
args.push(`codeql/${queryLanguage}-all`);
1587-
return this.runCodeQlCliCommand(
1594+
const ret = await this.runCodeQlCliCommand(
15881595
["pack", "add"],
15891596
args,
15901597
`Adding and installing ${queryLanguage} pack dependency.`,
15911598
);
1599+
await this.notifyPackChanged(dir);
1600+
return ret;
15921601
}
15931602

15941603
/**
@@ -1628,11 +1637,13 @@ export class CodeQLCliServer implements Disposable {
16281637
...this.getAdditionalPacksArg(workspaceFolders),
16291638
);
16301639
}
1631-
return this.runJsonCodeQlCliCommandWithAuthentication(
1640+
const ret = await this.runJsonCodeQlCliCommandWithAuthentication(
16321641
["pack", "install"],
16331642
args,
16341643
"Installing pack dependencies",
16351644
);
1645+
await this.notifyPackChanged(dir);
1646+
return ret;
16361647
}
16371648

16381649
/**
@@ -1750,6 +1761,21 @@ export class CodeQLCliServer implements Disposable {
17501761
this._versionChangedListeners.push(listener);
17511762
}
17521763

1764+
private async notifyPackChanged(packDir: string) {
1765+
const packFilePath = join(packDir, "codeql-pack.yml");
1766+
await this.languageClient.sendNotification(
1767+
DidChangeWatchedFilesNotification.type,
1768+
{
1769+
changes: [
1770+
{
1771+
type: FileChangeType.Changed,
1772+
uri: Uri.file(packFilePath).toString(),
1773+
},
1774+
],
1775+
},
1776+
);
1777+
}
1778+
17531779
private async refreshVersion(): Promise<VersionAndFeatures> {
17541780
const distribution = await this.distributionProvider.getDistribution();
17551781
switch (distribution.kind) {

extensions/ql-vscode/src/extension.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,13 @@ async function activateWithInstalledDistribution(
748748
);
749749
ctx.subscriptions.push(qlConfigurationListener);
750750

751+
void extLogger.log("Initializing CodeQL language server.");
752+
const languageClient = createLanguageClient(qlConfigurationListener);
753+
751754
void extLogger.log("Initializing CodeQL cli server...");
752755
const cliServer = new CodeQLCliServer(
753756
app,
757+
languageClient,
754758
distributionManager,
755759
new CliConfigListener(),
756760
extLogger,
@@ -961,9 +965,6 @@ async function activateWithInstalledDistribution(
961965

962966
ctx.subscriptions.push(tmpDirDisposal);
963967

964-
void extLogger.log("Initializing CodeQL language server.");
965-
const languageClient = createLanguageClient(qlConfigurationListener);
966-
967968
const localQueries = new LocalQueries(
968969
app,
969970
qs,

0 commit comments

Comments
 (0)