diff options
author | figsoda <figsoda@pm.me> | 2023-04-19 19:08:07 -0400 |
---|---|---|
committer | figsoda <figsoda@pm.me> | 2023-04-19 21:17:19 -0400 |
commit | 79a85d3ce548122577aaf9f779e07ec4cba6faca (patch) | |
tree | eea45a4b423aa1132fd7c1461aedd945f360045f /pkgs/applications/editors/neovim | |
parent | 496c532a0301ef9d31286356050b4bdcab67ae79 (diff) | |
download | nixlib-79a85d3ce548122577aaf9f779e07ec4cba6faca.tar nixlib-79a85d3ce548122577aaf9f779e07ec4cba6faca.tar.gz nixlib-79a85d3ce548122577aaf9f779e07ec4cba6faca.tar.bz2 nixlib-79a85d3ce548122577aaf9f779e07ec4cba6faca.tar.lz nixlib-79a85d3ce548122577aaf9f779e07ec4cba6faca.tar.xz nixlib-79a85d3ce548122577aaf9f779e07ec4cba6faca.tar.zst nixlib-79a85d3ce548122577aaf9f779e07ec4cba6faca.zip |
neovim: bundle treesitter parsers
Diffstat (limited to 'pkgs/applications/editors/neovim')
-rw-r--r-- | pkgs/applications/editors/neovim/default.nix | 15 | ||||
-rw-r--r-- | pkgs/applications/editors/neovim/treesitter-parsers.nix | 24 | ||||
-rwxr-xr-x | pkgs/applications/editors/neovim/update-treesitter-parsers.py | 46 |
3 files changed, 84 insertions, 1 deletions
diff --git a/pkgs/applications/editors/neovim/default.nix b/pkgs/applications/editors/neovim/default.nix index fb850c7ca366..7d735421b07a 100644 --- a/pkgs/applications/editors/neovim/default.nix +++ b/pkgs/applications/editors/neovim/default.nix @@ -4,6 +4,8 @@ , unibilium, gperf , libvterm-neovim , tree-sitter +, fetchurl +, treesitter-parsers ? import ./treesitter-parsers.nix { inherit fetchurl; } , CoreServices , glibcLocales ? null, procps ? null @@ -119,7 +121,18 @@ in ) '' + lib.optionalString stdenv.isDarwin '' substituteInPlace src/nvim/CMakeLists.txt --replace " util" "" - ''; + '' + '' + mkdir -p $out/lib/nvim/parser + '' + lib.concatStrings (lib.mapAttrsToList + (language: src: '' + ln -s \ + ${tree-sitter.buildGrammar { + inherit language src; + version = "neovim-${version}"; + }}/parser \ + $out/lib/nvim/parser/${language}.so + '') + treesitter-parsers); shellHook='' export VIMRUNTIME=$PWD/runtime diff --git a/pkgs/applications/editors/neovim/treesitter-parsers.nix b/pkgs/applications/editors/neovim/treesitter-parsers.nix new file mode 100644 index 000000000000..d36f8bda8542 --- /dev/null +++ b/pkgs/applications/editors/neovim/treesitter-parsers.nix @@ -0,0 +1,24 @@ +{ fetchurl }: + +{ + c = fetchurl { + url = "https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.2.tar.gz"; + hash = "sha256:af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c13116a70af2"; + }; + lua = fetchurl { + url = "https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.14.tar.gz"; + hash = "sha256:930d0370dc15b66389869355c8e14305b9ba7aafd36edbfdb468c8023395016d"; + }; + vim = fetchurl { + url = "https://github.com/neovim/tree-sitter-vim/archive/v0.3.0.tar.gz"; + hash = "sha256:403acec3efb7cdb18ff3d68640fc823502a4ffcdfbb71cec3f98aa786c21cbe2"; + }; + vimdoc = fetchurl { + url = "https://github.com/neovim/tree-sitter-vimdoc/archive/v2.0.0.tar.gz"; + hash = "sha256:1ff8f4afd3a9599dd4c3ce87c155660b078c1229704d1a254433e33794b8f274"; + }; + query = fetchurl { + url = "https://github.com/nvim-treesitter/tree-sitter-query/archive/v0.1.0.tar.gz"; + hash = "sha256:e2b806f80e8bf1c4f4e5a96248393fe6622fc1fc6189d6896d269658f67f914c"; + }; +} diff --git a/pkgs/applications/editors/neovim/update-treesitter-parsers.py b/pkgs/applications/editors/neovim/update-treesitter-parsers.py new file mode 100755 index 000000000000..27260ca64917 --- /dev/null +++ b/pkgs/applications/editors/neovim/update-treesitter-parsers.py @@ -0,0 +1,46 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i python3 -p python3 + +import re +import subprocess +from pathlib import Path + +parsers = {} +dir = Path(__file__).parent +regex = re.compile(r"^set\(TREESITTER_([A-Z_]+)_(URL|SHA256)\s+([^ \)]+)\s*\)\s*$") + +src = subprocess.check_output( + [ + "nix-build", + dir.parent.parent.parent.parent, + "-A", + "neovim-unwrapped.src", + "--no-out-link", + ], + text=True, +).strip() + +for line in open(f"{src}/cmake.deps/CMakeLists.txt"): + m = regex.fullmatch(line) + if m is None: + continue + + lang = m[1].lower() + ty = m[2] + val = m[3] + + if not lang in parsers: + parsers[lang] = {} + parsers[lang][ty] = val + +with open(dir / "treesitter-parsers.nix", "w") as f: + f.write("{ fetchurl }:\n\n{\n") + for lang, src in parsers.items(): + f.write( + f""" {lang} = fetchurl {{ + url = "{src["URL"]}"; + hash = "sha256:{src["SHA256"]}"; + }}; +""" + ) + f.write("}\n") |