1{
2 pkgsBuildBuild,
3 lib,
4 fetchFromGitHub,
5 vscode-utils,
6 jq,
7 rust-analyzer,
8 buildNpmPackage,
9 moreutils,
10 esbuild,
11 pkg-config,
12 libsecret,
13 setDefaultServerPath ? true,
14}:
15
16let
17 pname = "rust-analyzer";
18 publisher = "rust-lang";
19
20 # Use the plugin version as in vscode marketplace, updated by update script.
21 inherit (vsix) version;
22
23 releaseTag = "2025-02-17";
24
25 src = fetchFromGitHub {
26 owner = "rust-lang";
27 repo = "rust-analyzer";
28 rev = releaseTag;
29 hash = "sha256-i76MMFSkCr4kDwurK8CACwZq7qEgVEgIzkOr2kiuAKk=";
30 };
31
32 vsix = buildNpmPackage {
33 inherit pname releaseTag;
34 version = lib.trim (lib.readFile ./version.txt);
35 src = "${src}/editors/code";
36 npmDepsHash = "sha256-0frOGphtzO6z8neSEYfjyRYrM6zEO3wId/TACblZkxM=";
37 buildInputs = [
38 pkgsBuildBuild.libsecret
39 ];
40 nativeBuildInputs = [
41 jq
42 moreutils
43 esbuild
44 # Required by `keytar`, which is a dependency of `vsce`.
45 pkg-config
46 ];
47
48 # Follows https://github.com/rust-lang/rust-analyzer/blob/41949748a6123fd6061eb984a47f4fe780525e63/xtask/src/dist.rs#L39-L65
49 installPhase = ''
50 jq '
51 .version = $ENV.version |
52 .releaseTag = $ENV.releaseTag |
53 .enableProposedApi = false |
54 walk(del(.["$generated-start"]?) | del(.["$generated-end"]?))
55 ' package.json | sponge package.json
56
57 mkdir -p $out
58 npx vsce package -o $out/${pname}.zip
59 '';
60 };
61
62in
63vscode-utils.buildVscodeExtension {
64 inherit version vsix pname;
65 src = "${vsix}/${pname}.zip";
66 vscodeExtUniqueId = "${publisher}.${pname}";
67 vscodeExtPublisher = publisher;
68 vscodeExtName = pname;
69
70 nativeBuildInputs = lib.optionals setDefaultServerPath [
71 jq
72 moreutils
73 ];
74
75 preInstall = lib.optionalString setDefaultServerPath ''
76 jq '(.contributes.configuration[] | select(.title == "server") | .properties."rust-analyzer.server.path".default) = $s' \
77 --arg s "${rust-analyzer}/bin/rust-analyzer" \
78 package.json | sponge package.json
79 '';
80
81 meta = {
82 description = "Alternative rust language server to the RLS";
83 homepage = "https://github.com/rust-lang/rust-analyzer";
84 license = [
85 lib.licenses.mit
86 lib.licenses.asl20
87 ];
88 maintainers = [ ];
89 platforms = lib.platforms.all;
90 };
91}