Skip to content

Commit d03b348

Browse files
author
Stephan Brandauer
authored
Merge pull request #3845 from github/kaeluka/4654-fix-spurious-errors
Fix Spurious Compilation Errors
2 parents 0f88b63 + 17542d1 commit d03b348

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { LOGGING_FLAGS } from "./cli-command";
3737
import type { CliFeatures, VersionAndFeatures } from "./cli-version";
3838
import { ExitCodeError, getCliError } from "./cli-errors";
3939
import { UserCancellationException } from "../common/vscode/progress";
40+
import type { LanguageClient } from "vscode-languageclient/node";
4041

4142
/**
4243
* The version of the SARIF format that we are using.
@@ -277,6 +278,7 @@ export class CodeQLCliServer implements Disposable {
277278

278279
constructor(
279280
private readonly app: App,
281+
private readonly languageClient: LanguageClient,
280282
private distributionProvider: DistributionProvider,
281283
private cliConfig: CliConfig,
282284
public readonly logger: Logger,
@@ -1584,11 +1586,13 @@ export class CodeQLCliServer implements Disposable {
15841586
async packAdd(dir: string, queryLanguage: QueryLanguage) {
15851587
const args = ["--dir", dir];
15861588
args.push(`codeql/${queryLanguage}-all`);
1587-
return this.runCodeQlCliCommand(
1589+
const ret = await this.runCodeQlCliCommand(
15881590
["pack", "add"],
15891591
args,
15901592
`Adding and installing ${queryLanguage} pack dependency.`,
15911593
);
1594+
await this.notifyPackInstalled();
1595+
return ret;
15921596
}
15931597

15941598
/**
@@ -1623,16 +1627,18 @@ export class CodeQLCliServer implements Disposable {
16231627
args.push(
16241628
// Allow prerelease packs from the ql submodule.
16251629
"--allow-prerelease",
1626-
// Allow the use of --additional-packs argument without issueing a warning
1630+
// Allow the use of --additional-packs argument without issuing a warning
16271631
"--no-strict-mode",
16281632
...this.getAdditionalPacksArg(workspaceFolders),
16291633
);
16301634
}
1631-
return this.runJsonCodeQlCliCommandWithAuthentication(
1635+
const ret = await this.runJsonCodeQlCliCommandWithAuthentication(
16321636
["pack", "install"],
16331637
args,
16341638
"Installing pack dependencies",
16351639
);
1640+
await this.notifyPackInstalled();
1641+
return ret;
16361642
}
16371643

16381644
/**
@@ -1750,6 +1756,17 @@ export class CodeQLCliServer implements Disposable {
17501756
this._versionChangedListeners.push(listener);
17511757
}
17521758

1759+
/**
1760+
* This method should be called after a pack has been installed.
1761+
*
1762+
* This restarts the language client. Restarting the language client has the
1763+
* effect of removing compilation errors in open ql/qll files that are caused
1764+
* by the pack not having been installed previously.
1765+
*/
1766+
private async notifyPackInstalled() {
1767+
await this.languageClient.restart();
1768+
}
1769+
17531770
private async refreshVersion(): Promise<VersionAndFeatures> {
17541771
const distribution = await this.distributionProvider.getDistribution();
17551772
switch (distribution.kind) {

extensions/ql-vscode/src/extension.ts

Lines changed: 4 additions & 3 deletions
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)