Skip to content

Commit

Permalink
Merge pull request #3845 from github/kaeluka/4654-fix-spurious-errors
Browse files Browse the repository at this point in the history
Fix Spurious Compilation Errors
  • Loading branch information
kaeluka authored Dec 2, 2024
2 parents 0f88b63 + 17542d1 commit d03b348
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
23 changes: 20 additions & 3 deletions extensions/ql-vscode/src/codeql-cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { LOGGING_FLAGS } from "./cli-command";
import type { CliFeatures, VersionAndFeatures } from "./cli-version";
import { ExitCodeError, getCliError } from "./cli-errors";
import { UserCancellationException } from "../common/vscode/progress";
import type { LanguageClient } from "vscode-languageclient/node";

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

constructor(
private readonly app: App,
private readonly languageClient: LanguageClient,
private distributionProvider: DistributionProvider,
private cliConfig: CliConfig,
public readonly logger: Logger,
Expand Down Expand Up @@ -1584,11 +1586,13 @@ export class CodeQLCliServer implements Disposable {
async packAdd(dir: string, queryLanguage: QueryLanguage) {
const args = ["--dir", dir];
args.push(`codeql/${queryLanguage}-all`);
return this.runCodeQlCliCommand(
const ret = await this.runCodeQlCliCommand(
["pack", "add"],
args,
`Adding and installing ${queryLanguage} pack dependency.`,
);
await this.notifyPackInstalled();
return ret;
}

/**
Expand Down Expand Up @@ -1623,16 +1627,18 @@ export class CodeQLCliServer implements Disposable {
args.push(
// Allow prerelease packs from the ql submodule.
"--allow-prerelease",
// Allow the use of --additional-packs argument without issueing a warning
// Allow the use of --additional-packs argument without issuing a warning
"--no-strict-mode",
...this.getAdditionalPacksArg(workspaceFolders),
);
}
return this.runJsonCodeQlCliCommandWithAuthentication(
const ret = await this.runJsonCodeQlCliCommandWithAuthentication(
["pack", "install"],
args,
"Installing pack dependencies",
);
await this.notifyPackInstalled();
return ret;
}

/**
Expand Down Expand Up @@ -1750,6 +1756,17 @@ export class CodeQLCliServer implements Disposable {
this._versionChangedListeners.push(listener);
}

/**
* This method should be called after a pack has been installed.
*
* This restarts the language client. Restarting the language client has the
* effect of removing compilation errors in open ql/qll files that are caused
* by the pack not having been installed previously.
*/
private async notifyPackInstalled() {
await this.languageClient.restart();
}

private async refreshVersion(): Promise<VersionAndFeatures> {
const distribution = await this.distributionProvider.getDistribution();
switch (distribution.kind) {
Expand Down
7 changes: 4 additions & 3 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,13 @@ async function activateWithInstalledDistribution(
);
ctx.subscriptions.push(qlConfigurationListener);

void extLogger.log("Initializing CodeQL language server.");
const languageClient = createLanguageClient(qlConfigurationListener);

void extLogger.log("Initializing CodeQL cli server...");
const cliServer = new CodeQLCliServer(
app,
languageClient,
distributionManager,
new CliConfigListener(),
extLogger,
Expand Down Expand Up @@ -961,9 +965,6 @@ async function activateWithInstalledDistribution(

ctx.subscriptions.push(tmpDirDisposal);

void extLogger.log("Initializing CodeQL language server.");
const languageClient = createLanguageClient(qlConfigurationListener);

const localQueries = new LocalQueries(
app,
qs,
Expand Down

0 comments on commit d03b348

Please sign in to comment.