Skip to content

Commit 70456d4

Browse files
authored
Fix tests and update toolchain to latest release (#1203)
1 parent 50c4bbd commit 70456d4

File tree

9 files changed

+97
-58
lines changed

9 files changed

+97
-58
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ jobs:
1818
ref: ${{ github.event.pull_request.head.sha }}
1919
fetch-depth: 20
2020

21+
- name: Install Go
22+
uses: actions/setup-go@v2
23+
with:
24+
go-version: 1.16.x
25+
2126
- name: Install Rust toolchain
2227
uses: actions-rs/toolchain@v1
2328
with:
@@ -29,12 +34,11 @@ jobs:
2934
- name: Install other dependencies
3035
run: |
3136
sudo apt-get update
32-
sudo apt-get install --yes --no-install-recommends neovim curl git python3-pip python3-pytest mypy flake8 libnode-dev node-gyp libssl1.0 npm make
37+
sudo apt-get install --yes --no-install-recommends neovim curl git python3-pip python3-pytest make
3338
sudo apt-get clean
3439
sudo rm -rf /var/lib/apt/lists/*
3540
python3 -m pip install neovim vim-vint
36-
sudo curl -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-linux -o /usr/local/bin/rust-analyzer
37-
sudo chmod +x /usr/local/bin/rust-analyzer
41+
go install golang.org/x/tools/gopls@v0.6.6
3842
3943
- name: Test
4044
run: make integration-test

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ integration-test: build
4747

4848
integration-test-docker:
4949
docker run --volume ${CURDIR}:/root/.config/nvim autozimu/languageclientneovim bash -c "\
50+
curl -O -L https://golang.org/dl/go1.16.2.linux-amd64.tar.gz && \
51+
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.2.linux-amd64.tar.gz && \
52+
export PATH=$$PATH:/usr/local/go/bin:/usr/local/cargo/bin && \
53+
export GOPATH=/usr/local/go && \
54+
go install golang.org/x/tools/gopls@v0.6.6 && \
5055
export CARGO_TARGET_DIR=/tmp && \
5156
cd /root/.config/nvim && \
5257
make integration-test"
@@ -58,7 +63,7 @@ clean:
5863
cargo clean
5964
rm -rf bin/languageclient
6065

61-
DATE := $(shell date --utc +%F)
66+
DATE := $(shell date -u +%F)
6267

6368
build-docker-image: ci/Dockerfile
6469
docker build \

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.46.0
1+
1.50.0

tests/LanguageClient_test.py

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ def join_path(path: str) -> str:
1919
return os.path.join(project_root, path)
2020

2121

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-
PATH_CODEACTION = join_path("data/sample-ts/src/codeAction.ts")
25-
print(PATH_MAIN_RS)
22+
PATH_MAIN_GO = join_path("data/sample-go/main.go")
23+
print(PATH_MAIN_GO)
2624

2725

2826
def assertRetry(predicate, retry_max=100):
@@ -55,130 +53,135 @@ def setup(nvim):
5553

5654

5755
def test_textDocument_definition(nvim):
58-
nvim.command("edit! {}".format(PATH_MAIN_RS))
59-
time.sleep(10)
60-
nvim.funcs.cursor(3, 22)
56+
nvim.command("edit! {}".format(PATH_MAIN_GO))
57+
time.sleep(2)
58+
nvim.funcs.cursor(10, 16)
6159
nvim.funcs.LanguageClient_textDocument_definition()
6260
time.sleep(3)
6361

64-
assert nvim.current.window.cursor == [8, 3]
62+
assert nvim.current.window.cursor == [13, 5]
6563

6664

6765
def test_textDocument_hover(nvim):
68-
nvim.command("edit! {}".format(PATH_MAIN_RS))
66+
nvim.command("edit! {}".format(PATH_MAIN_GO))
6967
time.sleep(1)
70-
nvim.funcs.cursor(3, 22)
68+
nvim.funcs.cursor(10, 16)
7169
nvim.funcs.LanguageClient_textDocument_hover()
7270
time.sleep(1)
7371
buf = getLanguageClientBuffers(nvim)[0]
74-
expect = "fn greet() -> i32"
72+
expect = "func greet() int32"
7573

7674
assert expect in "\n".join(buf)
7775

7876

7977
def test_textDocument_rename(nvim):
80-
nvim.command("edit! {}".format(PATH_MAIN_RS))
78+
nvim.command("edit! {}".format(PATH_MAIN_GO))
8179
time.sleep(1)
8280
expect = [line.replace("greet", "hello") for line in nvim.current.buffer]
83-
nvim.funcs.cursor(3, 22)
81+
nvim.funcs.cursor(10, 16)
8482
nvim.funcs.LanguageClient_textDocument_rename({"newName": "hello"})
8583
time.sleep(1)
8684

8785
assert nvim.current.buffer[:] == expect
8886

89-
nvim.command("edit! {}".format(PATH_MAIN_RS))
87+
nvim.command("edit! {}".format(PATH_MAIN_GO))
9088

9189

9290
def test_textDocument_rename_multiple_oneline(nvim):
93-
nvim.command("edit! {}".format(PATH_LIBS_RS))
91+
nvim.command("edit! {}".format(PATH_MAIN_GO))
9492
time.sleep(1)
95-
expect = [line.replace("a", "x") for line in nvim.current.buffer]
96-
nvim.funcs.cursor(2, 9)
93+
expect = [line.replace("someVar", "newVarName")
94+
for line in nvim.current.buffer]
95+
nvim.funcs.cursor(18, 2)
9796
# TODO: Test case where new variable length is different.
98-
nvim.funcs.LanguageClient_textDocument_rename({"newName": "x"})
99-
time.sleep(3)
97+
nvim.funcs.LanguageClient_textDocument_rename({"newName": "newVarName"})
98+
time.sleep(1)
10099

101100
assert nvim.current.buffer[:] == expect
102101

103102
nvim.command("bd!")
104-
nvim.command("edit! {}".format(PATH_MAIN_RS))
103+
nvim.command("edit! {}".format(PATH_MAIN_GO))
105104

106105

107106
def test_textDocument_rename_multiple_files(nvim):
108-
nvim.command("edit! {}".format(PATH_MAIN_RS))
107+
nvim.command("edit! {}".format(PATH_MAIN_GO))
109108
time.sleep(1)
110-
nvim.funcs.cursor(17, 5)
111-
expect = [line.replace("yo", "hello") for line in nvim.current.buffer]
109+
nvim.funcs.cursor(21, 15)
110+
expect = [line.replace("otherYo", "hello") for line in nvim.current.buffer]
112111
nvim.funcs.LanguageClient_textDocument_rename({"newName": "hello"})
113112
time.sleep(1)
114113

115114
assert nvim.current.buffer[:] == expect
116115

117116
nvim.command("bd!")
118117
nvim.command("bd!")
119-
nvim.command("edit! {}".format(PATH_MAIN_RS))
118+
nvim.command("edit! {}".format(PATH_MAIN_GO))
120119

121120

122121
def test_textDocument_documentSymbol(nvim):
123-
nvim.command("edit! {}".format(PATH_MAIN_RS))
122+
nvim.command("edit! {}".format(PATH_MAIN_GO))
124123
time.sleep(1)
125124
nvim.funcs.cursor(1, 1)
126125
nvim.funcs.LanguageClient_textDocument_documentSymbol()
127126
time.sleep(1)
128127

129128
assert nvim.funcs.getloclist(0)
130129

131-
nvim.command("3lnext")
130+
nvim.command("1lnext")
132131

133132
assert nvim.current.window.cursor != [1, 1]
134133

135134

136135
def test_workspace_symbol(nvim):
137-
nvim.command("edit! {}".format(PATH_LIBS_RS))
136+
nvim.command("edit! {}".format(PATH_MAIN_GO))
138137
time.sleep(1)
139138
nvim.funcs.cursor(1, 1)
140139
nvim.funcs.LanguageClient_workspace_symbol()
141140
time.sleep(1)
142141

143142
assert nvim.funcs.getloclist(0)
144143

145-
nvim.command("1lnext")
144+
nvim.command("3lnext")
146145

147-
assert nvim.current.window.cursor == [8, 0]
146+
assert nvim.current.window.cursor == [17, 0]
148147

149148

150149
def test_textDocument_references(nvim):
151-
nvim.command("edit! {}".format(PATH_MAIN_RS))
150+
nvim.command("edit! {}".format(PATH_MAIN_GO))
152151
time.sleep(1)
153-
nvim.funcs.cursor(8, 6)
152+
nvim.funcs.cursor(13, 6)
154153
nvim.funcs.LanguageClient_textDocument_references()
155-
time.sleep(1)
156-
expect = ["fn greet() -> i32 {", """println!("{}", greet());"""]
154+
time.sleep(2)
155+
expect = ["func greet() int32 {", "log.Println(greet())",
156+
"log.Println(greet())"]
157157

158158
assert [location["text"]
159159
for location in nvim.funcs.getloclist(0)] == expect
160160

161161
nvim.command("lnext")
162162

163-
assert nvim.current.window.cursor == [3, 19]
163+
assert nvim.current.window.cursor == [10, 13]
164164

165165

166166
def test_textDocument_references_modified_buffer(nvim):
167-
nvim.command("edit! {}".format(PATH_MAIN_RS))
167+
nvim.command("edit! {}".format(PATH_MAIN_GO))
168168
time.sleep(1)
169-
nvim.funcs.cursor(8, 6)
169+
nvim.funcs.cursor(13, 6)
170170
nvim.input("iabc")
171171
time.sleep(1)
172172
nvim.funcs.LanguageClient_textDocument_references()
173173
time.sleep(1)
174174

175-
assert nvim.current.window.cursor == [8, 3]
175+
nvim.command("lnext")
176+
177+
# first call to greet in sample-go/other.go
178+
assert nvim.current.window.cursor == [6, 13]
176179

177-
nvim.command("edit! {}".format(PATH_MAIN_RS))
180+
nvim.command("edit! {}".format(PATH_MAIN_GO))
178181

179182

180183
def test_languageClient_registerServerCommands(nvim):
181-
nvim.command("edit! {}".format(PATH_MAIN_RS))
184+
nvim.command("edit! {}".format(PATH_MAIN_GO))
182185
time.sleep(1)
183186
nvim.command('let g:responses = []')
184187
nvim.command("call LanguageClient_registerServerCommands("
@@ -188,7 +191,7 @@ def test_languageClient_registerServerCommands(nvim):
188191

189192

190193
def test_languageClient_registerHandlers(nvim):
191-
nvim.command("edit! {}".format(PATH_MAIN_RS))
194+
nvim.command("edit! {}".format(PATH_MAIN_GO))
192195
time.sleep(1)
193196
nvim.command('let g:responses = []')
194197
nvim.command("call LanguageClient_registerHandlers("
@@ -218,7 +221,7 @@ def test_languageClient_registerHandlers(nvim):
218221

219222

220223
def _open_float_window(nvim):
221-
nvim.funcs.cursor(3, 22)
224+
nvim.funcs.cursor(10, 15)
222225
pos = nvim.funcs.getpos('.')
223226
nvim.funcs.LanguageClient_textDocument_hover()
224227
time.sleep(1)
@@ -229,7 +232,7 @@ def test_textDocument_hover_float_window_closed_on_cursor_moved(nvim):
229232
if not nvim.funcs.exists("*nvim_open_win"):
230233
pytest.skip("Neovim 0.3.0 or earlier does not support floating window")
231234

232-
nvim.command("edit! {}".format(PATH_MAIN_RS))
235+
nvim.command("edit! {}".format(PATH_MAIN_GO))
233236
time.sleep(1)
234237

235238
buf = nvim.current.buffer
@@ -247,7 +250,7 @@ def test_textDocument_hover_float_window_closed_on_cursor_moved(nvim):
247250
assert pos == nvim.funcs.getpos(".")
248251

249252
# Move cursor to left
250-
nvim.funcs.cursor(13, 17)
253+
nvim.funcs.cursor(10, 14)
251254

252255
# Check float window buffer was closed by CursorMoved
253256
assert len(getLanguageClientBuffers(nvim)) == 0
@@ -257,7 +260,7 @@ def test_textDocument_hover_float_window_closed_on_entering_window(nvim):
257260
if not nvim.funcs.exists("*nvim_open_win"):
258261
pytest.skip("Neovim 0.3.0 or earlier does not support floating window")
259262

260-
nvim.command("edit! {}".format(PATH_MAIN_RS))
263+
nvim.command("edit! {}".format(PATH_MAIN_GO))
261264
time.sleep(1)
262265

263266
win_id = nvim.funcs.win_getid()
@@ -288,7 +291,7 @@ def test_textDocument_hover_float_window_closed_on_switching_to_buffer(nvim):
288291
another_bufnr = nvim.current.buffer.number
289292

290293
try:
291-
nvim.command("edit! {}".format(PATH_MAIN_RS))
294+
nvim.command("edit! {}".format(PATH_MAIN_GO))
292295
time.sleep(1)
293296

294297
source_bufnr = nvim.current.buffer.number
@@ -315,7 +318,7 @@ def test_textDocument_hover_float_window_move_cursor_into_window(nvim):
315318
if not nvim.funcs.exists("*nvim_open_win"):
316319
pytest.skip("Neovim 0.3.0 or earlier does not support floating window")
317320

318-
nvim.command("edit! {}".format(PATH_MAIN_RS))
321+
nvim.command("edit! {}".format(PATH_MAIN_GO))
319322
time.sleep(1)
320323

321324
prev_bufnr = nvim.current.buffer.number

tests/data/sample-go/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module sameple-go
2+
3+
go 1.15

tests/data/sample-go/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
)
7+
8+
func main() {
9+
fmt.Println("Hello, 世界")
10+
log.Println(greet())
11+
}
12+
13+
func greet() int32 {
14+
return 42
15+
}
16+
17+
func yo() {
18+
someVar := 3
19+
b := someVar + someVar
20+
log.Println(b)
21+
log.Println(otherYo())
22+
}

tests/data/sample-go/other.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package main
2+
3+
import "log"
4+
5+
func otherYo() string {
6+
log.Println(greet())
7+
return "yo"
8+
}

tests/data/sample-go/simple.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/data/vimrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let g:LanguageClient_serverCommands = {
2525
\ 'javascript': ['javascript-typescript-stdio'],
2626
\ 'typescript': ['javascript-typescript-stdio'],
2727
\ 'rust': ['rust-analyzer'],
28+
\ 'go': ['gopls'],
2829
\ }
2930
let g:LanguageClient_selectionUI = 'location-list'
3031
set formatexpr=LanguageClient#textDocument_rangeFormatting_sync()

0 commit comments

Comments
 (0)