Skip to content

Commit 639487b

Browse files
committed
AST viewer: Address review comments
Clear the CLI server's pack cache before installing packs, to avoid race conditions where the new lock file is not detected during query running. Adjust some helper methods.
1 parent f9a19b6 commit 639487b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

extensions/ql-vscode/src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -970,9 +970,9 @@ export class CodeQLCliServer implements Disposable {
970970
}
971971
}
972972

973-
async packResolveDependencies(dir: string, mode: 'use-lock'): Promise<{ [pack: string]: string }> {
974-
const args = ['--mode', mode, dir];
975-
const results: { [pack: string]: string } = await this.runJsonCodeQlCliCommand(['pack', 'resolve-dependencies'], args, 'Resolving pack dependencies');
973+
async packResolveDependencies(dir: string): Promise<{ [pack: string]: string }> {
974+
// Uses the default `--mode use-lock`, which creates the lock file if it doesn't exist.
975+
const results: { [pack: string]: string } = await this.runJsonCodeQlCliCommand(['pack', 'resolve-dependencies'], [dir], 'Resolving pack dependencies');
976976
return results;
977977
}
978978

extensions/ql-vscode/src/contextual/templateProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ export class TemplatePrintAstProvider {
230230
// Create a lock file so that we can resolve dependencies and library path
231231
// for the AST query.
232232
void logger.log(`Library pack ${packPath} is missing a lock file; creating a temporary lock file`);
233-
await this.cli.packResolveDependencies(packPath, 'use-lock');
233+
await this.cli.packResolveDependencies(packPath);
234+
// Clear CLI server pack cache before installing dependencies,
235+
// so that it picks up the new lock file, not the previously cached pack.
236+
void logger.log('Clearing the CodeQL CLI server\'s pack cache');
237+
await this.cli.clearCache();
234238
// Install dependencies.
235239
void logger.log(`Installing package dependencies for library pack ${packPath}`);
236240
await this.cli.packInstall(packPath);
@@ -260,7 +264,7 @@ export class TemplatePrintAstProvider {
260264
const tempLockFilePath = path.resolve(packPath, 'codeql-pack.lock.yml');
261265
void logger.log(`Deleting temporary package lock file at ${tempLockFilePath}`);
262266
// It's fine if the file doesn't exist.
263-
fs.rmSync(path.resolve(packPath, 'codeql-pack.lock.yml'), { force: true });
267+
await fs.promises.rm(path.resolve(packPath, 'codeql-pack.lock.yml'), { force: true });
264268
}
265269
return {
266270
query: queryResult,

0 commit comments

Comments
 (0)