@@ -62,6 +62,8 @@ type file struct {
6262 objectInfo storage.ObjectInfo // Info in the context of the workspace.
6363
6464 ir * ir.File
65+ irQuery queries.IR
66+ fileQuery queries.File
6567 referenceableSymbols map [ir.FullName ]* symbol
6668 referenceSymbols []* symbol
6769 symbols []* symbol
@@ -97,6 +99,11 @@ func (f *file) Reset(ctx context.Context) {
9799 f .workspace .Release ()
98100 f .workspace = nil
99101 }
102+ // Evict the query key if there is a query cached on the file. We cache the [queries.File]
103+ // query since this allows the executor to evict all dependent queries, e.g. AST and IR.
104+ if f .fileQuery .Path != "" {
105+ f .lsp .queryExecutor .Evict (f .fileQuery .Key ())
106+ }
100107 // Clear the file as nothing should use it after reset. This asserts that.
101108 * f = file {}
102109}
@@ -221,31 +228,46 @@ func (f *file) RefreshIR(ctx context.Context) {
221228 // Opener creates a cached view of all files in the workspace.
222229 pathToFiles := f .workspace .PathToFile ()
223230 files := make ([]* file , 0 , len (pathToFiles ))
231+ var evictQueryKeys []any
224232
225233 openerMap := f .lsp .opener .Get ()
226234 for path , file := range pathToFiles {
227235 current := openerMap [path ]
228236 // If there is no entry for the current path or if the file content has changed, we
229- // update the opener.
237+ // update the opener and set a new query .
230238 if current == nil || current .Text () != file .file .Text () {
231239 openerMap [path ] = file .file
240+ // Add the query key for eviction if there is a query cached on the file. We cache
241+ // the [queries.File] query since this allows the executor to evict all dependent
242+ // queries, e.g. AST and IR.
243+ if file .fileQuery .Path != "" {
244+ evictQueryKeys = append (evictQueryKeys , file .fileQuery .Key ())
245+ }
246+ file .fileQuery = queries.File {
247+ Opener : file .lsp .opener ,
248+ Path : path ,
249+ ReportError : true , // [queries.AST] sets this to be true.
250+ }
251+ file .irQuery = queries.IR {
252+ Opener : file .lsp .opener ,
253+ Path : file .objectInfo .Path (),
254+ Session : file .lsp .irSession ,
255+ }
232256 }
233257 files = append (files , file )
234258 }
235- // Remove paths that are no longer in the current workspace.
259+ // Remove paths that are no longer in the current workspace and evict stale query keys .
236260 for path := range openerMap {
237261 if _ , ok := pathToFiles [path ]; ! ok {
238262 delete (openerMap , path )
239263 }
240264 }
265+ f .lsp .queryExecutor .Evict (evictQueryKeys ... )
241266
242267 queries := xslices .Map (files , func (file * file ) incremental.Query [* ir.File ] {
243- return queries.IR {
244- Opener : f .lsp .opener ,
245- Path : file .objectInfo .Path (),
246- Session : f .lsp .irSession ,
247- }
268+ return file .irQuery
248269 })
270+
249271 results , diagnosticReport , err := incremental .Run (
250272 ctx ,
251273 f .lsp .queryExecutor ,
0 commit comments