@@ -19,10 +19,10 @@ def join_path(path: str) -> str:
19
19
return os .path .join (project_root , path )
20
20
21
21
22
- PATH_INDEXJS = join_path ("data/sample-js /src/index.js " )
23
- PATH_LIBSJS = join_path ("data/sample-js /src/libs.js " )
22
+ PATH_MAIN_RS = join_path ("data/sample-rs /src/main.rs " )
23
+ PATH_LIBS_RS = join_path ("data/sample-rs /src/libs.rs " )
24
24
PATH_CODEACTION = join_path ("data/sample-ts/src/codeAction.ts" )
25
- print (PATH_INDEXJS )
25
+ print (PATH_MAIN_RS )
26
26
27
27
28
28
def assertRetry (predicate , retry_max = 100 ):
@@ -38,72 +38,76 @@ def assertRetry(predicate, retry_max=100):
38
38
assert predicate ()
39
39
40
40
41
+ def getLanguageClientBuffers (nvim ):
42
+ return [b for b in nvim .buffers if b .name .endswith ("__LanguageClient__" )]
43
+
44
+
41
45
@pytest .fixture (scope = "module" )
42
46
def nvim () -> neovim .Nvim :
43
47
nvim = neovim .attach ("socket" , path = NVIM_LISTEN_ADDRESS )
44
48
time .sleep (1 )
45
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
46
- time .sleep (3 )
47
49
return nvim
48
50
49
51
50
- def test_fixture (nvim ):
51
- pass
52
+ @pytest .fixture (autouse = True )
53
+ def setup (nvim ):
54
+ nvim .command ("%bdelete!" )
52
55
53
56
54
- def test_textDocument_hover (nvim ):
55
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
56
- time .sleep (1 )
57
- nvim .funcs .cursor (13 , 19 )
58
- nvim .funcs .LanguageClient_textDocument_hover ()
59
- time .sleep (1 )
60
- b = next (b for b in nvim .buffers if b .name .endswith ('__LanguageClient__' ))
61
- expect = "function greet(): number"
57
+ def test_textDocument_definition (nvim ):
58
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
59
+ time .sleep (3 )
60
+ nvim .funcs .cursor (3 , 22 )
61
+ nvim .funcs .LanguageClient_textDocument_definition ()
62
+ time .sleep (3 )
62
63
63
- assert expect in b
64
+ assert nvim . current . window . cursor == [ 8 , 3 ]
64
65
65
66
66
- def test_textDocument_definition (nvim ):
67
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
67
+ def test_textDocument_hover (nvim ):
68
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
68
69
time .sleep (1 )
69
- nvim .funcs .cursor (13 , 19 )
70
- nvim .funcs .LanguageClient_textDocument_definition ()
70
+ nvim .funcs .cursor (3 , 22 )
71
+ nvim .funcs .LanguageClient_textDocument_hover ()
71
72
time .sleep (1 )
73
+ buf = getLanguageClientBuffers (nvim )[0 ]
74
+ expect = "fn greet() -> i32"
72
75
73
- assert nvim . current . window . cursor == [ 7 , 9 ]
76
+ assert expect in " \n " . join ( buf )
74
77
75
78
76
79
def test_textDocument_rename (nvim ):
77
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
80
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
78
81
time .sleep (1 )
79
82
expect = [line .replace ("greet" , "hello" ) for line in nvim .current .buffer ]
80
- nvim .funcs .cursor (13 , 19 )
83
+ nvim .funcs .cursor (3 , 22 )
81
84
nvim .funcs .LanguageClient_textDocument_rename ({"newName" : "hello" })
82
85
time .sleep (1 )
83
86
84
87
assert nvim .current .buffer [:] == expect
85
88
86
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
89
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
87
90
88
91
89
92
def test_textDocument_rename_multiple_oneline (nvim ):
90
- nvim .command ("edit! {}" .format (PATH_LIBSJS ))
93
+ nvim .command ("edit! {}" .format (PATH_LIBS_RS ))
91
94
time .sleep (1 )
92
- nvim .funcs .cursor (7 , 11 )
93
- expect = [line .replace ("a" , "abc" ) for line in nvim .current .buffer ]
94
- nvim .funcs .LanguageClient_textDocument_rename ({"newName" : "abc" })
95
+ expect = [line .replace ("a" , "x" ) for line in nvim .current .buffer ]
96
+ nvim .funcs .cursor (4 , 13 )
97
+ # TODO: Test case where new variable length is different.
98
+ nvim .funcs .LanguageClient_textDocument_rename ({"newName" : "x" })
95
99
time .sleep (1 )
96
100
97
101
assert nvim .current .buffer [:] == expect
98
102
99
103
nvim .command ("bd!" )
100
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
104
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
101
105
102
106
103
107
def test_textDocument_rename_multiple_files (nvim ):
104
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
108
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
105
109
time .sleep (1 )
106
- nvim .funcs .cursor (20 , 5 )
110
+ nvim .funcs .cursor (17 , 5 )
107
111
expect = [line .replace ("yo" , "hello" ) for line in nvim .current .buffer ]
108
112
nvim .funcs .LanguageClient_textDocument_rename ({"newName" : "hello" })
109
113
time .sleep (1 )
@@ -112,69 +116,70 @@ def test_textDocument_rename_multiple_files(nvim):
112
116
113
117
nvim .command ("bd!" )
114
118
nvim .command ("bd!" )
115
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
119
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
116
120
117
121
118
122
def test_textDocument_documentSymbol (nvim ):
119
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
123
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
120
124
time .sleep (1 )
121
125
nvim .funcs .cursor (1 , 1 )
122
126
nvim .funcs .LanguageClient_textDocument_documentSymbol ()
123
127
time .sleep (1 )
124
128
125
129
assert nvim .funcs .getloclist (0 )
126
130
127
- nvim .command ("4lnext " )
131
+ nvim .command ("3lnext " )
128
132
129
- assert nvim .current .window .cursor == [19 , 0 ]
133
+ assert nvim .current .window .cursor == [8 , 0 ]
130
134
131
135
132
136
def test_workspace_symbol (nvim ):
133
- nvim .command ("edit! {}" .format (PATH_LIBSJS ))
137
+ nvim .command ("edit! {}" .format (PATH_LIBS_RS ))
134
138
time .sleep (1 )
135
139
nvim .funcs .cursor (1 , 1 )
136
140
nvim .funcs .LanguageClient_workspace_symbol ()
137
141
time .sleep (1 )
138
142
139
143
assert nvim .funcs .getloclist (0 )
140
144
141
- nvim .command ("5lnext " )
145
+ nvim .command ("1lnext " )
142
146
143
- assert nvim .current .window .cursor == [7 , 0 ]
147
+ assert nvim .current .window .cursor == [8 , 0 ]
144
148
145
149
146
150
def test_textDocument_references (nvim ):
147
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
151
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
148
152
time .sleep (1 )
149
- nvim .funcs .cursor (7 , 12 )
153
+ nvim .funcs .cursor (8 , 6 )
150
154
nvim .funcs .LanguageClient_textDocument_references ()
151
155
time .sleep (1 )
152
- expect = ["function greet() {" ,
153
- """console.log(greet());""" ]
156
+ expect = ["fn greet() -> i32 {" , """println!("{}", greet());""" ]
154
157
155
- assert [location ["text" ] for location in
156
- nvim .funcs .getloclist (0 )] == expect
158
+ assert [location ["text" ]
159
+ for location in nvim .funcs .getloclist (0 )] == expect
157
160
158
161
nvim .command ("lnext" )
159
162
160
- assert nvim .current .window .cursor == [13 , 16 ]
163
+ assert nvim .current .window .cursor == [3 , 19 ]
161
164
162
165
163
166
def test_textDocument_references_modified_buffer (nvim ):
164
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
167
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
165
168
time .sleep (1 )
166
- nvim .funcs .cursor (7 , 10 )
169
+ nvim .funcs .cursor (8 , 6 )
167
170
nvim .input ("iabc" )
168
171
time .sleep (1 )
169
172
nvim .funcs .LanguageClient_textDocument_references ()
170
173
time .sleep (1 )
171
174
172
- assert nvim .current .window .cursor == [7 , 9 ]
175
+ assert nvim .current .window .cursor == [8 , 3 ]
173
176
174
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
177
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
175
178
176
179
177
180
def test_languageClient_registerServerCommands (nvim ):
181
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
182
+ time .sleep (1 )
178
183
nvim .command ('let g:responses = []' )
179
184
nvim .command ("call LanguageClient_registerServerCommands("
180
185
"{'bash': ['bash']}, g:responses)" )
@@ -183,6 +188,8 @@ def test_languageClient_registerServerCommands(nvim):
183
188
184
189
185
190
def test_languageClient_registerHandlers (nvim ):
191
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
192
+ time .sleep (1 )
186
193
nvim .command ('let g:responses = []' )
187
194
nvim .command ("call LanguageClient_registerHandlers("
188
195
"{'window/progress': 'HandleWindowProgress'}, g:responses)" )
@@ -211,7 +218,7 @@ def test_languageClient_registerHandlers(nvim):
211
218
212
219
213
220
def _open_float_window (nvim ):
214
- nvim .funcs .cursor (13 , 19 )
221
+ nvim .funcs .cursor (3 , 22 )
215
222
pos = nvim .funcs .getpos ('.' )
216
223
nvim .funcs .LanguageClient_textDocument_hover ()
217
224
time .sleep (1 )
@@ -222,15 +229,14 @@ def test_textDocument_hover_float_window_closed_on_cursor_moved(nvim):
222
229
if not nvim .funcs .exists ("*nvim_open_win" ):
223
230
pytest .skip ("Neovim 0.3.0 or earlier does not support floating window" )
224
231
225
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
232
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
226
233
time .sleep (1 )
227
234
228
235
buf = nvim .current .buffer
229
236
230
237
pos = _open_float_window (nvim )
231
238
232
- float_buf = next (
233
- b for b in nvim .buffers if b .name .endswith ("__LanguageClient__" ))
239
+ float_buf = getLanguageClientBuffers (nvim )[0 ]
234
240
235
241
# Check if float window is open
236
242
float_winnr = nvim .funcs .bufwinnr (float_buf .number )
@@ -244,15 +250,14 @@ def test_textDocument_hover_float_window_closed_on_cursor_moved(nvim):
244
250
nvim .funcs .cursor (13 , 17 )
245
251
246
252
# Check float window buffer was closed by CursorMoved
247
- assert all (
248
- b for b in nvim .buffers if not b .name .endswith ("__LanguageClient__" ))
253
+ assert len (getLanguageClientBuffers (nvim )) == 0
249
254
250
255
251
256
def test_textDocument_hover_float_window_closed_on_entering_window (nvim ):
252
257
if not nvim .funcs .exists ("*nvim_open_win" ):
253
258
pytest .skip ("Neovim 0.3.0 or earlier does not support floating window" )
254
259
255
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
260
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
256
261
time .sleep (1 )
257
262
258
263
win_id = nvim .funcs .win_getid ()
@@ -268,9 +273,7 @@ def test_textDocument_hover_float_window_closed_on_entering_window(nvim):
268
273
assert win_id == nvim .funcs .win_getid ()
269
274
270
275
# Check float window buffer was closed by BufEnter
271
- assert all (
272
- b for b in nvim .buffers
273
- if not b .name .endswith ("__LanguageClient__" ))
276
+ assert len (getLanguageClientBuffers (nvim )) == 0
274
277
finally :
275
278
nvim .command ("close!" )
276
279
@@ -285,15 +288,14 @@ def test_textDocument_hover_float_window_closed_on_switching_to_buffer(nvim):
285
288
another_bufnr = nvim .current .buffer .number
286
289
287
290
try :
288
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
291
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
289
292
time .sleep (1 )
290
293
291
294
source_bufnr = nvim .current .buffer .number
292
295
293
296
_open_float_window (nvim )
294
297
295
- float_buf = next (
296
- b for b in nvim .buffers if b .name .endswith ("__LanguageClient__" ))
298
+ float_buf = getLanguageClientBuffers (nvim )[0 ]
297
299
float_winnr = nvim .funcs .bufwinnr (float_buf .number )
298
300
assert float_winnr > 0
299
301
@@ -304,9 +306,7 @@ def test_textDocument_hover_float_window_closed_on_switching_to_buffer(nvim):
304
306
assert nvim .current .buffer .number == another_bufnr
305
307
306
308
# Check float window buffer was closed by BufEnter
307
- assert all (
308
- b for b in nvim .buffers
309
- if not b .name .endswith ("__LanguageClient__" ))
309
+ assert len (getLanguageClientBuffers (nvim )) == 0
310
310
finally :
311
311
nvim .command ("bdelete! {}" .format (another_bufnr ))
312
312
@@ -315,7 +315,7 @@ def test_textDocument_hover_float_window_move_cursor_into_window(nvim):
315
315
if not nvim .funcs .exists ("*nvim_open_win" ):
316
316
pytest .skip ("Neovim 0.3.0 or earlier does not support floating window" )
317
317
318
- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
318
+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
319
319
time .sleep (1 )
320
320
321
321
prev_bufnr = nvim .current .buffer .number
@@ -331,5 +331,4 @@ def test_textDocument_hover_float_window_move_cursor_into_window(nvim):
331
331
assert nvim .current .buffer .number == prev_bufnr
332
332
333
333
# Check float window buffer was closed by :close in the window
334
- assert all (
335
- b for b in nvim .buffers if not b .name .endswith ("__LanguageClient__" ))
334
+ assert len (getLanguageClientBuffers (nvim )) == 0
0 commit comments