@@ -8,7 +8,10 @@ import type { Log } from "sarif";
88import { SemVer } from "semver" ;
99import type { Readable } from "stream" ;
1010import tk from "tree-kill" ;
11- import type { CancellationToken , Disposable , Uri } from "vscode" ;
11+ import type { CancellationToken , Disposable } from "vscode" ;
12+ import { Uri } from "vscode" ;
13+
14+ import { existsSync } from "fs" ;
1215
1316import type {
1417 BqrsInfo ,
@@ -37,6 +40,11 @@ import { LOGGING_FLAGS } from "./cli-command";
3740import type { CliFeatures , VersionAndFeatures } from "./cli-version" ;
3841import { ExitCodeError , getCliError } from "./cli-errors" ;
3942import { UserCancellationException } from "../common/vscode/progress" ;
43+ import type { LanguageClient } from "vscode-languageclient/node" ;
44+ import {
45+ DidChangeWatchedFilesNotification ,
46+ FileChangeType ,
47+ } from "vscode-languageclient/node" ;
4048
4149/**
4250 * The version of the SARIF format that we are using.
@@ -277,6 +285,7 @@ export class CodeQLCliServer implements Disposable {
277285
278286 constructor (
279287 private readonly app : App ,
288+ private readonly languageClient : LanguageClient ,
280289 private distributionProvider : DistributionProvider ,
281290 private cliConfig : CliConfig ,
282291 public readonly logger : Logger ,
@@ -1584,11 +1593,13 @@ export class CodeQLCliServer implements Disposable {
15841593 async packAdd ( dir : string , queryLanguage : QueryLanguage ) {
15851594 const args = [ "--dir" , dir ] ;
15861595 args . push ( `codeql/${ queryLanguage } -all` ) ;
1587- return this . runCodeQlCliCommand (
1596+ const ret = await this . runCodeQlCliCommand (
15881597 [ "pack" , "add" ] ,
15891598 args ,
15901599 `Adding and installing ${ queryLanguage } pack dependency.` ,
15911600 ) ;
1601+ await this . notifyPackChanged ( dir ) ;
1602+ return ret ;
15921603 }
15931604
15941605 /**
@@ -1628,11 +1639,13 @@ export class CodeQLCliServer implements Disposable {
16281639 ...this . getAdditionalPacksArg ( workspaceFolders ) ,
16291640 ) ;
16301641 }
1631- return this . runJsonCodeQlCliCommandWithAuthentication (
1642+ const ret = await this . runJsonCodeQlCliCommandWithAuthentication (
16321643 [ "pack" , "install" ] ,
16331644 args ,
16341645 "Installing pack dependencies" ,
16351646 ) ;
1647+ await this . notifyPackChanged ( dir ) ;
1648+ return ret ;
16361649 }
16371650
16381651 /**
@@ -1750,6 +1763,29 @@ export class CodeQLCliServer implements Disposable {
17501763 this . _versionChangedListeners . push ( listener ) ;
17511764 }
17521765
1766+ private async notifyPackChanged ( packDir : string ) {
1767+ const packFilePath = join ( packDir , "codeql-pack.yml" ) ;
1768+ if ( ! existsSync ( packFilePath ) ) {
1769+ throw new Error ( `Pack file ${ packFilePath } does not exist` ) ;
1770+ }
1771+ await this . languageClient . sendNotification (
1772+ DidChangeWatchedFilesNotification . type ,
1773+ {
1774+ changes : [
1775+ {
1776+ type : FileChangeType . Changed ,
1777+ uri : Uri . file ( packFilePath ) . toString ( ) ,
1778+ } ,
1779+ ] ,
1780+ } ,
1781+ ) ;
1782+
1783+ // restarting the language client has the effect of removing compilation
1784+ // errors in open ql/qll files that are caused by the pack not having been
1785+ // installed previously:
1786+ await this . languageClient . restart ( ) ;
1787+ }
1788+
17531789 private async refreshVersion ( ) : Promise < VersionAndFeatures > {
17541790 const distribution = await this . distributionProvider . getDistribution ( ) ;
17551791 switch ( distribution . kind ) {
0 commit comments