My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix

49 lines
1.3 KiB

{ runCommandNoCC, cargo, neovim, rust-analyzer, rustc }:
runCommandNoCC "test-neovim-rust-analyzer" {
nativeBuildInputs = [ cargo neovim rust-analyzer rustc ];
testRustSrc = /* rust */ ''
fn main() {
let mut var = vec![None];
var.push(Some("hello".to_owned()));
}
'';
nvimConfig = /* lua */ ''
vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({
cmd = { "rust-analyzer" },
handlers = {
["$/progress"] = function(_, msg, ctx)
if msg.token == "rustAnalyzer/Indexing" and msg.value.kind == "end" then
vim.cmd("goto 23") -- let mut |var =...
vim.lsp.buf.hover()
end
end,
["textDocument/hover"] = function(_, msg, ctx)
-- Keep newlines.
io.write(msg.contents.value)
vim.cmd("q")
end,
},
on_error = function(code)
print("error: " .. code)
vim.cmd("q")
end
}))
'';
} ''
# neovim requires a writable HOME.
export HOME="$(pwd)"
cargo new --bin test-rust-analyzer
cd test-rust-analyzer
cat <<<"$testRustSrc" >src/main.rs
cat <<<"$nvimConfig" >script.lua
# `-u` doesn't work
result="$(nvim --headless +'lua dofile("script.lua")' src/main.rs)"
echo "$result"
[[ "$result" == *"var: Vec<Option<String>>"* ]]
touch $out
''