1
- //go:build !windows
2
-
3
1
package workspace
4
2
5
3
import (
@@ -11,7 +9,6 @@ import (
11
9
)
12
10
13
11
func TestEditing (t * testing.T ) {
14
- t .Skip ("cuelsp disabled" )
15
12
const files = `
16
13
-- cue.mod/module.cue --
17
14
module: "mod.example/x"
@@ -41,75 +38,158 @@ v2: "hi"
41
38
v3: a.v1
42
39
`
43
40
44
- t .Run ("open" , func (t * testing.T ) {
41
+ t .Run ("open - one package only " , func (t * testing.T ) {
45
42
WithOptions (RootURIAsDefaultFolder ()).Run (t , files , func (t * testing.T , env * Env ) {
43
+ rootURI := env .Sandbox .Workdir .RootURI ()
44
+ env .Await (
45
+ LogExactf (protocol .Debug , 1 , false , "Workspace folder added: %v" , rootURI ),
46
+ )
46
47
env .OpenFile ("a/a.cue" )
47
48
env .Await (
48
- // There's a snapshot for a/a.cue (because it was opened):
49
- LogMatching (protocol .Debug , `/a/a\.cue":{"file://` , 1 , false ),
50
- // a/a.cue belongs to two packages:
51
- LogMatching (protocol .Debug , `/a/a\.cue":\["mod\.example/x/a","mod\.example/x/a@v0:a"\]` , 1 , false ),
52
- // a/d/d.cue belongs to one package:
53
- LogMatching (protocol .Debug , `/a/d/d\.cue":\["mod\.example/x/a/d@v0:e"\]` , 1 , false ),
54
- // b/b.cue is used in two packages because of ancestor imports:
55
- LogMatching (protocol .Debug , `/b/b\.cue":\["mod\.example/x/b/c@v0:b","mod\.example/x/b@v0:b"\]` , 1 , false ),
56
- // b/c/c.cue only exists in one package:
57
- LogMatching (protocol .Debug , `/b/c/c.cue":\["mod\.example/x/b/c@v0:b"\]` , 1 , false ),
49
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=unknown Created" , rootURI ),
50
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Reloaded" , rootURI ),
51
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/a/a.cue found [Package dir=%v/a importPath=mod.example/x/a@v0]" , rootURI , rootURI , rootURI ),
52
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/a@v0]" , rootURI ),
53
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/a importPath=mod.example/x/a@v0" , rootURI , rootURI ),
58
54
)
59
55
})
60
56
})
61
57
62
- t .Run ("edit - split ancestor imports " , func (t * testing.T ) {
58
+ t .Run ("open - one package only - ancestor " , func (t * testing.T ) {
63
59
WithOptions (RootURIAsDefaultFolder ()).Run (t , files , func (t * testing.T , env * Env ) {
64
- env .OpenFile ( "b/b.cue" )
60
+ rootURI := env .Sandbox . Workdir . RootURI ( )
65
61
env .Await (
66
- // There's a snapshot for b/b.cue (because it was opened):
67
- LogMatching (protocol .Debug , `/b/b\.cue":{"file://` , 1 , false ),
68
- // b/b.cue is used in two packages because of ancestor imports:
69
- LogMatching (protocol .Debug , `/b/b\.cue":\["mod\.example/x/b/c@v0:b","mod\.example/x/b@v0:b"\]` , 1 , false ),
70
- // b/c/c.cue only exists in one package:
71
- LogMatching (protocol .Debug , `/b/c/c.cue":\["mod\.example/x/b/c@v0:b"\]` , 1 , false ),
62
+ LogExactf (protocol .Debug , 1 , false , "Workspace folder added: %v" , rootURI ),
72
63
)
64
+ env .OpenFile ("b/c/c.cue" )
65
+ env .Await (
66
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=unknown Created" , rootURI ),
67
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Reloaded" , rootURI ),
68
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/b/c/c.cue found [Package dir=%v/b/c importPath=mod.example/x/b/c@v0:b]" , rootURI , rootURI , rootURI ),
69
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b/c@v0:b]" , rootURI ),
70
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/b/c importPath=mod.example/x/b/c@v0:b" , rootURI , rootURI ),
71
+ // We do not load the parent/same package
72
+ NoLogExactf (protocol .Debug , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b@v0]" , rootURI ),
73
+ )
74
+ // Although we have not loaded the mod.example/x/b@v0
75
+ // package, the b/b.cue file will have been loaded and will
76
+ // be being modelled. We can prove this by changing this file
77
+ // (without opening it) and observing the x/b/c:b package
78
+ // gets reloaded.
79
+ //
80
+ // WriteWorkspaceFile issues a file-watch notification to the
81
+ // server. This tells the server the file has changed on
82
+ // disk, but has not been opened in the editor.
83
+ env .WriteWorkspaceFile ("b/b.cue" , "package b\n \n v2: int\n " )
84
+ env .Await (
85
+ LogExactf (protocol .Debug , 2 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b/c@v0:b]" , rootURI ),
86
+ LogExactf (protocol .Debug , 2 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/b/c importPath=mod.example/x/b/c@v0:b" , rootURI , rootURI ),
87
+ // We still do not load the parent/same package
88
+ NoLogExactf (protocol .Debug , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b@v0]" , rootURI ),
89
+ )
90
+ })
91
+ })
73
92
74
- // change b/b.cue (which is an ancestor import of b/c/c.cue)
75
- // package from "b" to "bz" (thus impacting the build files
76
- // of b/c/c.cue)
77
- env .EditBuffer ("b/b.cue" , fake .NewEdit (0 , 9 , 0 , 9 , "z" ))
93
+ t .Run ("open - import chain" , func (t * testing.T ) {
94
+ WithOptions (RootURIAsDefaultFolder ()).Run (t , files , func (t * testing.T , env * Env ) {
95
+ rootURI := env .Sandbox .Workdir .RootURI ()
96
+ env .Await (
97
+ LogExactf (protocol .Debug , 1 , false , "Workspace folder added: %v" , rootURI ),
98
+ )
99
+ env .OpenFile ("b/c/c.cue" )
100
+ env .Await (
101
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=unknown Created" , rootURI ),
102
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Reloaded" , rootURI ),
103
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/b/c/c.cue found [Package dir=%v/b/c importPath=mod.example/x/b/c@v0:b]" , rootURI , rootURI , rootURI ),
104
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b/c@v0:b]" , rootURI ),
105
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/b/c importPath=mod.example/x/b/c@v0:b" , rootURI , rootURI ),
106
+ // b/c/c.cue imports mod.example/x/a. So we should see a
107
+ // load for x/a as a side-effect of loading pkg x/b/c:b
108
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/a importPath=mod.example/x/a@v0" , rootURI , rootURI ),
109
+ )
110
+ // Even with a.cue not open in the editor, if we rewrite
111
+ // a.cue, we should see a reload of x/a and x/b/c:b
112
+ env .WriteWorkspaceFile ("a/a.cue" , "package a\n \n v1: string\n " )
113
+ env .Await (
114
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/a@v0 mod.example/x/b/c@v0:b]" , rootURI ),
115
+ LogExactf (protocol .Debug , 2 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/a importPath=mod.example/x/a@v0" , rootURI , rootURI ),
116
+ LogExactf (protocol .Debug , 2 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/b/c importPath=mod.example/x/b/c@v0:b" , rootURI , rootURI ),
117
+ )
118
+ })
119
+ })
78
120
121
+ t .Run ("edit - change package" , func (t * testing.T ) {
122
+ WithOptions (RootURIAsDefaultFolder ()).Run (t , files , func (t * testing.T , env * Env ) {
123
+ rootURI := env .Sandbox .Workdir .RootURI ()
124
+ env .OpenFile ("b/b.cue" )
125
+ env .Await (
126
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/b/b.cue found [Package dir=%v/b importPath=mod.example/x/b@v0]" , rootURI , rootURI , rootURI ),
127
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b@v0]" , rootURI ),
128
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/b importPath=mod.example/x/b@v0" , rootURI , rootURI ),
129
+ // We do not load the child/same package
130
+ NoLogExactf (protocol .Debug , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b/c@v0:b]" , rootURI ),
131
+ )
132
+ // Now open the child/same package
133
+ env .OpenFile ("b/c/c.cue" )
134
+ env .Await (
135
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/b/c/c.cue found [Package dir=%v/b/c importPath=mod.example/x/b/c@v0:b]" , rootURI , rootURI , rootURI ),
136
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b/c@v0:b]" , rootURI ),
137
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/b/c importPath=mod.example/x/b/c@v0:b" , rootURI , rootURI ),
138
+ )
139
+ // Change b/b.cue (which is an ancestor import of b/c/c.cue)
140
+ // package from "b" to "bz"
141
+ env .EditBuffer ("b/b.cue" , fake .NewEdit (0 , 9 , 0 , 9 , "z" ))
142
+ env .Await (
143
+ // We should see a single reload of both existing packages:
144
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b/c@v0:b mod.example/x/b@v0]" , rootURI ),
145
+ // The load of mod.example/x/b@v0 will have failed, so we should see a new pkg search for b.cue:
146
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/b/b.cue found [Package dir=%v/b importPath=mod.example/x/b@v0:bz]" , rootURI , rootURI , rootURI ),
147
+ // And we should now see that the mod.example/x/b@v0:bz package gets loaded successfully
148
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b@v0:bz]" , rootURI ),
149
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/b importPath=mod.example/x/b@v0:bz" , rootURI , rootURI ),
150
+ )
151
+ // A further edit of b/b.cue should now cause package x/b:bz to be reloaded, but x/b/c:b does not get reloaded:
152
+ env .EditBuffer ("b/b.cue" , fake .NewEdit (2 , 0 , 2 , 0 , "w" ))
79
153
env .Await (
80
- // There's still a snapshot for b/b.cue:
81
- LogMatching (protocol .Debug , `/b/b\.cue":{"file://` , 2 , false ),
82
- // b.cue is now only in the package bz
83
- LogMatching (protocol .Debug , `/b/b\.cue":\["mod\.example/x/b@v0:bz"\]` , 1 , false ),
84
- // b/c/c.cue only exists in one package:
85
- LogMatching (protocol .Debug , `/b/c/c.cue":\["mod\.example/x/b/c@v0:b"\]` , 2 , false ),
154
+ // Now 2 loads of x/b:bz
155
+ LogExactf (protocol .Debug , 2 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b@v0:bz]" , rootURI ),
156
+ LogExactf (protocol .Debug , 2 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/b importPath=mod.example/x/b@v0:bz" , rootURI , rootURI ),
157
+ // Still exactly 1 explicit load of x/b/c:b
158
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/b/c@v0:b]" , rootURI ),
86
159
)
87
160
})
88
161
})
89
162
90
163
t .Run ("edit - create ancestor imports" , func (t * testing.T ) {
91
164
WithOptions (RootURIAsDefaultFolder ()).Run (t , files , func (t * testing.T , env * Env ) {
165
+ rootURI := env .Sandbox .Workdir .RootURI ()
92
166
env .OpenFile ("a/a.cue" )
93
167
env .Await (
94
- // There's a snapshot for a/a.cue (because it was opened):
95
- LogMatching (protocol .Debug , `/a/a\.cue":{"file://` , 1 , false ),
96
- // a/a.cue belongs to two packages:
97
- LogMatching (protocol .Debug , `/a/a\.cue":\["mod\.example/x/a","mod\.example/x/a@v0:a"\]` , 1 , false ),
98
- // a/d/d.cue belongs to one package:
99
- LogMatching (protocol .Debug , `/a/d/d\.cue":\["mod\.example/x/a/d@v0:e"\]` , 1 , false ),
168
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/a/a.cue found [Package dir=%v/a importPath=mod.example/x/a@v0]" , rootURI , rootURI , rootURI ),
169
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/a@v0]" , rootURI ),
170
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/a importPath=mod.example/x/a@v0" , rootURI , rootURI ),
171
+ )
172
+ env .OpenFile ("a/d/d.cue" )
173
+ env .Await (
174
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/a/d/d.cue found [Package dir=%v/a/d importPath=mod.example/x/a/d@v0:e]" , rootURI , rootURI , rootURI ),
175
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/a/d@v0:e]" , rootURI ),
176
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/a/d importPath=mod.example/x/a/d@v0:e" , rootURI , rootURI ),
100
177
)
101
-
102
178
// change a/a.cue package from "a" to "e". This makes it
103
179
// become the same package as a/d/d.cue
104
180
env .EditBuffer ("a/a.cue" , fake .NewEdit (0 , 8 , 0 , 9 , "e" ))
105
-
106
181
env .Await (
107
- // There's still a snapshot for a/a.cue:
108
- LogMatching (protocol .Debug , `/a/a\.cue":{"file://` , 2 , false ),
109
- // a/a.cue has moved into the e package, both in the x/a/d/ path, and the x/a/ path:
110
- LogMatching (protocol .Debug , `/a/a\.cue":\["mod\.example/x/a/d@v0:e","mod\.example/x/a@v0:e"\]` , 1 , false ),
111
- // a/d/d.cue still belongs to one package:
112
- LogMatching (protocol .Debug , `/a/d/d\.cue":\["mod\.example/x/a/d@v0:e"\]` , 2 , false ),
182
+ // We should first see a reload of x/a, which will fail.
183
+ LogExactf (protocol .Debug , 2 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/a@v0]" , rootURI ),
184
+ // There'll then be a new search and it should find both packages.
185
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 For file %v/a/a.cue found [" +
186
+ "Package dir=%v/a importPath=mod.example/x/a@v0:e " +
187
+ "Package dir=%v/a/d importPath=mod.example/x/a/d@v0:e]" ,
188
+ rootURI , rootURI , rootURI , rootURI ),
189
+ // And both packages should get reloaded in one go:
190
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loading packages [mod.example/x/a/d@v0:e mod.example/x/a@v0:e]" , rootURI ),
191
+ LogExactf (protocol .Debug , 2 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/a/d importPath=mod.example/x/a/d@v0:e" , rootURI , rootURI ),
192
+ LogExactf (protocol .Debug , 1 , false , "Module dir=%v module=mod.example/x@v0 Loaded Package dir=%v/a importPath=mod.example/x/a@v0:e" , rootURI , rootURI ),
113
193
)
114
194
})
115
195
})
0 commit comments