From 4ae5670eaa7dce6e82d5e0a5b49a97ac7023ccce Mon Sep 17 00:00:00 2001 From: oxalica Date: Tue, 17 May 2022 23:33:48 +0800 Subject: [PATCH 1/2] rust-analyzer: 2022-05-02 -> 2022-05-17 --- pkgs/development/tools/rust/rust-analyzer/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/development/tools/rust/rust-analyzer/default.nix b/pkgs/development/tools/rust/rust-analyzer/default.nix index acacdcefb415..ce07a3973f9c 100644 --- a/pkgs/development/tools/rust/rust-analyzer/default.nix +++ b/pkgs/development/tools/rust/rust-analyzer/default.nix @@ -11,14 +11,14 @@ rustPlatform.buildRustPackage rec { pname = "rust-analyzer-unwrapped"; - version = "2022-05-02"; - cargoSha256 = "sha256-uZCUruIBTNTKYWYb8xQgJ6FsKlRi+Sh5n7m7aVk+hHQ="; + version = "2022-05-17"; + cargoSha256 = "sha256-H0nuS56mvo5YUAUOsEnR4Cv3iFKixoHK83BcM1PFMA8="; src = fetchFromGitHub { owner = "rust-lang"; repo = "rust-analyzer"; rev = version; - sha256 = "sha256-5kAbd/tTc9vkr27ar44hnpXdS0vQg0OLJUMlp0FBjqA="; + sha256 = "sha256-vrVpgQYUuJPgK1NMb1nxlCdxjoYo40YkUbZpH2Z2mwM="; }; patches = [ From 178aaa60f1d179a4351f7d8f5b5403bc1d756992 Mon Sep 17 00:00:00 2001 From: oxalica Date: Wed, 18 May 2022 01:27:46 +0800 Subject: [PATCH 2/2] rust-analyzer: add tests with neovim --- .../tools/rust/rust-analyzer/default.nix | 7 ++- .../rust/rust-analyzer/test-neovim-lsp.nix | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix diff --git a/pkgs/development/tools/rust/rust-analyzer/default.nix b/pkgs/development/tools/rust/rust-analyzer/default.nix index ce07a3973f9c..861a4075990c 100644 --- a/pkgs/development/tools/rust/rust-analyzer/default.nix +++ b/pkgs/development/tools/rust/rust-analyzer/default.nix @@ -1,5 +1,6 @@ { lib , stdenv +, callPackage , fetchFromGitHub , rustPlatform , CoreServices @@ -54,7 +55,11 @@ rustPlatform.buildRustPackage rec { runHook postInstallCheck ''; - passthru.updateScript = ./update.sh; + passthru = { + updateScript = ./update.sh; + # FIXME: Pass overrided `rust-analyzer` once `buildRustPackage` also implements #119942 + tests.neovim-lsp = callPackage ./test-neovim-lsp.nix { }; + }; meta = with lib; { description = "A modular compiler frontend for the Rust language"; diff --git a/pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix b/pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix new file mode 100644 index 000000000000..6782a7418a68 --- /dev/null +++ b/pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix @@ -0,0 +1,49 @@ +{ 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>"* ]] + touch $out +''