notify language client of updated packages from cli.ts
This commit is contained in:
@@ -8,7 +8,10 @@ import type { Log } from "sarif";
|
|||||||
import { SemVer } from "semver";
|
import { SemVer } from "semver";
|
||||||
import type { Readable } from "stream";
|
import type { Readable } from "stream";
|
||||||
import tk from "tree-kill";
|
import tk from "tree-kill";
|
||||||
import type { CancellationToken, Disposable, Uri } from "vscode";
|
import type { CancellationToken, Disposable } from "vscode";
|
||||||
|
import { Uri } from "vscode";
|
||||||
|
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
BqrsInfo,
|
BqrsInfo,
|
||||||
@@ -37,6 +40,11 @@ import { LOGGING_FLAGS } from "./cli-command";
|
|||||||
import type { CliFeatures, VersionAndFeatures } from "./cli-version";
|
import type { CliFeatures, VersionAndFeatures } from "./cli-version";
|
||||||
import { ExitCodeError, getCliError } from "./cli-errors";
|
import { ExitCodeError, getCliError } from "./cli-errors";
|
||||||
import { UserCancellationException } from "../common/vscode/progress";
|
import { UserCancellationException } from "../common/vscode/progress";
|
||||||
|
import type { LanguageClient } from "vscode-languageclient/node";
|
||||||
|
import {
|
||||||
|
DidChangeWatchedFilesNotification,
|
||||||
|
FileChangeType,
|
||||||
|
} from "vscode-languageclient/node";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The version of the SARIF format that we are using.
|
* The version of the SARIF format that we are using.
|
||||||
@@ -277,6 +285,7 @@ export class CodeQLCliServer implements Disposable {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly app: App,
|
private readonly app: App,
|
||||||
|
private readonly languageClient: LanguageClient,
|
||||||
private distributionProvider: DistributionProvider,
|
private distributionProvider: DistributionProvider,
|
||||||
private cliConfig: CliConfig,
|
private cliConfig: CliConfig,
|
||||||
public readonly logger: Logger,
|
public readonly logger: Logger,
|
||||||
@@ -1584,11 +1593,13 @@ export class CodeQLCliServer implements Disposable {
|
|||||||
async packAdd(dir: string, queryLanguage: QueryLanguage) {
|
async packAdd(dir: string, queryLanguage: QueryLanguage) {
|
||||||
const args = ["--dir", dir];
|
const args = ["--dir", dir];
|
||||||
args.push(`codeql/${queryLanguage}-all`);
|
args.push(`codeql/${queryLanguage}-all`);
|
||||||
return this.runCodeQlCliCommand(
|
const ret = await this.runCodeQlCliCommand(
|
||||||
["pack", "add"],
|
["pack", "add"],
|
||||||
args,
|
args,
|
||||||
`Adding and installing ${queryLanguage} pack dependency.`,
|
`Adding and installing ${queryLanguage} pack dependency.`,
|
||||||
);
|
);
|
||||||
|
await this.notifyPackChanged(dir);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1628,11 +1639,13 @@ export class CodeQLCliServer implements Disposable {
|
|||||||
...this.getAdditionalPacksArg(workspaceFolders),
|
...this.getAdditionalPacksArg(workspaceFolders),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return this.runJsonCodeQlCliCommandWithAuthentication(
|
const ret = await this.runJsonCodeQlCliCommandWithAuthentication(
|
||||||
["pack", "install"],
|
["pack", "install"],
|
||||||
args,
|
args,
|
||||||
"Installing pack dependencies",
|
"Installing pack dependencies",
|
||||||
);
|
);
|
||||||
|
await this.notifyPackChanged(dir);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1750,6 +1763,29 @@ export class CodeQLCliServer implements Disposable {
|
|||||||
this._versionChangedListeners.push(listener);
|
this._versionChangedListeners.push(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async notifyPackChanged(packDir: string) {
|
||||||
|
const packFilePath = join(packDir, "codeql-pack.yml");
|
||||||
|
if (!existsSync(packFilePath)) {
|
||||||
|
throw new Error(`Pack file ${packFilePath} does not exist`);
|
||||||
|
}
|
||||||
|
await this.languageClient.sendNotification(
|
||||||
|
DidChangeWatchedFilesNotification.type,
|
||||||
|
{
|
||||||
|
changes: [
|
||||||
|
{
|
||||||
|
type: FileChangeType.Changed,
|
||||||
|
uri: Uri.file(packFilePath).toString(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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:
|
||||||
|
await this.languageClient.restart();
|
||||||
|
}
|
||||||
|
|
||||||
private async refreshVersion(): Promise<VersionAndFeatures> {
|
private async refreshVersion(): Promise<VersionAndFeatures> {
|
||||||
const distribution = await this.distributionProvider.getDistribution();
|
const distribution = await this.distributionProvider.getDistribution();
|
||||||
switch (distribution.kind) {
|
switch (distribution.kind) {
|
||||||
|
|||||||
@@ -748,9 +748,13 @@ async function activateWithInstalledDistribution(
|
|||||||
);
|
);
|
||||||
ctx.subscriptions.push(qlConfigurationListener);
|
ctx.subscriptions.push(qlConfigurationListener);
|
||||||
|
|
||||||
|
void extLogger.log("Initializing CodeQL language server.");
|
||||||
|
const languageClient = createLanguageClient(qlConfigurationListener);
|
||||||
|
|
||||||
void extLogger.log("Initializing CodeQL cli server...");
|
void extLogger.log("Initializing CodeQL cli server...");
|
||||||
const cliServer = new CodeQLCliServer(
|
const cliServer = new CodeQLCliServer(
|
||||||
app,
|
app,
|
||||||
|
languageClient,
|
||||||
distributionManager,
|
distributionManager,
|
||||||
new CliConfigListener(),
|
new CliConfigListener(),
|
||||||
extLogger,
|
extLogger,
|
||||||
@@ -961,9 +965,6 @@ async function activateWithInstalledDistribution(
|
|||||||
|
|
||||||
ctx.subscriptions.push(tmpDirDisposal);
|
ctx.subscriptions.push(tmpDirDisposal);
|
||||||
|
|
||||||
void extLogger.log("Initializing CodeQL language server.");
|
|
||||||
const languageClient = createLanguageClient(qlConfigurationListener);
|
|
||||||
|
|
||||||
const localQueries = new LocalQueries(
|
const localQueries = new LocalQueries(
|
||||||
app,
|
app,
|
||||||
qs,
|
qs,
|
||||||
|
|||||||
Reference in New Issue
Block a user