@@ -17,7 +17,6 @@ package buflsp
1717import (
1818 "context"
1919 "fmt"
20- "io/fs"
2120 "iter"
2221 "log/slog"
2322
@@ -139,11 +138,13 @@ type workspace struct {
139138
140139// Lease increments the reference count.
141140func (w * workspace ) Lease () {
141+ w .lsp .logger .Debug ("workspace: lease" , slog .String ("path" , w .workspaceURI .Filename ()))
142142 w .refCount ++
143143}
144144
145145// Release decrements the reference count.
146146func (w * workspace ) Release () int {
147+ w .lsp .logger .Debug ("workspace: release" , slog .String ("path" , w .workspaceURI .Filename ()))
147148 w .refCount --
148149 return w .refCount
149150}
@@ -228,18 +229,6 @@ func (w *workspace) CheckClient() bufcheck.Client {
228229 return w .checkClient
229230}
230231
231- // Open implements [github.com/bufbuild/protocompile/experimental/source.Opener].
232- func (w * workspace ) Open (path string ) (string , error ) {
233- if w .workspace == nil {
234- return "" , fs .ErrNotExist
235- }
236- file , ok := w .pathToFile [path ]
237- if ! ok {
238- return "" , fs .ErrNotExist
239- }
240- return file .file .Text (), nil
241- }
242-
243232// PathToFile is an index of all files within the workspace.
244233func (w * workspace ) PathToFile () map [string ]* file {
245234 if w == nil {
@@ -250,12 +239,17 @@ func (w *workspace) PathToFile() map[string]*file {
250239
251240// indexFiles builds the pathToFile mapping.
252241func (w * workspace ) indexFiles (ctx context.Context ) {
253- unused := w .pathToFile
254- w .pathToFile = make (map [string ]* file , len (unused ))
242+ w .lsp .logger .Debug ("workspace: index files" , slog .String ("path" , w .workspaceURI .Filename ()))
243+ previous := w .pathToFile
244+ w .pathToFile = make (map [string ]* file , len (previous ))
255245
256246 for fileInfo := range w .fileInfos (ctx ) {
257- fileURI := uri .File (fileInfo .LocalPath ())
258- file := w .lsp .fileManager .Track (fileURI )
247+ file , ok := previous [fileInfo .Path ()]
248+ if ! ok {
249+ fileURI := uri .File (fileInfo .LocalPath ())
250+ file = w .lsp .fileManager .Track (fileURI )
251+ w .lsp .logger .Debug ("workspace: index track file" , slog .String ("path" , file .uri .Filename ()))
252+ }
259253
260254 // Currently we only associate a file with one workspace. This assumption isn't accurate
261255 // for shared dependencies. Here we update to the lastest, most recently used, workspace.
@@ -277,10 +271,11 @@ func (w *workspace) indexFiles(ctx context.Context) {
277271
278272 // Update index.
279273 w .pathToFile [fileInfo .Path ()] = file
280- delete (unused , fileInfo .Path ())
274+ delete (previous , fileInfo .Path ())
281275 }
282276 // Drop all unused files. It was deleted from the workspace.
283- for _ , file := range unused {
277+ for _ , file := range previous {
278+ w .lsp .logger .Debug ("workspace: index drop file" , slog .String ("path" , file .uri .Filename ()))
284279 file .Close (ctx )
285280 }
286281}
0 commit comments