lol

Merge pull request #227159 from figsoda/neovim-ts

authored by

figsoda and committed by
GitHub
a002cddf 585449c7

+84 -1
+14 -1
pkgs/applications/editors/neovim/default.nix
··· 4 4 , unibilium, gperf 5 5 , libvterm-neovim 6 6 , tree-sitter 7 + , fetchurl 8 + , treesitter-parsers ? import ./treesitter-parsers.nix { inherit fetchurl; } 7 9 , CoreServices 8 10 , glibcLocales ? null, procps ? null 9 11 ··· 119 121 ) 120 122 '' + lib.optionalString stdenv.isDarwin '' 121 123 substituteInPlace src/nvim/CMakeLists.txt --replace " util" "" 122 - ''; 124 + '' + '' 125 + mkdir -p $out/lib/nvim/parser 126 + '' + lib.concatStrings (lib.mapAttrsToList 127 + (language: src: '' 128 + ln -s \ 129 + ${tree-sitter.buildGrammar { 130 + inherit language src; 131 + version = "neovim-${version}"; 132 + }}/parser \ 133 + $out/lib/nvim/parser/${language}.so 134 + '') 135 + treesitter-parsers); 123 136 124 137 shellHook='' 125 138 export VIMRUNTIME=$PWD/runtime
+24
pkgs/applications/editors/neovim/treesitter-parsers.nix
··· 1 + { fetchurl }: 2 + 3 + { 4 + c = fetchurl { 5 + url = "https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.2.tar.gz"; 6 + hash = "sha256:af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c13116a70af2"; 7 + }; 8 + lua = fetchurl { 9 + url = "https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.14.tar.gz"; 10 + hash = "sha256:930d0370dc15b66389869355c8e14305b9ba7aafd36edbfdb468c8023395016d"; 11 + }; 12 + vim = fetchurl { 13 + url = "https://github.com/neovim/tree-sitter-vim/archive/v0.3.0.tar.gz"; 14 + hash = "sha256:403acec3efb7cdb18ff3d68640fc823502a4ffcdfbb71cec3f98aa786c21cbe2"; 15 + }; 16 + vimdoc = fetchurl { 17 + url = "https://github.com/neovim/tree-sitter-vimdoc/archive/v2.0.0.tar.gz"; 18 + hash = "sha256:1ff8f4afd3a9599dd4c3ce87c155660b078c1229704d1a254433e33794b8f274"; 19 + }; 20 + query = fetchurl { 21 + url = "https://github.com/nvim-treesitter/tree-sitter-query/archive/v0.1.0.tar.gz"; 22 + hash = "sha256:e2b806f80e8bf1c4f4e5a96248393fe6622fc1fc6189d6896d269658f67f914c"; 23 + }; 24 + }
+46
pkgs/applications/editors/neovim/update-treesitter-parsers.py
··· 1 + #!/usr/bin/env nix-shell 2 + #!nix-shell -i python3 -p python3 3 + 4 + import re 5 + import subprocess 6 + from pathlib import Path 7 + 8 + parsers = {} 9 + dir = Path(__file__).parent 10 + regex = re.compile(r"^set\(TREESITTER_([A-Z_]+)_(URL|SHA256)\s+([^ \)]+)\s*\)\s*$") 11 + 12 + src = subprocess.check_output( 13 + [ 14 + "nix-build", 15 + dir.parent.parent.parent.parent, 16 + "-A", 17 + "neovim-unwrapped.src", 18 + "--no-out-link", 19 + ], 20 + text=True, 21 + ).strip() 22 + 23 + for line in open(f"{src}/cmake.deps/CMakeLists.txt"): 24 + m = regex.fullmatch(line) 25 + if m is None: 26 + continue 27 + 28 + lang = m[1].lower() 29 + ty = m[2] 30 + val = m[3] 31 + 32 + if not lang in parsers: 33 + parsers[lang] = {} 34 + parsers[lang][ty] = val 35 + 36 + with open(dir / "treesitter-parsers.nix", "w") as f: 37 + f.write("{ fetchurl }:\n\n{\n") 38 + for lang, src in parsers.items(): 39 + f.write( 40 + f""" {lang} = fetchurl {{ 41 + url = "{src["URL"]}"; 42 + hash = "sha256:{src["SHA256"]}"; 43 + }}; 44 + """ 45 + ) 46 + f.write("}\n")