@@ -62,8 +62,6 @@ 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
6765 referenceableSymbols map [ir.FullName ]* symbol
6866 referenceSymbols []* symbol
6967 symbols []* symbol
@@ -101,9 +99,7 @@ func (f *file) Reset(ctx context.Context) {
10199 }
102100 // Evict the query key if there is a query cached on the file. We cache the [queries.File]
103101 // 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- }
102+ f .lsp .queryExecutor .Evict (f .queryFileKeys ()... )
107103 // Clear the file as nothing should use it after reset. This asserts that.
108104 * f = file {}
109105}
@@ -245,21 +241,9 @@ func (f *file) RefreshIR(ctx context.Context) {
245241 // update the opener and set a new query.
246242 if current == nil || current .Text () != file .file .Text () {
247243 openerMap [path ] = file .file
248- // Add the query key for eviction if there is a query cached on the file. We cache
249- // the [queries.File] query since this allows the executor to evict all dependent
250- // queries, e.g. AST and IR.
251- if file .fileQuery .Path != "" {
252- evictQueryKeys = append (evictQueryKeys , file .fileQuery .Key ())
253- }
254- file .fileQuery = queries.File {
255- Opener : file .lsp .opener ,
256- Path : path ,
257- ReportError : true , // [queries.AST] sets this to be true.
258- }
259- file .irQuery = queries.IR {
260- Opener : file .lsp .opener ,
261- Path : file .objectInfo .Path (),
262- Session : file .lsp .irSession ,
244+ if current != nil {
245+ // This indicates the file content has changed, so we evict the query file keys.
246+ evictQueryKeys = append (evictQueryKeys , file .queryFileKeys ()... )
263247 }
264248 }
265249 files = append (files , file )
@@ -273,7 +257,7 @@ func (f *file) RefreshIR(ctx context.Context) {
273257 f .lsp .queryExecutor .Evict (evictQueryKeys ... )
274258
275259 queries := xslices .Map (files , func (file * file ) incremental.Query [* ir.File ] {
276- return file .irQuery
260+ return file .queryIR ()
277261 })
278262
279263 results , diagnosticReport , err := incremental .Run (
@@ -319,6 +303,40 @@ func (f *file) RefreshIR(ctx context.Context) {
319303 )
320304}
321305
306+ // queryIR returns the [queries.IR] for the current file.
307+ func (f * file ) queryIR () incremental.Query [* ir.File ] {
308+ if f .objectInfo == nil {
309+ return nil
310+ }
311+ return queries.IR {
312+ Opener : f .lsp .opener ,
313+ Path : f .objectInfo .Path (),
314+ Session : f .lsp .irSession ,
315+ }
316+ }
317+
318+ // queryFileKeys returns the keys for [queries.File] with ReportError set to true and false.
319+ // This is because [queries.AST] depends on ReportError set to true and [queries.IR] depends
320+ // on ReportError set to false, so we need both keys when evicting cached [queries.File]
321+ // results for stale file states.
322+ func (f * file ) queryFileKeys () []any {
323+ if f .objectInfo == nil {
324+ return nil
325+ }
326+ return []any {
327+ queries.File {
328+ Opener : f .lsp .opener ,
329+ Path : f .objectInfo .Path (),
330+ ReportError : true ,
331+ }.Key (),
332+ queries.File {
333+ Opener : f .lsp .opener ,
334+ Path : f .objectInfo .Path (),
335+ ReportError : false ,
336+ }.Key (),
337+ }
338+ }
339+
322340// IndexSymbols processes the IR of a file and generates symbols for each symbol in
323341// the document.
324342//
0 commit comments