Skip to content

Commit 5ce4576

Browse files
committed
Add codeQL.contextualQueries.disableCache
An internal option to help library authours to run and debug the find references and find dependencies contetextual queries without relying on the implicit cache.
1 parent f4a3115 commit 5ce4576

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ const ROOT_SETTING = new Setting("codeQL");
6969
// Global configuration
7070
const TELEMETRY_SETTING = new Setting("telemetry", ROOT_SETTING);
7171
const AST_VIEWER_SETTING = new Setting("astViewer", ROOT_SETTING);
72+
const CONTEXTUAL_QUERIES_SETTINGS = new Setting(
73+
"contextualQueries",
74+
ROOT_SETTING,
75+
);
7276
const GLOBAL_TELEMETRY_SETTING = new Setting("telemetry");
7377
const LOG_INSIGHTS_SETTING = new Setting("logInsights", ROOT_SETTING);
7478

@@ -479,13 +483,21 @@ export function joinOrderWarningThreshold(): number {
479483
}
480484

481485
/**
482-
* Avoids caching in the AST viewer if the user is also a canary user.
486+
* Hidden setting: Avoids caching in the AST viewer if the user is also a canary user.
483487
*/
484488
export const NO_CACHE_AST_VIEWER = new Setting(
485489
"disableCache",
486490
AST_VIEWER_SETTING,
487491
);
488492

493+
/**
494+
* Hidden setting: Avoids caching in jump to def and find refs contextual queries if the user is also a canary user.
495+
*/
496+
export const NO_CACHE_CONTEXTUAL_QUERIES = new Setting(
497+
"disableCache",
498+
CONTEXTUAL_QUERIES_SETTINGS,
499+
);
500+
489501
// Settings for variant analysis
490502
const VARIANT_ANALYSIS_SETTING = new Setting("variantAnalysis", ROOT_SETTING);
491503

extensions/ql-vscode/src/language-support/contextual/template-provider.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import {
3030
resolveQueries,
3131
runContextualQuery,
3232
} from "./query-resolver";
33-
import { isCanary, NO_CACHE_AST_VIEWER } from "../../config";
33+
import {
34+
isCanary,
35+
NO_CACHE_AST_VIEWER,
36+
NO_CACHE_CONTEXTUAL_QUERIES,
37+
} from "../../config";
3438
import { CoreCompletedQuery, QueryRunner } from "../../query-server";
3539
import { AstBuilder } from "../ast-viewer/ast-builder";
3640

@@ -59,7 +63,10 @@ export class TemplateQueryDefinitionProvider implements DefinitionProvider {
5963
position: Position,
6064
_token: CancellationToken,
6165
): Promise<LocationLink[]> {
62-
const fileLinks = await this.cache.get(document.uri.toString());
66+
const fileLinks = this.shouldUseCache()
67+
? await this.cache.get(document.uri.toString())
68+
: await this.getDefinitions(document.uri.toString());
69+
6370
const locLinks: LocationLink[] = [];
6471
for (const link of fileLinks) {
6572
if (link.originSelectionRange!.contains(position)) {
@@ -69,6 +76,10 @@ export class TemplateQueryDefinitionProvider implements DefinitionProvider {
6976
return locLinks;
7077
}
7178

79+
private shouldUseCache() {
80+
return !(isCanary() && NO_CACHE_CONTEXTUAL_QUERIES.getValue<boolean>());
81+
}
82+
7283
private async getDefinitions(uriString: string): Promise<LocationLink[]> {
7384
return withProgress(
7485
async (progress, token) => {
@@ -118,7 +129,10 @@ export class TemplateQueryReferenceProvider implements ReferenceProvider {
118129
_context: ReferenceContext,
119130
_token: CancellationToken,
120131
): Promise<Location[]> {
121-
const fileLinks = await this.cache.get(document.uri.toString());
132+
const fileLinks = this.shouldUseCache()
133+
? await this.cache.get(document.uri.toString())
134+
: await this.getReferences(document.uri.toString());
135+
122136
const locLinks: Location[] = [];
123137
for (const link of fileLinks) {
124138
if (link.targetRange!.contains(position)) {
@@ -131,6 +145,10 @@ export class TemplateQueryReferenceProvider implements ReferenceProvider {
131145
return locLinks;
132146
}
133147

148+
private shouldUseCache() {
149+
return !(isCanary() && NO_CACHE_CONTEXTUAL_QUERIES.getValue<boolean>());
150+
}
151+
134152
private async getReferences(uriString: string): Promise<FullLocationLink[]> {
135153
return withProgress(
136154
async (progress, token) => {
@@ -182,7 +200,7 @@ export class TemplatePrintAstProvider {
182200
"Cannot view the AST. Please select a valid source file inside a CodeQL database.",
183201
);
184202
}
185-
const completedQuery = this.shouldCache()
203+
const completedQuery = this.shouldUseCache()
186204
? await this.cache.get(fileUri.toString(), progress, token)
187205
: await this.getAst(fileUri.toString(), progress, token);
188206

@@ -194,7 +212,7 @@ export class TemplatePrintAstProvider {
194212
);
195213
}
196214

197-
private shouldCache() {
215+
private shouldUseCache() {
198216
return !(isCanary() && NO_CACHE_AST_VIEWER.getValue<boolean>());
199217
}
200218

@@ -271,7 +289,14 @@ export class TemplatePrintCfgProvider {
271289
if (!document) {
272290
return;
273291
}
274-
return await this.cache.get(document.uri.toString());
292+
293+
return this.shouldUseCache()
294+
? await this.cache.get(document.uri.toString())
295+
: await this.getCfgUri(document.uri.toString());
296+
}
297+
298+
private shouldUseCache() {
299+
return !(isCanary() && NO_CACHE_AST_VIEWER.getValue<boolean>());
275300
}
276301

277302
private async getCfgUri(

0 commit comments

Comments
 (0)