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

This commit is contained in:
Austin Horstman 2024-11-17 08:49:52 -06:00 committed by GitHub
commit 7f36c78e33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 128 additions and 100 deletions

View File

@ -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";
};

View File

@ -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
''

View File

@ -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}"
''

View File

@ -1,62 +0,0 @@
{ runCommand, cargo, neovim, rust-analyzer, rustc }:
runCommand "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()));
}
'';
# 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 = /* lua */ ''
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
''

View File

@ -1,15 +0,0 @@
{ 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}"
''

View File

@ -7079,10 +7079,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 {