Skip to content

Commit 3fb3eac

Browse files
committed
Update integration tests to use rust-analyzer
1 parent 075184a commit 3fb3eac

File tree

8 files changed

+82
-76
lines changed

8 files changed

+82
-76
lines changed

ci/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ RUN npm install -g [email protected]
1212
RUN rustup component add rustfmt rls rust-analysis rust-src \
1313
&& rustc --version \
1414
&& rls --version
15+
RUN curl -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-linux -o /usr/local/bin/rust-analyzer \
16+
&& chmod +x /usr/local/bin/rust-analyzer
1517

1618
ENV CARGO_TARGET_DIR=/tmp
1719

rplugin/python3/denite/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
sys.path.insert(0, dirname(__file__))
1010

11-
from lsp.protocol import SymbolKind # isort:skip # noqa: I100
11+
from lsp.protocol import SymbolKind # isort:skip # noqa: I100 E402
1212

1313

1414
MAX_FNAME_LEN = 30

rplugin/python3/denite/source/documentSymbol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
sys.path.insert(0, dirname(dirname(__file__)))
88

9-
from common import ( # isort:skip # noqa: I100
9+
from common import ( # isort:skip # noqa: I100 E402
1010
convert_symbols_to_candidates,
1111
SYMBOL_CANDIDATE_HIGHLIGHT_SYNTAX,
1212
highlight_setup,

rplugin/python3/denite/source/workspaceSymbol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
sys.path.insert(0, path.dirname(path.dirname(__file__)))
77

8-
from common import ( # isort:skip # noqa: I100
8+
from common import ( # isort:skip # noqa: I100 E402
99
convert_symbols_to_candidates,
1010
SYMBOL_CANDIDATE_HIGHLIGHT_SYNTAX,
1111
highlight_setup,

shell.nix

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ let
55
in
66
pkgs.mkShell {
77
buildInputs = (with pkgs; [
8+
curl
9+
git
810
mypy
11+
neovim
12+
# rustup # error on Linux: /lib64/libc.so.6: version `GLIBC_2.14' not found
13+
rust-analyzer
14+
tmux
15+
vim-vint
916
(with python37Packages; [
1017
flake8
1118
pynvim
1219
pytest
1320
])
14-
rustup
15-
vim-vint
1621
])
1722
++ stdenv.lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
1823
CoreServices

tests/LanguageClient_test.py

+67-68
Original file line numberDiff line numberDiff line change
@@ -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")
2424
PATH_CODEACTION = join_path("data/sample-ts/src/codeAction.ts")
25-
print(PATH_INDEXJS)
25+
print(PATH_MAIN_RS)
2626

2727

2828
def 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")
4246
def 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

7679
def 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

8992
def 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

103107
def 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

118122
def 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

132136
def 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

146150
def 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

163166
def 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

177180
def 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

185190
def 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

213220
def _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

251256
def 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

tests/data/vimrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let g:LanguageClient_serverStderr = expand('~/.local/share/nvim/LanguageServer.l
2424
let g:LanguageClient_serverCommands = {
2525
\ 'javascript': ['javascript-typescript-stdio'],
2626
\ 'typescript': ['javascript-typescript-stdio'],
27-
\ 'rust': ['rustup', 'run', 'stable', 'rls'],
27+
\ 'rust': ['rust-analyzer'],
2828
\ }
2929
let g:LanguageClient_selectionUI = 'location-list'
3030
set formatexpr=LanguageClient#textDocument_rangeFormatting_sync()

tests/test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ rm -f /tmp/nvim-LanguageClient-IntegrationTest
1515
if [[ "$TMUX" ]]; then
1616
tmux split-window 'NVIM_LISTEN_ADDRESS=/tmp/nvim-LanguageClient-IntegrationTest nvim -n -u tests/data/vimrc'
1717
else
18-
NVIM_LISTEN_ADDRESS=/tmp/nvim-LanguageClient-IntegrationTest nvim -n -u tests/data/vimrc --headless &
18+
NVIM_LISTEN_ADDRESS=/tmp/nvim-LanguageClient-IntegrationTest nvim -n -u tests/data/vimrc --headless 2>/dev/null &
1919
fi
2020
PID=$!
2121
sleep 1s
2222

23-
py.test-3 --capture=no --exitfirst -v $@
23+
$(command -v pytest-3 || echo pytest) --capture=no --exitfirst -v $@
2424
ret=$?
2525

2626
if [[ $ret != 0 ]]; then

0 commit comments

Comments
 (0)