@@ -19,10 +19,10 @@ def join_path(path: str) -> str:
1919 return os .path .join (project_root , path )
2020
2121
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 " )
2424PATH_CODEACTION = join_path ("data/sample-ts/src/codeAction.ts" )
25- print (PATH_INDEXJS )
25+ print (PATH_MAIN_RS )
2626
2727
2828def assertRetry (predicate , retry_max = 100 ):
@@ -38,72 +38,76 @@ def assertRetry(predicate, retry_max=100):
3838 assert predicate ()
3939
4040
41+ def getLanguageClientBuffers (nvim ):
42+ return [b for b in nvim .buffers if b .name .endswith ("__LanguageClient__" )]
43+
44+
4145@pytest .fixture (scope = "module" )
4246def nvim () -> neovim .Nvim :
4347 nvim = neovim .attach ("socket" , path = NVIM_LISTEN_ADDRESS )
4448 time .sleep (1 )
45- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
46- time .sleep (3 )
4749 return nvim
4850
4951
50- def test_fixture (nvim ):
51- pass
52+ @pytest .fixture (autouse = True )
53+ def setup (nvim ):
54+ nvim .command ("%bdelete!" )
5255
5356
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 )
6263
63- assert expect in b
64+ assert nvim . current . window . cursor == [ 8 , 3 ]
6465
6566
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 ))
6869 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 ()
7172 time .sleep (1 )
73+ buf = getLanguageClientBuffers (nvim )[0 ]
74+ expect = "fn greet() -> i32"
7275
73- assert nvim . current . window . cursor == [ 7 , 9 ]
76+ assert expect in " \n " . join ( buf )
7477
7578
7679def test_textDocument_rename (nvim ):
77- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
80+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
7881 time .sleep (1 )
7982 expect = [line .replace ("greet" , "hello" ) for line in nvim .current .buffer ]
80- nvim .funcs .cursor (13 , 19 )
83+ nvim .funcs .cursor (3 , 22 )
8184 nvim .funcs .LanguageClient_textDocument_rename ({"newName" : "hello" })
8285 time .sleep (1 )
8386
8487 assert nvim .current .buffer [:] == expect
8588
86- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
89+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
8790
8891
8992def test_textDocument_rename_multiple_oneline (nvim ):
90- nvim .command ("edit! {}" .format (PATH_LIBSJS ))
93+ nvim .command ("edit! {}" .format (PATH_LIBS_RS ))
9194 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" })
9599 time .sleep (1 )
96100
97101 assert nvim .current .buffer [:] == expect
98102
99103 nvim .command ("bd!" )
100- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
104+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
101105
102106
103107def test_textDocument_rename_multiple_files (nvim ):
104- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
108+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
105109 time .sleep (1 )
106- nvim .funcs .cursor (20 , 5 )
110+ nvim .funcs .cursor (17 , 5 )
107111 expect = [line .replace ("yo" , "hello" ) for line in nvim .current .buffer ]
108112 nvim .funcs .LanguageClient_textDocument_rename ({"newName" : "hello" })
109113 time .sleep (1 )
@@ -112,69 +116,70 @@ def test_textDocument_rename_multiple_files(nvim):
112116
113117 nvim .command ("bd!" )
114118 nvim .command ("bd!" )
115- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
119+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
116120
117121
118122def test_textDocument_documentSymbol (nvim ):
119- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
123+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
120124 time .sleep (1 )
121125 nvim .funcs .cursor (1 , 1 )
122126 nvim .funcs .LanguageClient_textDocument_documentSymbol ()
123127 time .sleep (1 )
124128
125129 assert nvim .funcs .getloclist (0 )
126130
127- nvim .command ("4lnext " )
131+ nvim .command ("3lnext " )
128132
129- assert nvim .current .window .cursor == [19 , 0 ]
133+ assert nvim .current .window .cursor == [8 , 0 ]
130134
131135
132136def test_workspace_symbol (nvim ):
133- nvim .command ("edit! {}" .format (PATH_LIBSJS ))
137+ nvim .command ("edit! {}" .format (PATH_LIBS_RS ))
134138 time .sleep (1 )
135139 nvim .funcs .cursor (1 , 1 )
136140 nvim .funcs .LanguageClient_workspace_symbol ()
137141 time .sleep (1 )
138142
139143 assert nvim .funcs .getloclist (0 )
140144
141- nvim .command ("5lnext " )
145+ nvim .command ("1lnext " )
142146
143- assert nvim .current .window .cursor == [7 , 0 ]
147+ assert nvim .current .window .cursor == [8 , 0 ]
144148
145149
146150def test_textDocument_references (nvim ):
147- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
151+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
148152 time .sleep (1 )
149- nvim .funcs .cursor (7 , 12 )
153+ nvim .funcs .cursor (8 , 6 )
150154 nvim .funcs .LanguageClient_textDocument_references ()
151155 time .sleep (1 )
152- expect = ["function greet() {" ,
153- """console.log(greet());""" ]
156+ expect = ["fn greet() -> i32 {" , """println!("{}", greet());""" ]
154157
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
157160
158161 nvim .command ("lnext" )
159162
160- assert nvim .current .window .cursor == [13 , 16 ]
163+ assert nvim .current .window .cursor == [3 , 19 ]
161164
162165
163166def test_textDocument_references_modified_buffer (nvim ):
164- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
167+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
165168 time .sleep (1 )
166- nvim .funcs .cursor (7 , 10 )
169+ nvim .funcs .cursor (8 , 6 )
167170 nvim .input ("iabc" )
168171 time .sleep (1 )
169172 nvim .funcs .LanguageClient_textDocument_references ()
170173 time .sleep (1 )
171174
172- assert nvim .current .window .cursor == [7 , 9 ]
175+ assert nvim .current .window .cursor == [8 , 3 ]
173176
174- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
177+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
175178
176179
177180def test_languageClient_registerServerCommands (nvim ):
181+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
182+ time .sleep (1 )
178183 nvim .command ('let g:responses = []' )
179184 nvim .command ("call LanguageClient_registerServerCommands("
180185 "{'bash': ['bash']}, g:responses)" )
@@ -183,6 +188,8 @@ def test_languageClient_registerServerCommands(nvim):
183188
184189
185190def test_languageClient_registerHandlers (nvim ):
191+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
192+ time .sleep (1 )
186193 nvim .command ('let g:responses = []' )
187194 nvim .command ("call LanguageClient_registerHandlers("
188195 "{'window/progress': 'HandleWindowProgress'}, g:responses)" )
@@ -211,7 +218,7 @@ def test_languageClient_registerHandlers(nvim):
211218
212219
213220def _open_float_window (nvim ):
214- nvim .funcs .cursor (13 , 19 )
221+ nvim .funcs .cursor (3 , 22 )
215222 pos = nvim .funcs .getpos ('.' )
216223 nvim .funcs .LanguageClient_textDocument_hover ()
217224 time .sleep (1 )
@@ -222,15 +229,14 @@ def test_textDocument_hover_float_window_closed_on_cursor_moved(nvim):
222229 if not nvim .funcs .exists ("*nvim_open_win" ):
223230 pytest .skip ("Neovim 0.3.0 or earlier does not support floating window" )
224231
225- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
232+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
226233 time .sleep (1 )
227234
228235 buf = nvim .current .buffer
229236
230237 pos = _open_float_window (nvim )
231238
232- float_buf = next (
233- b for b in nvim .buffers if b .name .endswith ("__LanguageClient__" ))
239+ float_buf = getLanguageClientBuffers (nvim )[0 ]
234240
235241 # Check if float window is open
236242 float_winnr = nvim .funcs .bufwinnr (float_buf .number )
@@ -244,15 +250,14 @@ def test_textDocument_hover_float_window_closed_on_cursor_moved(nvim):
244250 nvim .funcs .cursor (13 , 17 )
245251
246252 # 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
249254
250255
251256def test_textDocument_hover_float_window_closed_on_entering_window (nvim ):
252257 if not nvim .funcs .exists ("*nvim_open_win" ):
253258 pytest .skip ("Neovim 0.3.0 or earlier does not support floating window" )
254259
255- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
260+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
256261 time .sleep (1 )
257262
258263 win_id = nvim .funcs .win_getid ()
@@ -268,9 +273,7 @@ def test_textDocument_hover_float_window_closed_on_entering_window(nvim):
268273 assert win_id == nvim .funcs .win_getid ()
269274
270275 # 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
274277 finally :
275278 nvim .command ("close!" )
276279
@@ -285,15 +288,14 @@ def test_textDocument_hover_float_window_closed_on_switching_to_buffer(nvim):
285288 another_bufnr = nvim .current .buffer .number
286289
287290 try :
288- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
291+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
289292 time .sleep (1 )
290293
291294 source_bufnr = nvim .current .buffer .number
292295
293296 _open_float_window (nvim )
294297
295- float_buf = next (
296- b for b in nvim .buffers if b .name .endswith ("__LanguageClient__" ))
298+ float_buf = getLanguageClientBuffers (nvim )[0 ]
297299 float_winnr = nvim .funcs .bufwinnr (float_buf .number )
298300 assert float_winnr > 0
299301
@@ -304,9 +306,7 @@ def test_textDocument_hover_float_window_closed_on_switching_to_buffer(nvim):
304306 assert nvim .current .buffer .number == another_bufnr
305307
306308 # 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
310310 finally :
311311 nvim .command ("bdelete! {}" .format (another_bufnr ))
312312
@@ -315,7 +315,7 @@ def test_textDocument_hover_float_window_move_cursor_into_window(nvim):
315315 if not nvim .funcs .exists ("*nvim_open_win" ):
316316 pytest .skip ("Neovim 0.3.0 or earlier does not support floating window" )
317317
318- nvim .command ("edit! {}" .format (PATH_INDEXJS ))
318+ nvim .command ("edit! {}" .format (PATH_MAIN_RS ))
319319 time .sleep (1 )
320320
321321 prev_bufnr = nvim .current .buffer .number
@@ -331,5 +331,4 @@ def test_textDocument_hover_float_window_move_cursor_into_window(nvim):
331331 assert nvim .current .buffer .number == prev_bufnr
332332
333333 # 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