2022-10-21 18:38:19 +00:00
{ lib
, fetchFromGitHub
, linkFarm
, makeWrapper
, rustPlatform
, tree-sitter
2024-09-19 14:19:46 +00:00
, gitUpdater
, versionCheckHook
2022-10-21 18:38:19 +00:00
} :
let
# based on https://github.com/NixOS/nixpkgs/blob/aa07b78b9606daf1145a37f6299c6066939df075/pkgs/development/tools/parsing/tree-sitter/default.nix#L85-L104
withPlugins = grammarFn :
let
grammars = grammarFn tree-sitter . builtGrammars ;
in
linkFarm " g r a m m a r s "
( map
( drv :
let
name = lib . strings . getName drv ;
in
{
name =
" l i b " +
( lib . strings . removeSuffix " - g r a m m a r " name )
+ " . s o " ;
path = " ${ drv } / p a r s e r " ;
}
)
grammars ) ;
libPath = withPlugins ( _ : tree-sitter . allGrammars ) ;
in
rustPlatform . buildRustPackage rec {
pname = " d i f f s i t t e r " ;
2024-09-19 14:19:46 +00:00
version = " 0 . 8 . 4 " ;
2022-10-21 18:38:19 +00:00
src = fetchFromGitHub {
owner = " a f n a n e n a y e t " ;
repo = pname ;
rev = " v ${ version } " ;
2024-09-19 14:19:46 +00:00
hash = " s h a 2 5 6 - t a 7 J c S P E g p J w i e Y v t Z n N M F v s Y v z 4 F u x t h h m K M Y e 2 X U E = " ;
2022-10-21 18:38:19 +00:00
fetchSubmodules = false ;
} ;
2024-09-19 14:19:46 +00:00
cargoHash = " s h a 2 5 6 - V b d V 4 d f t C x x K L J r 9 T E u C e 9 t v S G b c 6 2 A U w l D Z d a N R N h w = " ;
2022-10-21 18:38:19 +00:00
buildNoDefaultFeatures = true ;
buildFeatures = [
" d y n a m i c - g r a m m a r - l i b s "
] ;
nativeBuildInputs = [
makeWrapper
] ;
2024-09-19 14:19:46 +00:00
nativeInstallCheckInputs = [
versionCheckHook
] ;
doInstallCheck = true ;
2022-10-21 18:38:19 +00:00
postInstall = ''
2023-05-24 13:37:59 +00:00
# completions are not yet implemented
# so we can safely remove this without installing the completions
rm $ out/bin/diffsitter_completions
2022-10-21 18:38:19 +00:00
wrapProgram " $ o u t / b i n / d i f f s i t t e r " \
- - prefix LD_LIBRARY_PATH : " ${ libPath } "
'' ;
doCheck = false ;
# failures:
# tests::diff_hunks_snapshot::_medium_cpp_cpp_false_expects
# tests::diff_hunks_snapshot::_medium_cpp_cpp_true_expects
# tests::diff_hunks_snapshot::_medium_rust_rs_false_expects
# tests::diff_hunks_snapshot::_medium_rust_rs_true_expects
# tests::diff_hunks_snapshot::_short_python_py_true_expects
# tests::diff_hunks_snapshot::_short_rust_rs_true_expects
2024-09-19 14:19:46 +00:00
passthru . updateScript = gitUpdater { rev-prefix = " v " ; } ;
2022-10-21 18:38:19 +00:00
meta = with lib ; {
homepage = " h t t p s : / / g i t h u b . c o m / a f n a n e n a y e t / d i f f s i t t e r " ;
2024-06-20 14:57:18 +00:00
description = " T r e e - s i t t e r b a s e d A S T d i f f t o o l t o g e t m e a n i n g f u l s e m a n t i c d i f f s " ;
2022-10-21 18:38:19 +00:00
license = licenses . mit ;
maintainers = with maintainers ; [ bbigras ] ;
} ;
}