vimPlugins.nvim-treesitter: 0.10.0-unstable-2025-05-24 -> 0.10.0-unstable-2025-12-29
This commit is contained in:
@@ -64,6 +64,8 @@
|
||||
|
||||
- Xfce panel plugins have been moved to top level (e.g. if you previously added `pkgs.xfce.xfce4-whiskermenu-plugin` to `environment.systemPackages`, you will need to change it to `pkgs.xfce4-whiskermenu-plugin`).
|
||||
|
||||
- `vimPlugins.nvim-treesitter` has been updated to `main` branch, which is a full and incompatible rewrite. If you can't or don't want to update, you should use `vimPlugins.nvim-treesitter-legacy`.
|
||||
|
||||
## Other Notable Changes {#sec-nixpkgs-release-26.05-notable-changes}
|
||||
|
||||
<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
|
||||
|
||||
@@ -215,66 +215,74 @@ let
|
||||
|
||||
grammarToPlugin =
|
||||
grammar:
|
||||
let
|
||||
name = lib.pipe grammar [
|
||||
lib.getName
|
||||
# If the grammar has already been processed by this function, return it as-is.
|
||||
# This makes the function idempotent and prevents double-wrapping which mangles
|
||||
# the names of the generated parser files.
|
||||
if grammar ? origGrammar then
|
||||
grammar
|
||||
else
|
||||
let
|
||||
name = lib.pipe grammar [
|
||||
lib.getName
|
||||
|
||||
# added in buildGrammar
|
||||
(lib.removeSuffix "-grammar")
|
||||
# added in buildGrammar
|
||||
(lib.removeSuffix "-grammar")
|
||||
|
||||
# grammars from tree-sitter.builtGrammars
|
||||
(lib.removePrefix "tree-sitter-")
|
||||
(lib.replaceStrings [ "-" ] [ "_" ])
|
||||
];
|
||||
# grammars from tree-sitter.builtGrammars
|
||||
(lib.removePrefix "tree-sitter-")
|
||||
(lib.replaceStrings [ "-" ] [ "_" ])
|
||||
];
|
||||
|
||||
nvimGrammars = lib.mapAttrsToList (
|
||||
name: value:
|
||||
value.origGrammar
|
||||
or (throw "additions to `pkgs.vimPlugins.nvim-treesitter.grammarPlugins` set should be passed through `pkgs.neovimUtils.grammarToPlugin` first")
|
||||
) vimPlugins.nvim-treesitter.grammarPlugins;
|
||||
isNvimGrammar = x: builtins.elem x nvimGrammars;
|
||||
nvimGrammars = lib.mapAttrsToList (
|
||||
name: value:
|
||||
value.origGrammar
|
||||
or (throw "additions to `pkgs.vimPlugins.nvim-treesitter.grammarPlugins` set should be passed through `pkgs.neovimUtils.grammarToPlugin` first")
|
||||
) vimPlugins.nvim-treesitter.grammarPlugins;
|
||||
isNvimGrammar = x: builtins.elem x nvimGrammars;
|
||||
|
||||
toNvimTreesitterGrammar = makeSetupHook {
|
||||
name = "to-nvim-treesitter-grammar";
|
||||
} ./to-nvim-treesitter-grammar.sh;
|
||||
in
|
||||
toNvimTreesitterGrammar = makeSetupHook {
|
||||
name = "to-nvim-treesitter-grammar";
|
||||
} ./to-nvim-treesitter-grammar.sh;
|
||||
in
|
||||
|
||||
(toVimPlugin (
|
||||
stdenv.mkDerivation {
|
||||
name = "treesitter-grammar-${name}";
|
||||
(toVimPlugin (
|
||||
stdenv.mkDerivation {
|
||||
name = "nvim-treesitter-grammar-${name}";
|
||||
|
||||
origGrammar = grammar;
|
||||
grammarName = name;
|
||||
origGrammar = grammar;
|
||||
grammarName = name;
|
||||
|
||||
# Queries for nvim-treesitter's (not just tree-sitter's) officially
|
||||
# supported languages are bundled with nvim-treesitter
|
||||
# Queries from repositories for such languages are incompatible
|
||||
# with nvim's implementation of treesitter.
|
||||
#
|
||||
# We try our best effort to only include queries for niche languages
|
||||
# (there are grammars for them in nixpkgs, but they're in
|
||||
# `tree-sitter-grammars.tree-sitter-*`; `vimPlugins.nvim-treesitter-parsers.*`
|
||||
# only includes officially supported languages)
|
||||
#
|
||||
# To use grammar for a niche language, users usually do:
|
||||
# packages.all.start = with final.vimPlugins; [
|
||||
# (pkgs.neovimUtils.grammarToPlugin pkgs.tree-sitter-grammars.tree-sitter-LANG)
|
||||
# ]
|
||||
#
|
||||
# See also https://github.com/NixOS/nixpkgs/pull/344849#issuecomment-2381447839
|
||||
installQueries = !isNvimGrammar grammar;
|
||||
# Queries for nvim-treesitter's (not just tree-sitter's) officially
|
||||
# supported languages are bundled with nvim-treesitter
|
||||
# Queries from repositories for such languages are incompatible
|
||||
# with nvim's implementation of treesitter.
|
||||
#
|
||||
# We try our best effort to only include queries for niche languages
|
||||
# (there are grammars for them in nixpkgs, but they're in
|
||||
# `tree-sitter-grammars.tree-sitter-*`; `vimPlugins.nvim-treesitter-parsers.*`
|
||||
# only includes officially supported languages)
|
||||
#
|
||||
# To use grammar for a niche language, users usually do:
|
||||
# packages.all.start = with final.vimPlugins; [
|
||||
# (pkgs.neovimUtils.grammarToPlugin pkgs.tree-sitter-grammars.tree-sitter-LANG)
|
||||
# ]
|
||||
#
|
||||
# See also https://github.com/NixOS/nixpkgs/pull/344849#issuecomment-2381447839
|
||||
installQueries = !isNvimGrammar grammar;
|
||||
|
||||
dontUnpack = true;
|
||||
__structuredAttrs = true;
|
||||
dontUnpack = true;
|
||||
__structuredAttrs = true;
|
||||
|
||||
nativeBuildInputs = [ toNvimTreesitterGrammar ];
|
||||
nativeBuildInputs = [ toNvimTreesitterGrammar ];
|
||||
|
||||
meta = {
|
||||
platforms = lib.platforms.all;
|
||||
passthru = grammar.passthru or { };
|
||||
|
||||
meta = {
|
||||
platforms = lib.platforms.all;
|
||||
}
|
||||
// grammar.meta;
|
||||
}
|
||||
// grammar.meta;
|
||||
}
|
||||
));
|
||||
));
|
||||
|
||||
/*
|
||||
Fork of vimUtils.packDir that additionally generates a propagated-build-inputs-file that
|
||||
|
||||
@@ -11922,12 +11922,12 @@ final: prev: {
|
||||
|
||||
nvim-treesitter = buildVimPlugin {
|
||||
pname = "nvim-treesitter";
|
||||
version = "0.10.0-unstable-2025-05-24";
|
||||
version = "0.10.0-unstable-2025-12-29";
|
||||
src = fetchFromGitHub {
|
||||
owner = "nvim-treesitter";
|
||||
repo = "nvim-treesitter";
|
||||
rev = "42fc28ba918343ebfd5565147a42a26580579482";
|
||||
hash = "sha256-CVs9FTdg3oKtRjz2YqwkMr0W5qYLGfVyxyhE3qnGYbI=";
|
||||
rev = "7efc1b58a8061d29786860006c7257c90a5196dc";
|
||||
hash = "sha256-AMEzUaVVPzHT7vpPJUFt5UbBiN9tygH5UMio/lU/baw=";
|
||||
};
|
||||
meta.homepage = "https://github.com/nvim-treesitter/nvim-treesitter/";
|
||||
meta.hydraPlatforms = [ ];
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
lib,
|
||||
vimPlugins,
|
||||
}:
|
||||
lib.recurseIntoAttrs vimPlugins.nvim-treesitter.grammarPlugins
|
||||
lib.recurseIntoAttrs vimPlugins.nvim-treesitter.parsers
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,13 @@
|
||||
{
|
||||
lib,
|
||||
callPackage,
|
||||
symlinkJoin,
|
||||
vimUtils,
|
||||
tree-sitter,
|
||||
neovim,
|
||||
neovimUtils,
|
||||
runCommand,
|
||||
vimPlugins,
|
||||
tree-sitter-grammars,
|
||||
writableTmpDirAsHomeHook,
|
||||
}:
|
||||
|
||||
@@ -15,18 +16,43 @@ self: super:
|
||||
let
|
||||
inherit (neovimUtils) grammarToPlugin;
|
||||
|
||||
overrides = prev: {
|
||||
buildQueries =
|
||||
{ language }:
|
||||
vimUtils.toVimPlugin (
|
||||
runCommand "nvim-treesitter-queries-${language}"
|
||||
{
|
||||
passthru = { inherit language; };
|
||||
meta.description = "Queries for ${language} from nvim-treesitter";
|
||||
}
|
||||
''
|
||||
mkdir -p "$out/queries"
|
||||
if [ -d "${super.nvim-treesitter.src}/runtime/queries/${language}" ]; then
|
||||
ln -s "${super.nvim-treesitter.src}/runtime/queries/${language}" "$out/queries/${language}"
|
||||
else
|
||||
echo "Error: there are no queries for ${language}."
|
||||
exit 1
|
||||
fi
|
||||
''
|
||||
);
|
||||
|
||||
generated = callPackage ./generated.nix {
|
||||
inherit (tree-sitter) buildGrammar;
|
||||
inherit buildQueries;
|
||||
};
|
||||
|
||||
generatedGrammars =
|
||||
let
|
||||
generated = callPackage ./generated.nix {
|
||||
inherit (tree-sitter) buildGrammar;
|
||||
};
|
||||
in
|
||||
lib.overrideExisting generated (overrides generated);
|
||||
inherit (generated) parsers queries;
|
||||
|
||||
generatedDerivations = lib.filterAttrs (_: lib.isDerivation) generatedGrammars;
|
||||
parsersWithMeta = lib.mapAttrs (
|
||||
lang: parser:
|
||||
if lib.hasAttr lang queries then
|
||||
parser.overrideAttrs (old: {
|
||||
passthru = (old.passthru or { }) // {
|
||||
associatedQuery = queries.${lang};
|
||||
};
|
||||
})
|
||||
else
|
||||
parser
|
||||
) parsers;
|
||||
|
||||
# add aliases so grammars from `tree-sitter` are overwritten in `withPlugins`
|
||||
# for example, for ocaml_interface, the following aliases will be added
|
||||
@@ -34,7 +60,7 @@ let
|
||||
# tree-sitter-ocaml-interface
|
||||
# tree-sitter-ocaml_interface
|
||||
builtGrammars =
|
||||
generatedGrammars
|
||||
parsersWithMeta
|
||||
// lib.concatMapAttrs (
|
||||
k: v:
|
||||
let
|
||||
@@ -47,9 +73,9 @@ let
|
||||
${replaced} = v;
|
||||
"tree-sitter-${replaced}" = v;
|
||||
}
|
||||
) generatedDerivations;
|
||||
) parsersWithMeta;
|
||||
|
||||
allGrammars = lib.attrValues generatedDerivations;
|
||||
allGrammars = lib.attrValues parsersWithMeta;
|
||||
|
||||
# Usage:
|
||||
# pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ p.c p.java ... ])
|
||||
@@ -57,28 +83,44 @@ let
|
||||
# pkgs.vimPlugins.nvim-treesitter.withAllGrammars
|
||||
withPlugins =
|
||||
f:
|
||||
let
|
||||
selectedGrammars = f (tree-sitter.builtGrammars // builtGrammars);
|
||||
|
||||
grammarPlugins = map grammarToPlugin selectedGrammars;
|
||||
|
||||
queryPlugins = lib.pipe selectedGrammars [
|
||||
(map (g: g.passthru.associatedQuery or null))
|
||||
(lib.filter (q: q != null))
|
||||
];
|
||||
in
|
||||
self.nvim-treesitter.overrideAttrs {
|
||||
passthru.dependencies = map grammarToPlugin (f (tree-sitter.builtGrammars // builtGrammars));
|
||||
passthru.dependencies = [
|
||||
(symlinkJoin {
|
||||
name = "nvim-treesitter-grammars";
|
||||
paths = grammarPlugins ++ queryPlugins;
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
withAllGrammars = withPlugins (_: allGrammars);
|
||||
grammarPlugins = lib.mapAttrs (_: grammarToPlugin) parsersWithMeta;
|
||||
in
|
||||
|
||||
{
|
||||
postPatch = ''
|
||||
rm -r parser
|
||||
'';
|
||||
nvimSkipModules = [ "nvim-treesitter._meta.parsers" ];
|
||||
|
||||
passthru = (super.nvim-treesitter.passthru or { }) // {
|
||||
passthru = super.nvim-treesitter.passthru or { } // {
|
||||
inherit
|
||||
buildQueries
|
||||
builtGrammars
|
||||
allGrammars
|
||||
grammarPlugins
|
||||
grammarToPlugin
|
||||
withPlugins
|
||||
withAllGrammars
|
||||
queries
|
||||
;
|
||||
|
||||
grammarPlugins = lib.mapAttrs (_: grammarToPlugin) generatedDerivations;
|
||||
parsers = grammarPlugins;
|
||||
|
||||
tests = {
|
||||
check-queries =
|
||||
@@ -100,7 +142,7 @@ in
|
||||
ln -s ${withAllGrammars}/CONTRIBUTING.md .
|
||||
export ALLOWED_INSTALLATION_FAILURES=ipkg,norg,verilog
|
||||
|
||||
nvim --headless "+luafile ${withAllGrammars}/scripts/check-queries.lua" | tee log
|
||||
nvim --headless -l "${withAllGrammars}/scripts/check-queries.lua" | tee log
|
||||
|
||||
if grep -q Warning log; then
|
||||
echo "WARNING: warnings were emitted by the check"
|
||||
@@ -108,45 +150,9 @@ in
|
||||
fi
|
||||
'';
|
||||
|
||||
tree-sitter-queries-are-present-for-custom-grammars =
|
||||
let
|
||||
pluginsToCheck =
|
||||
map (grammar: grammarToPlugin grammar)
|
||||
# non-derivations are here because there is a `recurseForDerivations = true`
|
||||
(lib.filter lib.isDerivation (lib.attrValues tree-sitter-grammars));
|
||||
in
|
||||
runCommand "nvim-treesitter-test-queries-are-present-for-custom-grammars" { CI = true; } ''
|
||||
touch "$out"
|
||||
|
||||
function check_grammar {
|
||||
local grammar_name="$1"
|
||||
local grammar_path="$2"
|
||||
|
||||
local grammar_queries=$(find -L "$grammar_path/queries/$grammar_name" -name '*.scm')
|
||||
local EXPECTED_FILES="$grammar_path/parser/$grammar_name.so $grammar_queries"
|
||||
|
||||
echo ""
|
||||
echo "expected files for $grammar_name:"
|
||||
echo "$EXPECTED_FILES"
|
||||
|
||||
# the derivation has only symlinks, and `find` doesn't count them as files
|
||||
# so we cannot use `-type f`, thus we use `-not -type d`
|
||||
for file in $(find -L $2 -not -type d); do
|
||||
echo "checking $file"
|
||||
# see https://stackoverflow.com/a/8063284
|
||||
if ! echo "$EXPECTED_FILES" | grep -wqF "$file"; then
|
||||
echo "$file is unexpected, exiting"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
${lib.concatLines (lib.forEach pluginsToCheck (g: "check_grammar \"${g.grammarName}\" \"${g}\""))}
|
||||
'';
|
||||
|
||||
no-queries-for-official-grammars =
|
||||
let
|
||||
pluginsToCheck = lib.filter lib.isDerivation (lib.attrValues vimPlugins.nvim-treesitter-parsers);
|
||||
pluginsToCheck = lib.filter lib.isDerivation (lib.attrValues vimPlugins.nvim-treesitter.parsers);
|
||||
in
|
||||
runCommand "nvim-treesitter-test-no-queries-for-official-grammars" { CI = true; } ''
|
||||
touch "$out"
|
||||
@@ -168,10 +174,8 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
meta =
|
||||
|
||||
(super.nvim-treesitter.meta or { }) // {
|
||||
license = lib.licenses.asl20;
|
||||
maintainers = [ ];
|
||||
};
|
||||
meta = super.nvim-treesitter.meta or { } // {
|
||||
license = lib.licenses.asl20;
|
||||
maintainers = [ ];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,7 +13,10 @@ import requests
|
||||
log = logging.getLogger("vim-updater")
|
||||
|
||||
NURR_JSON_URL = (
|
||||
"https://raw.githubusercontent.com/nvim-neorocks/nurr/main/tree-sitter-parsers.json"
|
||||
"https://raw.githubusercontent.com/lumen-oss/nurr/main/tree-sitter-parsers.json"
|
||||
)
|
||||
NVIM_TREESITTER_QUERIES_URL = (
|
||||
"https://api.github.com/repos/nvim-treesitter/nvim-treesitter/contents/runtime/queries"
|
||||
)
|
||||
|
||||
|
||||
@@ -28,33 +31,41 @@ def generate_grammar(lang, parser_info):
|
||||
url = install_info["url"]
|
||||
rev = install_info["revision"]
|
||||
|
||||
generated = f""" {lang} = buildGrammar {{
|
||||
language = "{lang}";
|
||||
version = "0.0.0+rev={rev[:7]}";
|
||||
src = """
|
||||
generated = f""" {lang} = buildGrammar {{
|
||||
language = "{lang}";
|
||||
version = "0.0.0+rev={rev[:7]}";
|
||||
src = """
|
||||
|
||||
generated += subprocess.check_output(
|
||||
["nurl", url, rev, "--indent=4"], text=True
|
||||
["nurl", url, rev, "--indent=6"], text=True
|
||||
)
|
||||
generated += ";"
|
||||
|
||||
location = install_info.get("location", "")
|
||||
if location:
|
||||
generated += f"""
|
||||
location = "{location}";"""
|
||||
location = "{location}";"""
|
||||
|
||||
if install_info.get("generate", False):
|
||||
generated += """
|
||||
generate = true;"""
|
||||
generate = true;"""
|
||||
|
||||
generated += f"""
|
||||
meta.homepage = "{url}";
|
||||
}};
|
||||
meta.homepage = "{url}";
|
||||
}};
|
||||
"""
|
||||
|
||||
return generated
|
||||
|
||||
|
||||
def generate_query(lang):
|
||||
"""Generate query derivation for a language"""
|
||||
return f""" {lang} = buildQueries {{
|
||||
language = "{lang}";
|
||||
}};
|
||||
"""
|
||||
|
||||
|
||||
def fetch_nurr_parsers():
|
||||
"""Fetch the parser information from nurr repository"""
|
||||
log.info("Fetching parser data from %s", NURR_JSON_URL)
|
||||
@@ -81,6 +92,25 @@ def fetch_nurr_parsers():
|
||||
return parsers
|
||||
|
||||
|
||||
def fetch_available_queries():
|
||||
"""Fetch list of languages that have queries in nvim-treesitter repo"""
|
||||
log.info("Fetching available queries from %s", NVIM_TREESITTER_QUERIES_URL)
|
||||
|
||||
headers = {}
|
||||
github_token = os.environ.get("GITHUB_TOKEN")
|
||||
if github_token:
|
||||
headers["Authorization"] = f"token {github_token}"
|
||||
|
||||
response = requests.get(NVIM_TREESITTER_QUERIES_URL, headers=headers, timeout=30)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
# We assume items with type="dir" in the queries/ folder are language names
|
||||
languages = sorted([item["name"] for item in data if item["type"] == "dir"])
|
||||
log.info(f"Found {len(languages)} languages with queries")
|
||||
return languages
|
||||
|
||||
|
||||
def process_parser_info(parser_info):
|
||||
"""Process a single parser info entry and generate grammar for it"""
|
||||
return generate_grammar(parser_info["lang"], parser_info)
|
||||
@@ -89,12 +119,14 @@ def process_parser_info(parser_info):
|
||||
def update_grammars():
|
||||
"""Update grammar definitions using nurr's parser information"""
|
||||
parsers_info = fetch_nurr_parsers()
|
||||
queries_list = fetch_available_queries()
|
||||
|
||||
generated_file = """# generated by pkgs/applications/editors/vim/plugins/utils/nvim-treesitter/update.py
|
||||
# Using parser data from https://github.com/nvim-neorocks/nurr/blob/main/tree-sitter-parsers.json
|
||||
|
||||
{
|
||||
buildGrammar,
|
||||
buildQueries,
|
||||
"""
|
||||
|
||||
nurl_output = subprocess.check_output(["nurl", "-Ls", ","], text=True).strip()
|
||||
@@ -104,6 +136,7 @@ def update_grammars():
|
||||
}:
|
||||
|
||||
{
|
||||
parsers = {
|
||||
"""
|
||||
|
||||
# Process parsers in parallel for better performance
|
||||
@@ -111,7 +144,16 @@ def update_grammars():
|
||||
for generated in executor.map(process_parser_info, parsers_info):
|
||||
generated_file += generated
|
||||
|
||||
generated_file += "}\n"
|
||||
generated_file += """ };
|
||||
|
||||
queries = {
|
||||
"""
|
||||
|
||||
# Process queries
|
||||
for lang in queries_list:
|
||||
generated_file += generate_query(lang)
|
||||
|
||||
generated_file += " };\n}\n"
|
||||
return generated_file
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user