@@ -101,4 +101,28 @@ func TestSnapshot(t *testing.T) {
101
101
assert .Check (t , snapshotAfter .fs .diskFiles ["/home/projects/ts/p1/a.ts" ] == nil )
102
102
assert .Check (t , snapshotAfter .fs .diskFiles ["/home/projects/ts/p2/b.ts" ] != nil )
103
103
})
104
+
105
+ t .Run ("GetFile returns nil for non-existent files" , func (t * testing.T ) {
106
+ t .Parallel ()
107
+ files := map [string ]any {
108
+ "/home/projects/TS/p1/tsconfig.json" : "{}" ,
109
+ "/home/projects/TS/p1/index.ts" : "console.log('Hello, world!');" ,
110
+ }
111
+ session := setup (files )
112
+ session .DidOpenFile (context .Background (), "file:///home/projects/TS/p1/index.ts" , 1 , files ["/home/projects/TS/p1/index.ts" ].(string ), lsproto .LanguageKindTypeScript )
113
+ snapshot , release := session .Snapshot ()
114
+ defer release ()
115
+
116
+ // Test that GetFile returns nil for non-existent file (first call)
117
+ handle := snapshot .GetFile ("/home/projects/TS/p1/nonexistent.ts" )
118
+ assert .Check (t , handle == nil , "GetFile should return nil for non-existent file on first call" )
119
+
120
+ // Test that GetFile returns nil for non-existent file (second call - triggers the cached path)
121
+ handle2 := snapshot .GetFile ("/home/projects/TS/p1/nonexistent.ts" )
122
+ assert .Check (t , handle2 == nil , "GetFile should return nil for non-existent file on second call" )
123
+
124
+ // Test that ReadFile returns false for non-existent file
125
+ _ , ok := snapshot .ReadFile ("/home/projects/TS/p1/nonexistent.ts" )
126
+ assert .Check (t , ! ok , "ReadFile should return false for non-existent file" )
127
+ })
104
128
}
0 commit comments