Merge pull request #2385 from github/aeisenberg/no-cache-contextual

Add `codeQL.contextualQueries.disableCache`
This commit is contained in:
Andrew Eisenberg
2023-05-01 07:30:34 -07:00
committed by GitHub
2 changed files with 44 additions and 7 deletions

View File

@@ -69,6 +69,10 @@ const ROOT_SETTING = new Setting("codeQL");
// Global configuration // Global configuration
const TELEMETRY_SETTING = new Setting("telemetry", ROOT_SETTING); const TELEMETRY_SETTING = new Setting("telemetry", ROOT_SETTING);
const AST_VIEWER_SETTING = new Setting("astViewer", ROOT_SETTING); const AST_VIEWER_SETTING = new Setting("astViewer", ROOT_SETTING);
const CONTEXTUAL_QUERIES_SETTINGS = new Setting(
"contextualQueries",
ROOT_SETTING,
);
const GLOBAL_TELEMETRY_SETTING = new Setting("telemetry"); const GLOBAL_TELEMETRY_SETTING = new Setting("telemetry");
const LOG_INSIGHTS_SETTING = new Setting("logInsights", ROOT_SETTING); const LOG_INSIGHTS_SETTING = new Setting("logInsights", ROOT_SETTING);
@@ -479,13 +483,21 @@ export function joinOrderWarningThreshold(): number {
} }
/** /**
* Avoids caching in the AST viewer if the user is also a canary user. * Hidden setting: Avoids caching in the AST viewer if the user is also a canary user.
*/ */
export const NO_CACHE_AST_VIEWER = new Setting( export const NO_CACHE_AST_VIEWER = new Setting(
"disableCache", "disableCache",
AST_VIEWER_SETTING, AST_VIEWER_SETTING,
); );
/**
* Hidden setting: Avoids caching in jump to def and find refs contextual queries if the user is also a canary user.
*/
export const NO_CACHE_CONTEXTUAL_QUERIES = new Setting(
"disableCache",
CONTEXTUAL_QUERIES_SETTINGS,
);
// Settings for variant analysis // Settings for variant analysis
const VARIANT_ANALYSIS_SETTING = new Setting("variantAnalysis", ROOT_SETTING); const VARIANT_ANALYSIS_SETTING = new Setting("variantAnalysis", ROOT_SETTING);

View File

@@ -30,7 +30,11 @@ import {
resolveQueries, resolveQueries,
runContextualQuery, runContextualQuery,
} from "./query-resolver"; } from "./query-resolver";
import { isCanary, NO_CACHE_AST_VIEWER } from "../../config"; import {
isCanary,
NO_CACHE_AST_VIEWER,
NO_CACHE_CONTEXTUAL_QUERIES,
} from "../../config";
import { CoreCompletedQuery, QueryRunner } from "../../query-server"; import { CoreCompletedQuery, QueryRunner } from "../../query-server";
import { AstBuilder } from "../ast-viewer/ast-builder"; import { AstBuilder } from "../ast-viewer/ast-builder";
@@ -59,7 +63,10 @@ export class TemplateQueryDefinitionProvider implements DefinitionProvider {
position: Position, position: Position,
_token: CancellationToken, _token: CancellationToken,
): Promise<LocationLink[]> { ): Promise<LocationLink[]> {
const fileLinks = await this.cache.get(document.uri.toString()); const fileLinks = this.shouldUseCache()
? await this.cache.get(document.uri.toString())
: await this.getDefinitions(document.uri.toString());
const locLinks: LocationLink[] = []; const locLinks: LocationLink[] = [];
for (const link of fileLinks) { for (const link of fileLinks) {
if (link.originSelectionRange!.contains(position)) { if (link.originSelectionRange!.contains(position)) {
@@ -69,6 +76,10 @@ export class TemplateQueryDefinitionProvider implements DefinitionProvider {
return locLinks; return locLinks;
} }
private shouldUseCache() {
return !(isCanary() && NO_CACHE_CONTEXTUAL_QUERIES.getValue<boolean>());
}
private async getDefinitions(uriString: string): Promise<LocationLink[]> { private async getDefinitions(uriString: string): Promise<LocationLink[]> {
return withProgress( return withProgress(
async (progress, token) => { async (progress, token) => {
@@ -118,7 +129,10 @@ export class TemplateQueryReferenceProvider implements ReferenceProvider {
_context: ReferenceContext, _context: ReferenceContext,
_token: CancellationToken, _token: CancellationToken,
): Promise<Location[]> { ): Promise<Location[]> {
const fileLinks = await this.cache.get(document.uri.toString()); const fileLinks = this.shouldUseCache()
? await this.cache.get(document.uri.toString())
: await this.getReferences(document.uri.toString());
const locLinks: Location[] = []; const locLinks: Location[] = [];
for (const link of fileLinks) { for (const link of fileLinks) {
if (link.targetRange!.contains(position)) { if (link.targetRange!.contains(position)) {
@@ -131,6 +145,10 @@ export class TemplateQueryReferenceProvider implements ReferenceProvider {
return locLinks; return locLinks;
} }
private shouldUseCache() {
return !(isCanary() && NO_CACHE_CONTEXTUAL_QUERIES.getValue<boolean>());
}
private async getReferences(uriString: string): Promise<FullLocationLink[]> { private async getReferences(uriString: string): Promise<FullLocationLink[]> {
return withProgress( return withProgress(
async (progress, token) => { async (progress, token) => {
@@ -182,7 +200,7 @@ export class TemplatePrintAstProvider {
"Cannot view the AST. Please select a valid source file inside a CodeQL database.", "Cannot view the AST. Please select a valid source file inside a CodeQL database.",
); );
} }
const completedQuery = this.shouldCache() const completedQuery = this.shouldUseCache()
? await this.cache.get(fileUri.toString(), progress, token) ? await this.cache.get(fileUri.toString(), progress, token)
: await this.getAst(fileUri.toString(), progress, token); : await this.getAst(fileUri.toString(), progress, token);
@@ -194,7 +212,7 @@ export class TemplatePrintAstProvider {
); );
} }
private shouldCache() { private shouldUseCache() {
return !(isCanary() && NO_CACHE_AST_VIEWER.getValue<boolean>()); return !(isCanary() && NO_CACHE_AST_VIEWER.getValue<boolean>());
} }
@@ -271,7 +289,14 @@ export class TemplatePrintCfgProvider {
if (!document) { if (!document) {
return; return;
} }
return await this.cache.get(document.uri.toString());
return this.shouldUseCache()
? await this.cache.get(document.uri.toString())
: await this.getCfgUri(document.uri.toString());
}
private shouldUseCache() {
return !(isCanary() && NO_CACHE_AST_VIEWER.getValue<boolean>());
} }
private async getCfgUri( private async getCfgUri(