Skip to content

Commit 97c985b

Browse files
committed
Contextual queries: Record whether a temp lock file was created
1 parent 84b9d9c commit 97c985b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export async function resolveQueries(cli: CodeQLCliServer, qlpacks: QlPacksForLa
111111
throw new Error(`Couldn't find any queries tagged ${tagOfKeyType(keyType)} in any of the following packs: ${packsToSearch.join(', ')}.`);
112112
}
113113

114-
async function resolveContextualQuery(cli: CodeQLCliServer, query: string): Promise<{ packPath: string, lockFilePath?: string }> {
114+
async function resolveContextualQuery(cli: CodeQLCliServer, query: string): Promise<{ packPath: string, createdTempLockFile: boolean }> {
115115
// Contextual queries now live within the standard library packs.
116116
// This simplifies distribution (you don't need the standard query pack to use the AST viewer),
117117
// but if the library pack doesn't have a lockfile, we won't be able to find
@@ -126,12 +126,14 @@ async function resolveContextualQuery(cli: CodeQLCliServer, query: string): Prom
126126
}
127127
const packPath = path.dirname(packFilePath);
128128
const lockFilePath = packContents.find((p) => ['codeql-pack.lock.yml', 'qlpack.lock.yml'].includes(path.basename(p)));
129+
let createdTempLockFile = false;
129130
if (!lockFilePath) {
130131
// No lock file, likely because this library pack is in the package cache.
131132
// Create a lock file so that we can resolve dependencies and library path
132133
// for the contextual query.
133134
void logger.log(`Library pack ${packPath} is missing a lock file; creating a temporary lock file`);
134135
await cli.packResolveDependencies(packPath);
136+
createdTempLockFile = true;
135137
// Clear CLI server pack cache before installing dependencies,
136138
// so that it picks up the new lock file, not the previously cached pack.
137139
void logger.log('Clearing the CodeQL CLI server\'s pack cache');
@@ -140,7 +142,7 @@ async function resolveContextualQuery(cli: CodeQLCliServer, query: string): Prom
140142
void logger.log(`Installing package dependencies for library pack ${packPath}`);
141143
await cli.packInstall(packPath);
142144
}
143-
return { packPath, lockFilePath };
145+
return { packPath, createdTempLockFile };
144146
}
145147

146148
async function removeTemporaryLockFile(packPath: string) {
@@ -151,7 +153,7 @@ async function removeTemporaryLockFile(packPath: string) {
151153
}
152154

153155
export async function runContextualQuery(query: string, db: DatabaseItem, queryStorageDir: string, qs: QueryRunner, cli: CodeQLCliServer, progress: ProgressCallback, token: CancellationToken, templates: Record<string, string>) {
154-
const { packPath, lockFilePath } = await resolveContextualQuery(cli, query);
156+
const { packPath, createdTempLockFile } = await resolveContextualQuery(cli, query);
155157
const initialInfo = await createInitialQueryInfo(
156158
Uri.file(query),
157159
{
@@ -169,7 +171,7 @@ export async function runContextualQuery(query: string, db: DatabaseItem, queryS
169171
token,
170172
templates
171173
);
172-
if (!lockFilePath) {
174+
if (createdTempLockFile) {
173175
await removeTemporaryLockFile(packPath);
174176
}
175177
return queryResult;

0 commit comments

Comments
 (0)