Skip to content

Commit c082a38

Browse files
authored
Add a canary setting to avoid caching AST viewer queries (#818)
When codeql library developers are working on PrintAST queries, it is not easy to use the AST Viewer. The AST Viewer caches results so that multiple calls to view the AST of the same file are nearly instantaneous. However, this breaks down if you are changing the actual queries that perform AST viewing. In this case, you do not want the cache to be active. This commit adds an undocumented setting that prevents caching. To enable, set: ``` "codeQL.isCanary": true, "codeQL.astViewer.disableCache": true ``` Note that *both* settings must be true for this to work. This behaviour and all canary behaviour should be documented somewhere. I will add that later.
1 parent bdda277 commit c082a38

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const ROOT_SETTING = new Setting('codeQL');
4141

4242
// Global configuration
4343
const TELEMETRY_SETTING = new Setting('telemetry', ROOT_SETTING);
44+
const AST_VIEWER_SETTING = new Setting('astViewer', ROOT_SETTING);
4445
const GLOBAL_TELEMETRY_SETTING = new Setting('telemetry');
4546

4647
export const LOG_TELEMETRY = new Setting('logTelemetry', TELEMETRY_SETTING);
@@ -279,3 +280,8 @@ export const CANARY_FEATURES = new Setting('canary', ROOT_SETTING);
279280
export function isCanary() {
280281
return !!CANARY_FEATURES.getValue<boolean>();
281282
}
283+
284+
/**
285+
* Avoids caching in the AST viewer if the user is also a canary user.
286+
*/
287+
export const NO_CACHE_AST_VIEWER = new Setting('disableCache', AST_VIEWER_SETTING);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from './keyType';
2626
import { FullLocationLink, getLocationsForUriString, TEMPLATE_NAME } from './locationFinder';
2727
import { qlpackOfDatabase, resolveQueries } from './queryResolver';
28+
import { isCanary, NO_CACHE_AST_VIEWER } from '../config';
2829

2930
/**
3031
* Run templated CodeQL queries to find definitions and references in
@@ -141,7 +142,9 @@ export class TemplatePrintAstProvider {
141142
if (!document) {
142143
throw new Error('Cannot view the AST. Please select a valid source file inside a CodeQL database.');
143144
}
144-
const queryResults = await this.cache.get(document.uri.toString(), progress, token);
145+
const queryResults = this.shouldCache()
146+
? await this.cache.get(document.uri.toString(), progress, token)
147+
: await this.getAst(document.uri.toString(), progress, token);
145148

146149
return new AstBuilder(
147150
queryResults, this.cli,
@@ -150,6 +153,10 @@ export class TemplatePrintAstProvider {
150153
);
151154
}
152155

156+
private shouldCache() {
157+
return !(isCanary() && NO_CACHE_AST_VIEWER.getValue<boolean>());
158+
}
159+
153160
private async getAst(
154161
uriString: string,
155162
progress: ProgressCallback,

0 commit comments

Comments
 (0)