1 { runCommand, cargo, neovim, rust-analyzer, rustc }:
2 runCommand "test-neovim-rust-analyzer" {
3 nativeBuildInputs = [ cargo neovim rust-analyzer rustc ];
5 testRustSrc = /* rust */ ''
7 let mut var = vec![None];
8 var.push(Some("hello".to_owned()));
12 nvimConfig = /* lua */ ''
13 vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({
14 cmd = { "rust-analyzer" },
16 ["$/progress"] = function(_, msg, ctx)
17 if msg.token == "rustAnalyzer/Indexing" and msg.value.kind == "end" then
18 vim.cmd("goto 23") -- let mut |var =...
22 ["textDocument/hover"] = function(_, msg, ctx)
24 io.write(msg.contents.value)
28 on_error = function(code)
29 print("error: " .. code)
36 # neovim requires a writable HOME.
39 cargo new --bin test-rust-analyzer
41 cat <<<"$testRustSrc" >src/main.rs
42 cat <<<"$nvimConfig" >script.lua
45 result="$(nvim --headless +'lua dofile("script.lua")' src/main.rs)"
47 [[ "$result" == *"var: Vec<Option<String>>"* ]]