@@ -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" ;
3438import { CoreCompletedQuery , QueryRunner } from "../../query-server" ;
3539import { 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