1{ lib
2, fetchFromGitHub
3, linkFarm
4, makeWrapper
5, rustPlatform
6, tree-sitter
7}:
8
9let
10 # based on https://github.com/NixOS/nixpkgs/blob/aa07b78b9606daf1145a37f6299c6066939df075/pkgs/development/tools/parsing/tree-sitter/default.nix#L85-L104
11 withPlugins = grammarFn:
12 let
13 grammars = grammarFn tree-sitter.builtGrammars;
14 in
15 linkFarm "grammars"
16 (map
17 (drv:
18 let
19 name = lib.strings.getName drv;
20 in
21 {
22 name =
23 "lib" +
24 (lib.strings.removeSuffix "-grammar" name)
25 + ".so";
26 path = "${drv}/parser";
27 }
28 )
29 grammars);
30
31 libPath = withPlugins (_: tree-sitter.allGrammars);
32in
33rustPlatform.buildRustPackage rec {
34 pname = "diffsitter";
35 version = "0.8.0";
36
37 src = fetchFromGitHub {
38 owner = "afnanenayet";
39 repo = pname;
40 rev = "v${version}";
41 sha256 = "sha256-KrmK0RJdNJcZGM/7IxDP5IbJMTY3v6MkHA1SQW+U3hw=";
42 fetchSubmodules = false;
43 };
44
45 cargoHash = "sha256-3HALOoa3QDl9KE2UHxszzDw/VuDLLmjccXQvBBrfrHA=";
46
47 buildNoDefaultFeatures = true;
48 buildFeatures = [
49 "dynamic-grammar-libs"
50 ];
51
52 nativeBuildInputs = [
53 makeWrapper
54 ];
55
56 postInstall = ''
57 # completions are not yet implemented
58 # so we can safely remove this without installing the completions
59 rm $out/bin/diffsitter_completions
60
61 wrapProgram "$out/bin/diffsitter" \
62 --prefix LD_LIBRARY_PATH : "${libPath}"
63 '';
64
65 doCheck = false;
66 # failures:
67 # tests::diff_hunks_snapshot::_medium_cpp_cpp_false_expects
68 # tests::diff_hunks_snapshot::_medium_cpp_cpp_true_expects
69 # tests::diff_hunks_snapshot::_medium_rust_rs_false_expects
70 # tests::diff_hunks_snapshot::_medium_rust_rs_true_expects
71 # tests::diff_hunks_snapshot::_short_python_py_true_expects
72 # tests::diff_hunks_snapshot::_short_rust_rs_true_expects
73
74 meta = with lib; {
75 homepage = "https://github.com/afnanenayet/diffsitter";
76 description = "A tree-sitter based AST difftool to get meaningful semantic diffs";
77 license = licenses.mit;
78 maintainers = with maintainers; [ bbigras ];
79 };
80}