Merge pull request #173422 from oxalica/bump/rust-analyzer

rust-analyzer: 2022-05-02 -> 2022-05-17 and add tests
This commit is contained in:
Sandro 2022-05-19 19:16:46 +02:00 committed by GitHub
commit c3041fb60a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 4 deletions

View file

@ -1,5 +1,6 @@
{ lib { lib
, stdenv , stdenv
, callPackage
, fetchFromGitHub , fetchFromGitHub
, rustPlatform , rustPlatform
, CoreServices , CoreServices
@ -11,14 +12,14 @@
rustPlatform.buildRustPackage rec { rustPlatform.buildRustPackage rec {
pname = "rust-analyzer-unwrapped"; pname = "rust-analyzer-unwrapped";
version = "2022-05-02"; version = "2022-05-17";
cargoSha256 = "sha256-uZCUruIBTNTKYWYb8xQgJ6FsKlRi+Sh5n7m7aVk+hHQ="; cargoSha256 = "sha256-H0nuS56mvo5YUAUOsEnR4Cv3iFKixoHK83BcM1PFMA8=";
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "rust-lang"; owner = "rust-lang";
repo = "rust-analyzer"; repo = "rust-analyzer";
rev = version; rev = version;
sha256 = "sha256-5kAbd/tTc9vkr27ar44hnpXdS0vQg0OLJUMlp0FBjqA="; sha256 = "sha256-vrVpgQYUuJPgK1NMb1nxlCdxjoYo40YkUbZpH2Z2mwM=";
}; };
patches = [ patches = [
@ -54,7 +55,11 @@ rustPlatform.buildRustPackage rec {
runHook postInstallCheck 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; { meta = with lib; {
description = "A modular compiler frontend for the Rust language"; description = "A modular compiler frontend for the Rust language";

View file

@ -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<Option<String>>"* ]]
touch $out
''