tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
rust-analyzer/test-neovim-lsp: format
Austin Horstman
1 year ago
fe713828
8991722d
+69
-56
1 changed file
expand all
collapse all
unified
split
pkgs
development
tools
rust
rust-analyzer
test-neovim-lsp.nix
+69
-56
pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix
···
1
1
-
{ runCommand, cargo, neovim, rust-analyzer, rustc }:
2
2
-
runCommand "test-neovim-rust-analyzer" {
3
3
-
nativeBuildInputs = [ cargo neovim rust-analyzer rustc ];
1
1
+
{
2
2
+
runCommand,
3
3
+
cargo,
4
4
+
neovim,
5
5
+
rust-analyzer,
6
6
+
rustc,
7
7
+
}:
8
8
+
runCommand "test-neovim-rust-analyzer"
9
9
+
{
10
10
+
nativeBuildInputs = [
11
11
+
cargo
12
12
+
neovim
13
13
+
rust-analyzer
14
14
+
rustc
15
15
+
];
4
16
5
5
-
testRustSrc = /* rust */ ''
6
6
-
fn main() {
7
7
-
let mut var = vec![None];
8
8
-
var.push(Some("hello".to_owned()));
9
9
-
}
10
10
-
'';
17
17
+
testRustSrc = ''
18
18
+
fn main() {
19
19
+
let mut var = vec![None];
20
20
+
var.push(Some("hello".to_owned()));
21
21
+
}
22
22
+
'';
11
23
12
12
-
# NB. Wait for server done type calculations before sending `hover` request,
13
13
-
# otherwise it would return `{unknown}`.
14
14
-
# Ref: https://github.com/rust-lang/rust-analyzer/blob/7b11fdeb681c12002861b9804a388efde81c9647/docs/dev/lsp-extensions.md#server-status
15
15
-
nvimConfig = /* lua */ ''
16
16
-
local caps = vim.lsp.protocol.make_client_capabilities()
17
17
-
caps["experimental"] = { serverStatusNotification = true }
18
18
-
vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({
19
19
-
cmd = { "rust-analyzer" },
20
20
-
capabilities = caps,
21
21
-
handlers = {
22
22
-
["experimental/serverStatus"] = function(_, msg, ctx)
23
23
-
if msg.health == "ok" then
24
24
-
if msg.quiescent then
25
25
-
vim.cmd("goto 23") -- let mut |var =...
26
26
-
vim.lsp.buf.hover()
24
24
+
# NB. Wait for server done type calculations before sending `hover` request,
25
25
+
# otherwise it would return `{unknown}`.
26
26
+
# Ref: https://github.com/rust-lang/rust-analyzer/blob/7b11fdeb681c12002861b9804a388efde81c9647/docs/dev/lsp-extensions.md#server-status
27
27
+
nvimConfig = ''
28
28
+
local caps = vim.lsp.protocol.make_client_capabilities()
29
29
+
caps["experimental"] = { serverStatusNotification = true }
30
30
+
vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({
31
31
+
cmd = { "rust-analyzer" },
32
32
+
capabilities = caps,
33
33
+
handlers = {
34
34
+
["experimental/serverStatus"] = function(_, msg, ctx)
35
35
+
if msg.health == "ok" then
36
36
+
if msg.quiescent then
37
37
+
vim.cmd("goto 23") -- let mut |var =...
38
38
+
vim.lsp.buf.hover()
39
39
+
end
40
40
+
else
41
41
+
print("error: server status is not ok: ")
42
42
+
vim.cmd("q")
43
43
+
end
44
44
+
end,
45
45
+
["textDocument/hover"] = function(_, msg, ctx)
46
46
+
if msg then
47
47
+
-- Keep newlines.
48
48
+
io.write(msg.contents.value)
49
49
+
vim.cmd("q")
27
50
end
28
28
-
else
29
29
-
print("error: server status is not ok: ")
30
30
-
vim.cmd("q")
31
31
-
end
32
32
-
end,
33
33
-
["textDocument/hover"] = function(_, msg, ctx)
34
34
-
if msg then
35
35
-
-- Keep newlines.
36
36
-
io.write(msg.contents.value)
37
37
-
vim.cmd("q")
38
38
-
end
39
39
-
end,
40
40
-
},
41
41
-
on_error = function(code)
42
42
-
print("error: " .. code)
43
43
-
vim.cmd("q")
44
44
-
end
45
45
-
}))
46
46
-
'';
51
51
+
end,
52
52
+
},
53
53
+
on_error = function(code)
54
54
+
print("error: " .. code)
55
55
+
vim.cmd("q")
56
56
+
end
57
57
+
}))
58
58
+
'';
47
59
48
48
-
} ''
49
49
-
# neovim requires a writable HOME.
50
50
-
export HOME="$(pwd)"
60
60
+
}
61
61
+
''
62
62
+
# neovim requires a writable HOME.
63
63
+
export HOME="$(pwd)"
51
64
52
52
-
cargo new --bin test-rust-analyzer
53
53
-
cd test-rust-analyzer
54
54
-
cat <<<"$testRustSrc" >src/main.rs
55
55
-
cat <<<"$nvimConfig" >script.lua
65
65
+
cargo new --bin test-rust-analyzer
66
66
+
cd test-rust-analyzer
67
67
+
cat <<<"$testRustSrc" >src/main.rs
68
68
+
cat <<<"$nvimConfig" >script.lua
56
69
57
57
-
# `-u` doesn't work
58
58
-
result="$(nvim --headless +'lua dofile("script.lua")' src/main.rs)"
59
59
-
echo "$result"
60
60
-
[[ "$result" == *"var: Vec<Option<String>>"* ]]
61
61
-
touch $out
62
62
-
''
70
70
+
# `-u` doesn't work
71
71
+
result="$(nvim --headless +'lua dofile("script.lua")' src/main.rs)"
72
72
+
echo "$result"
73
73
+
[[ "$result" == *"var: Vec<Option<String>>"* ]]
74
74
+
touch $out
75
75
+
''