Skip to content

Commit 7f36c78

Browse files
authored
rust-analyzer-unwrapped: 2024-09-02 -> 2024-11-11 (#354304)
2 parents 3660fd7 + 66689ef commit 7f36c78

File tree

6 files changed

+128
-100
lines changed

6 files changed

+128
-100
lines changed

pkgs/development/tools/rust/rust-analyzer/default.nix renamed to pkgs/by-name/ru/rust-analyzer-unwrapped/package.nix

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
1-
{ lib
2-
, stdenv
3-
, callPackage
4-
, fetchFromGitHub
5-
, rustPlatform
6-
, CoreServices
7-
, cmake
8-
, libiconv
9-
, useMimalloc ? false
10-
, doCheck ? true
11-
, nix-update-script
1+
{
2+
lib,
3+
stdenv,
4+
fetchFromGitHub,
5+
rustPlatform,
6+
cmake,
7+
libiconv,
8+
useMimalloc ? false,
9+
doCheck ? true,
10+
nix-update-script,
1211
}:
1312

1413
rustPlatform.buildRustPackage rec {
1514
pname = "rust-analyzer-unwrapped";
16-
version = "2024-09-02";
17-
cargoHash = "sha256-t45RzYkuywGByGWwUON3dW0aKjLYcFXB8uy4CybPuf4=";
15+
version = "2024-11-11";
16+
cargoHash = "sha256-lzbk/APerZih7+1ZxBKl0rUHCJJA8W8RIqalEfu+MFI=";
1817

1918
src = fetchFromGitHub {
2019
owner = "rust-lang";
2120
repo = "rust-analyzer";
2221
rev = version;
23-
hash = "sha256-YH0kH5CSOnAuPUB1BUzUqvnKiv5SgDhfMNjrkki9Ahk=";
22+
hash = "sha256-TDI1s2Sc/rpMLwful1NcTjYBbqzbQ4Mjw5PPOuOXVfg=";
2423
};
2524

26-
cargoBuildFlags = [ "--bin" "rust-analyzer" "--bin" "rust-analyzer-proc-macro-srv" ];
27-
cargoTestFlags = [ "--package" "rust-analyzer" "--package" "proc-macro-srv-cli" ];
25+
cargoBuildFlags = [
26+
"--bin"
27+
"rust-analyzer"
28+
"--bin"
29+
"rust-analyzer-proc-macro-srv"
30+
];
31+
cargoTestFlags = [
32+
"--package"
33+
"rust-analyzer"
34+
"--package"
35+
"proc-macro-srv-cli"
36+
];
2837

2938
# Code format check requires more dependencies but don't really matter for packaging.
3039
# So just ignore it.
@@ -33,7 +42,6 @@ rustPlatform.buildRustPackage rec {
3342
nativeBuildInputs = lib.optional useMimalloc cmake;
3443

3544
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
36-
CoreServices
3745
libiconv
3846
];
3947

@@ -58,13 +66,18 @@ rustPlatform.buildRustPackage rec {
5866
passthru = {
5967
updateScript = nix-update-script { };
6068
# FIXME: Pass overrided `rust-analyzer` once `buildRustPackage` also implements #119942
61-
tests.neovim-lsp = callPackage ./test-neovim-lsp.nix { };
69+
# FIXME: test script can't find rust std lib so hover doesn't return expected result
70+
# https://github.com/NixOS/nixpkgs/pull/354304
71+
# tests.neovim-lsp = callPackage ./test-neovim-lsp.nix { };
6272
};
6373

6474
meta = with lib; {
6575
description = "Modular compiler frontend for the Rust language";
6676
homepage = "https://rust-analyzer.github.io";
67-
license = with licenses; [ mit asl20 ];
77+
license = with licenses; [
78+
mit
79+
asl20
80+
];
6881
maintainers = with maintainers; [ oxalica ];
6982
mainProgram = "rust-analyzer";
7083
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
runCommand,
3+
cargo,
4+
neovim,
5+
rust-analyzer,
6+
rustc,
7+
}:
8+
runCommand "test-neovim-rust-analyzer"
9+
{
10+
nativeBuildInputs = [
11+
cargo
12+
neovim
13+
rust-analyzer
14+
rustc
15+
];
16+
17+
testRustSrc = ''
18+
fn main() {
19+
let mut var = vec![None];
20+
var.push(Some("hello".to_owned()));
21+
}
22+
'';
23+
24+
# NB. Wait for server done type calculations before sending `hover` request,
25+
# otherwise it would return `{unknown}`.
26+
# Ref: https://github.com/rust-lang/rust-analyzer/blob/7b11fdeb681c12002861b9804a388efde81c9647/docs/dev/lsp-extensions.md#server-status
27+
nvimConfig = ''
28+
local caps = vim.lsp.protocol.make_client_capabilities()
29+
caps["experimental"] = { serverStatusNotification = true }
30+
vim.lsp.buf_attach_client(vim.api.nvim_get_current_buf(), vim.lsp.start_client({
31+
cmd = { "rust-analyzer" },
32+
capabilities = caps,
33+
handlers = {
34+
["experimental/serverStatus"] = function(_, msg, ctx)
35+
if msg.health == "ok" then
36+
if msg.quiescent then
37+
vim.cmd("goto 23") -- let mut |var =...
38+
vim.lsp.buf.hover()
39+
end
40+
else
41+
print("error: server status is not ok: ")
42+
vim.cmd("q")
43+
end
44+
end,
45+
["textDocument/hover"] = function(_, msg, ctx)
46+
if msg then
47+
-- Keep newlines.
48+
io.write(msg.contents.value)
49+
vim.cmd("q")
50+
end
51+
end,
52+
},
53+
on_error = function(code)
54+
print("error: " .. code)
55+
vim.cmd("q")
56+
end
57+
}))
58+
'';
59+
60+
}
61+
''
62+
# neovim requires a writable HOME.
63+
export HOME="$(pwd)"
64+
65+
cargo new --bin test-rust-analyzer
66+
cd test-rust-analyzer
67+
cat <<<"$testRustSrc" >src/main.rs
68+
cat <<<"$nvimConfig" >script.lua
69+
70+
# `-u` doesn't work
71+
result="$(nvim --headless +'lua dofile("script.lua")' src/main.rs)"
72+
echo "$result"
73+
[[ "$result" == *"var: Vec<Option<String>>"* ]]
74+
touch $out
75+
''
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
rustPlatform,
3+
runCommand,
4+
makeWrapper,
5+
rust-analyzer-unwrapped,
6+
pname ? "rust-analyzer",
7+
version ? rust-analyzer-unwrapped.version,
8+
# Use name from `RUST_SRC_PATH`
9+
rustSrc ? rustPlatform.rustLibSrc,
10+
}:
11+
runCommand "${pname}-${version}"
12+
{
13+
inherit pname version;
14+
inherit (rust-analyzer-unwrapped) src meta;
15+
nativeBuildInputs = [ makeWrapper ];
16+
}
17+
''
18+
mkdir -p $out/bin
19+
makeWrapper ${rust-analyzer-unwrapped}/bin/rust-analyzer $out/bin/rust-analyzer \
20+
--set-default RUST_SRC_PATH "${rustSrc}"
21+
''

pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix

Lines changed: 0 additions & 62 deletions
This file was deleted.

pkgs/development/tools/rust/rust-analyzer/wrapper.nix

Lines changed: 0 additions & 15 deletions
This file was deleted.

pkgs/top-level/all-packages.nix

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7079,10 +7079,6 @@ with pkgs;
70797079
opensyclWithRocm = opensycl.override { rocmSupport = true; };
70807080

70817081
rustfmt = rustPackages.rustfmt;
7082-
rust-analyzer-unwrapped = callPackage ../development/tools/rust/rust-analyzer {
7083-
inherit (darwin.apple_sdk.frameworks) CoreServices;
7084-
};
7085-
rust-analyzer = callPackage ../development/tools/rust/rust-analyzer/wrapper.nix { };
70867082
rust-bindgen-unwrapped = callPackage ../development/tools/rust/bindgen/unwrapped.nix { };
70877083
rust-bindgen = callPackage ../development/tools/rust/bindgen { };
70887084
rust-cbindgen = callPackage ../development/tools/rust/cbindgen {

0 commit comments

Comments
 (0)