diff --git a/pkgs/development/tools/rust/rust-analyzer/default.nix b/pkgs/by-name/ru/rust-analyzer-unwrapped/package.nix
similarity index 64%
rename from pkgs/development/tools/rust/rust-analyzer/default.nix
rename to pkgs/by-name/ru/rust-analyzer-unwrapped/package.nix
index 986458e90b27..7c1c1484edd8 100644
--- a/pkgs/development/tools/rust/rust-analyzer/default.nix
+++ b/pkgs/by-name/ru/rust-analyzer-unwrapped/package.nix
@@ -1,30 +1,39 @@
-{ lib
-, stdenv
-, callPackage
-, fetchFromGitHub
-, rustPlatform
-, CoreServices
-, cmake
-, libiconv
-, useMimalloc ? false
-, doCheck ? true
-, nix-update-script
+{
+ lib,
+ stdenv,
+ fetchFromGitHub,
+ rustPlatform,
+ cmake,
+ libiconv,
+ useMimalloc ? false,
+ doCheck ? true,
+ nix-update-script,
}:
rustPlatform.buildRustPackage rec {
pname = "rust-analyzer-unwrapped";
- version = "2024-09-02";
- cargoHash = "sha256-t45RzYkuywGByGWwUON3dW0aKjLYcFXB8uy4CybPuf4=";
+ version = "2024-11-11";
+ cargoHash = "sha256-lzbk/APerZih7+1ZxBKl0rUHCJJA8W8RIqalEfu+MFI=";
src = fetchFromGitHub {
owner = "rust-lang";
repo = "rust-analyzer";
rev = version;
- hash = "sha256-YH0kH5CSOnAuPUB1BUzUqvnKiv5SgDhfMNjrkki9Ahk=";
+ hash = "sha256-TDI1s2Sc/rpMLwful1NcTjYBbqzbQ4Mjw5PPOuOXVfg=";
};
- cargoBuildFlags = [ "--bin" "rust-analyzer" "--bin" "rust-analyzer-proc-macro-srv" ];
- cargoTestFlags = [ "--package" "rust-analyzer" "--package" "proc-macro-srv-cli" ];
+ cargoBuildFlags = [
+ "--bin"
+ "rust-analyzer"
+ "--bin"
+ "rust-analyzer-proc-macro-srv"
+ ];
+ cargoTestFlags = [
+ "--package"
+ "rust-analyzer"
+ "--package"
+ "proc-macro-srv-cli"
+ ];
# Code format check requires more dependencies but don't really matter for packaging.
# So just ignore it.
@@ -33,7 +42,6 @@ rustPlatform.buildRustPackage rec {
nativeBuildInputs = lib.optional useMimalloc cmake;
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
- CoreServices
libiconv
];
@@ -58,13 +66,18 @@ rustPlatform.buildRustPackage rec {
passthru = {
updateScript = nix-update-script { };
# FIXME: Pass overrided `rust-analyzer` once `buildRustPackage` also implements #119942
- tests.neovim-lsp = callPackage ./test-neovim-lsp.nix { };
+ # FIXME: test script can't find rust std lib so hover doesn't return expected result
+ # https://github.com/NixOS/nixpkgs/pull/354304
+ # tests.neovim-lsp = callPackage ./test-neovim-lsp.nix { };
};
meta = with lib; {
description = "Modular compiler frontend for the Rust language";
homepage = "https://rust-analyzer.github.io";
- license = with licenses; [ mit asl20 ];
+ license = with licenses; [
+ mit
+ asl20
+ ];
maintainers = with maintainers; [ oxalica ];
mainProgram = "rust-analyzer";
};
diff --git a/pkgs/by-name/ru/rust-analyzer-unwrapped/test-neovim-lsp.nix b/pkgs/by-name/ru/rust-analyzer-unwrapped/test-neovim-lsp.nix
new file mode 100644
index 000000000000..9e7219763b89
--- /dev/null
+++ b/pkgs/by-name/ru/rust-analyzer-unwrapped/test-neovim-lsp.nix
@@ -0,0 +1,75 @@
+{
+ runCommand,
+ cargo,
+ neovim,
+ rust-analyzer,
+ rustc,
+}:
+runCommand "test-neovim-rust-analyzer"
+ {
+ nativeBuildInputs = [
+ cargo
+ neovim
+ rust-analyzer
+ rustc
+ ];
+
+ testRustSrc = ''
+ fn main() {
+ let mut var = vec![None];
+ var.push(Some("hello".to_owned()));
+ }
+ '';
+
+ # NB. Wait for server done type calculations before sending `hover` request,
+ # otherwise it would return `{unknown}`.
+ # Ref: https://github.com/rust-lang/rust-analyzer/blob/7b11fdeb681c12002861b9804a388efde81c9647/docs/dev/lsp-extensions.md#server-status
+ nvimConfig = ''
+ local caps = vim.lsp.protocol.make_client_capabilities()
+ caps["experimental"] = { serverStatusNotification = true }
+ vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({
+ cmd = { "rust-analyzer" },
+ capabilities = caps,
+ handlers = {
+ ["experimental/serverStatus"] = function(_, msg, ctx)
+ if msg.health == "ok" then
+ if msg.quiescent then
+ vim.cmd("goto 23") -- let mut |var =...
+ vim.lsp.buf.hover()
+ end
+ else
+ print("error: server status is not ok: ")
+ vim.cmd("q")
+ end
+ end,
+ ["textDocument/hover"] = function(_, msg, ctx)
+ if msg then
+ -- Keep newlines.
+ io.write(msg.contents.value)
+ vim.cmd("q")
+ end
+ 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