@@ -5,12 +5,51 @@ import (
55 "testing"
66
77 "github.com/microsoft/TypeScript/tsc/internal/bundled"
8+ "github.com/microsoft/TypeScript/tsc/internal/core"
89 "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto"
910 "github.com/microsoft/TypeScript/tsc/internal/testutil/projecttestutil"
1011 "github.com/microsoft/TypeScript/tsc/internal/tspath"
1112 "gotest.tools/v3/assert"
1213)
1314
15+ func TestStandaloneSessionUsesSnapshotHostWithoutProjectSession (t * testing.T ) {
16+ t .Parallel ()
17+ if ! bundled .Embedded {
18+ t .Skip ("bundled files are not embedded" )
19+ }
20+
21+ const configFileName = "/home/projects/p/tsconfig.json"
22+ init , _ := projecttestutil .GetSessionInitOptions (map [string ]any {
23+ configFileName : `{ "compilerOptions": { "strict": true } }` ,
24+ "/home/projects/p/src/index.ts" : `export const x = 1;` ,
25+ }, nil , & projecttestutil.TypingsInstallerOptions {})
26+ session := NewStandaloneSession (init , nil )
27+ defer session .Close ()
28+
29+ firstResponse , err := session .handleUpdateSnapshot (context .Background (), & UpdateSnapshotParams {
30+ OpenFiles : []DocumentIdentifier {{FileName : "/home/projects/p/src/index.ts" }},
31+ })
32+ assert .NilError (t , err )
33+ assert .Equal (t , firstResponse .Snapshot , SnapshotID (1 ))
34+ assert .Equal (t , len (firstResponse .Projects ), 1 )
35+
36+ response , err := session .handleUpdateSnapshot (context .Background (), & UpdateSnapshotParams {
37+ OpenProjects : []DocumentIdentifier {{FileName : configFileName }},
38+ })
39+ assert .NilError (t , err )
40+ assert .Equal (t , response .Snapshot , SnapshotID (2 ))
41+
42+ programResponse , err := session .handleCreateProgram (context .Background (), & CreateProgramParams {
43+ RootFiles : []DocumentIdentifier {{FileName : "/home/projects/p/src/index.ts" }},
44+ CreateProgramOptions : CreateProgramOptions {
45+ CompilerOptions : core.CompilerOptions {NoLib : core .TSTrue },
46+ },
47+ })
48+ assert .NilError (t , err )
49+ assert .Assert (t , programResponse .Project != nil )
50+ assert .Equal (t , programResponse .Snapshot , SnapshotID (4 ))
51+ }
52+
1453// TestSessionTracksAndReleasesAPIRefs verifies that an API session holds at most
1554// one ref per opened project/file (opens are idempotent) and releases exactly
1655// those refs when the session is closed, so it never leaks or over-releases refs
@@ -30,7 +69,8 @@ func TestSessionTracksAndReleasesAPIRefs(t *testing.T) {
3069 }
3170 projectSession , _ := projecttestutil .Setup (files )
3271 defer projectSession .Close ()
33- session := NewSession (projectSession , nil )
72+ session := NewLSPSession (projectSession , nil )
73+ assert .Assert (t , session .compatibilitySnapshot == nil )
3474
3575 _ , err := session .handleUpdateSnapshot (context .Background (), & UpdateSnapshotParams {
3676 OpenProjects : []DocumentIdentifier {{FileName : configFileName }},
@@ -63,7 +103,7 @@ func TestSessionTracksAndReleasesAPIRefs(t *testing.T) {
63103 }
64104 projectSession , _ := projecttestutil .Setup (files )
65105 defer projectSession .Close ()
66- session := NewSession (projectSession , nil )
106+ session := NewLSPSession (projectSession , nil )
67107 defer session .Close ()
68108
69109 _ , err := session .handleUpdateSnapshot (context .Background (), & UpdateSnapshotParams {
@@ -98,7 +138,7 @@ func TestSessionTracksAndReleasesAPIRefs(t *testing.T) {
98138 }
99139 projectSession , _ := projecttestutil .Setup (files )
100140 defer projectSession .Close ()
101- session := NewSession (projectSession , nil )
141+ session := NewLSPSession (projectSession , nil )
102142
103143 _ , err := session .handleUpdateSnapshot (context .Background (), & UpdateSnapshotParams {
104144 OpenFiles : []DocumentIdentifier {{FileName : fileName }},
@@ -151,7 +191,7 @@ func TestSessionTracksAndReleasesAPIRefs(t *testing.T) {
151191 }
152192 projectSession , _ := projecttestutil .Setup (files )
153193 defer projectSession .Close ()
154- session := NewSession (projectSession , nil )
194+ session := NewLSPSession (projectSession , nil )
155195 defer session .Close ()
156196
157197 // Open via a relative path; it should be tracked under the absolute path
@@ -230,7 +270,7 @@ func TestUpdateSnapshotResponseSkipsUnloadedAncestorProject(t *testing.T) {
230270 assert .Assert (t , ancestorProject != nil )
231271 assert .Assert (t , ancestorProject .CommandLine == nil )
232272
233- session := NewSession (projectSession , nil )
273+ session := NewLSPSession (projectSession , nil )
234274 defer session .Close ()
235275
236276 response , err := session .handleUpdateSnapshot (context .Background (), & UpdateSnapshotParams {
0 commit comments