Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Spurious Compilation Errors #3845

Merged
merged 3 commits into from
Dec 2, 2024
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
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
Loading