Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions internal/project/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@ func TestSnapshot(t *testing.T) {
assert.Check(t, snapshotAfter.fs.diskFiles["/home/projects/ts/p1/a.ts"] == nil)
assert.Check(t, snapshotAfter.fs.diskFiles["/home/projects/ts/p2/b.ts"] != nil)
})

t.Run("GetFile returns nil for non-existent files", func(t *testing.T) {
t.Parallel()
files := map[string]any{
"/home/projects/TS/p1/tsconfig.json": "{}",
"/home/projects/TS/p1/index.ts": "console.log('Hello, world!');",
}
session := setup(files)
session.DidOpenFile(context.Background(), "file:///home/projects/TS/p1/index.ts", 1, files["/home/projects/TS/p1/index.ts"].(string), lsproto.LanguageKindTypeScript)
snapshot, release := session.Snapshot()
defer release()

handle := snapshot.GetFile("/home/projects/TS/p1/nonexistent.ts")
assert.Check(t, handle == nil, "GetFile should return nil for non-existent file")

// Test that ReadFile returns false for non-existent file
_, ok := snapshot.ReadFile("/home/projects/TS/p1/nonexistent.ts")
assert.Check(t, !ok, "ReadFile should return false for non-existent file")
})
}
8 changes: 5 additions & 3 deletions internal/project/snapshotfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ func (s *snapshotFS) GetFile(fileName string) FileHandle {
}
return nil
}))
if entry, ok := s.readFiles.LoadOrStore(s.toPath(fileName), newEntry); ok {
return entry()
entry, _ := s.readFiles.LoadOrStore(s.toPath(fileName), newEntry)
file := entry()
if file == nil {
return nil
}
return nil
return file
}

type snapshotFSBuilder struct {
Expand Down