Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-analyzer-unwrapped: 2024-09-02 -> 2024-11-11 #354304

Merged
merged 9 commits into from
Nov 17, 2024
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -33,7 +42,6 @@ rustPlatform.buildRustPackage rec {
nativeBuildInputs = lib.optional useMimalloc cmake;

buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
CoreServices
libiconv
];

Expand All @@ -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";
};
Expand Down
75 changes: 75 additions & 0 deletions pkgs/by-name/ru/rust-analyzer-unwrapped/test-neovim-lsp.nix
Original file line number Diff line number Diff line change
@@ -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<Option<String>>"* ]]
touch $out
''
21 changes: 21 additions & 0 deletions pkgs/by-name/ru/rust-analyzer/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
rustPlatform,
runCommand,
makeWrapper,
rust-analyzer-unwrapped,
pname ? "rust-analyzer",
version ? rust-analyzer-unwrapped.version,
# Use name from `RUST_SRC_PATH`
rustSrc ? rustPlatform.rustLibSrc,
}:
runCommand "${pname}-${version}"
{
inherit pname version;
inherit (rust-analyzer-unwrapped) src meta;
nativeBuildInputs = [ makeWrapper ];
}
''
mkdir -p $out/bin
makeWrapper ${rust-analyzer-unwrapped}/bin/rust-analyzer $out/bin/rust-analyzer \
--set-default RUST_SRC_PATH "${rustSrc}"
''
62 changes: 0 additions & 62 deletions pkgs/development/tools/rust/rust-analyzer/test-neovim-lsp.nix

This file was deleted.

15 changes: 0 additions & 15 deletions pkgs/development/tools/rust/rust-analyzer/wrapper.nix

This file was deleted.

4 changes: 0 additions & 4 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7081,10 +7081,6 @@ with pkgs;
opensyclWithRocm = opensycl.override { rocmSupport = true; };

rustfmt = rustPackages.rustfmt;
rust-analyzer-unwrapped = callPackage ../development/tools/rust/rust-analyzer {
inherit (darwin.apple_sdk.frameworks) CoreServices;
};
rust-analyzer = callPackage ../development/tools/rust/rust-analyzer/wrapper.nix { };
rust-bindgen-unwrapped = callPackage ../development/tools/rust/bindgen/unwrapped.nix { };
rust-bindgen = callPackage ../development/tools/rust/bindgen { };
rust-cbindgen = callPackage ../development/tools/rust/cbindgen {
Expand Down