From ba90b54301f662b9d79875722d4b9552bb26c412 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 9 Jul 2024 15:26:48 +0200 Subject: [PATCH] build(deps): drop unused bundled bash, python parsers and queries Problem: Neovim bundles treesitter parsers for bash and python but does not use them by default. This dilutes the messaging about the bundled parsers being required for functionality or reasonable out-of-the-box experience. It also increases the risk of query incompatibilities for no gain. Solution: Stop bundling bash and python parser and queries. (cherry picked from commit 51d85f7ea58bd715cec1fdfa8d19826cafe7185d) --- BUILD.md | 2 +- cmake.deps/cmake/BuildTreesitterParsers.cmake | 2 +- cmake.deps/deps.txt | 4 - runtime/doc/news.txt | 4 +- runtime/queries/bash/folds.scm | 9 - runtime/queries/bash/highlights.scm | 232 --------- runtime/queries/bash/injections.scm | 3 - runtime/queries/python/folds.scm | 28 -- runtime/queries/python/highlights.scm | 457 ------------------ test/functional/treesitter/fold_spec.lua | 16 +- 10 files changed, 12 insertions(+), 745 deletions(-) delete mode 100644 runtime/queries/bash/folds.scm delete mode 100644 runtime/queries/bash/highlights.scm delete mode 100644 runtime/queries/bash/injections.scm delete mode 100644 runtime/queries/python/folds.scm delete mode 100644 runtime/queries/python/highlights.scm diff --git a/BUILD.md b/BUILD.md index 621a615948..5ff88ab0ff 100644 --- a/BUILD.md +++ b/BUILD.md @@ -240,7 +240,7 @@ cmake --build build ### How to build without "bundled" dependencies 1. Manually install the dependencies: - - libuv libluv libvterm luajit lua-lpeg lua-mpack msgpack-c tree-sitter tree-sitter-bash tree-sitter-c tree-sitter-lua tree-sitter-markdown tree-sitter-python tree-sitter-query tree-sitter-vim tree-sitter-vimdoc unibilium + - libuv libluv libvterm luajit lua-lpeg lua-mpack msgpack-c tree-sitter tree-sitter-c tree-sitter-lua tree-sitter-markdown tree-sitter-query tree-sitter-vim tree-sitter-vimdoc unibilium 2. Run CMake: ```sh cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo diff --git a/cmake.deps/cmake/BuildTreesitterParsers.cmake b/cmake.deps/cmake/BuildTreesitterParsers.cmake index 837d075d20..060447e6fe 100644 --- a/cmake.deps/cmake/BuildTreesitterParsers.cmake +++ b/cmake.deps/cmake/BuildTreesitterParsers.cmake @@ -28,7 +28,7 @@ function(BuildTSParser) ${EXTERNALPROJECT_OPTIONS}) endfunction() -foreach(lang c lua vim vimdoc query python bash) +foreach(lang c lua vim vimdoc query) BuildTSParser(LANG ${lang}) endforeach() BuildTSParser(LANG markdown CMAKE_FILE MarkdownParserCMakeLists.txt) diff --git a/cmake.deps/deps.txt b/cmake.deps/deps.txt index 0e3862430c..6c72708747 100644 --- a/cmake.deps/deps.txt +++ b/cmake.deps/deps.txt @@ -51,10 +51,6 @@ TREESITTER_VIMDOC_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v3.0. TREESITTER_VIMDOC_SHA256 a639bf92bf57bfa1cdc90ca16af27bfaf26a9779064776dd4be34c1ef1453f6c TREESITTER_QUERY_URL https://github.com/tree-sitter-grammars/tree-sitter-query/archive/v0.4.0.tar.gz TREESITTER_QUERY_SHA256 d3a423ab66dc62b2969625e280116678a8a22582b5ff087795222108db2f6a6e -TREESITTER_PYTHON_URL https://github.com/tree-sitter/tree-sitter-python/archive/v0.21.0.tar.gz -TREESITTER_PYTHON_SHA256 720304a603271fa89e4430a14d6a81a023d6d7d1171b1533e49c0ab44f1e1c13 -TREESITTER_BASH_URL https://github.com/tree-sitter/tree-sitter-bash/archive/v0.21.0.tar.gz -TREESITTER_BASH_SHA256 f0515efda839cfede851adb24ac154227fbc0dfb60c6c11595ecfa9087d43ceb TREESITTER_MARKDOWN_URL https://github.com/MDeiml/tree-sitter-markdown/archive/v0.2.3.tar.gz TREESITTER_MARKDOWN_SHA256 4909d6023643f1afc3ab219585d4035b7403f3a17849782ab803c5f73c8a31d5 TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.22.6.tar.gz diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 6889ce32fd..f4c1ade5da 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -349,8 +349,8 @@ The following new features were added. |default-autocmds| • Treesitter: - • Bundled parsers and queries (highlight, folds) for Markdown, Python, and - Bash. + • Bundled parsers and queries (highlight, folds) for Markdown (used for LSP + hover). • |:InspectTree| shows root nodes. • |:InspectTree| now supports |folding|. • |:InspectTree| shows node ranges in 0-based instead of 1-based indexing. diff --git a/runtime/queries/bash/folds.scm b/runtime/queries/bash/folds.scm deleted file mode 100644 index 766dbe598b..0000000000 --- a/runtime/queries/bash/folds.scm +++ /dev/null @@ -1,9 +0,0 @@ -[ - (function_definition) - (if_statement) - (case_statement) - (for_statement) - (while_statement) - (c_style_for_statement) - (heredoc_redirect) -] @fold diff --git a/runtime/queries/bash/highlights.scm b/runtime/queries/bash/highlights.scm deleted file mode 100644 index feb0e038ea..0000000000 --- a/runtime/queries/bash/highlights.scm +++ /dev/null @@ -1,232 +0,0 @@ -[ - "(" - ")" - "{" - "}" - "[" - "]" - "[[" - "]]" - "((" - "))" -] @punctuation.bracket - -[ - ";" - ";;" - ";&" - ";;&" - "&" -] @punctuation.delimiter - -[ - ">" - ">>" - "<" - "<<" - "&&" - "|" - "|&" - "||" - "=" - "+=" - "=~" - "==" - "!=" - "&>" - "&>>" - "<&" - ">&" - ">|" - "<&-" - ">&-" - "<<-" - "<<<" - ".." - "!" -] @operator - -; Do *not* spell check strings since they typically have some sort of -; interpolation in them, or, are typically used for things like filenames, URLs, -; flags and file content. -[ - (string) - (raw_string) - (ansi_c_string) - (heredoc_body) -] @string - -[ - (heredoc_start) - (heredoc_end) -] @label - -(variable_assignment - (word) @string) - -(command - argument: "$" @string) ; bare dollar - -(concatenation - (word) @string) - -[ - "if" - "then" - "else" - "elif" - "fi" - "case" - "in" - "esac" -] @keyword.conditional - -[ - "for" - "do" - "done" - "select" - "until" - "while" -] @keyword.repeat - -[ - "declare" - "typeset" - "export" - "readonly" - "local" - "unset" - "unsetenv" -] @keyword - -"function" @keyword.function - -(special_variable_name) @constant - -; trap -l -((word) @constant.builtin - (#any-of? @constant.builtin - "SIGHUP" "SIGINT" "SIGQUIT" "SIGILL" "SIGTRAP" "SIGABRT" "SIGBUS" "SIGFPE" "SIGKILL" "SIGUSR1" - "SIGSEGV" "SIGUSR2" "SIGPIPE" "SIGALRM" "SIGTERM" "SIGSTKFLT" "SIGCHLD" "SIGCONT" "SIGSTOP" - "SIGTSTP" "SIGTTIN" "SIGTTOU" "SIGURG" "SIGXCPU" "SIGXFSZ" "SIGVTALRM" "SIGPROF" "SIGWINCH" - "SIGIO" "SIGPWR" "SIGSYS" "SIGRTMIN" "SIGRTMIN+1" "SIGRTMIN+2" "SIGRTMIN+3" "SIGRTMIN+4" - "SIGRTMIN+5" "SIGRTMIN+6" "SIGRTMIN+7" "SIGRTMIN+8" "SIGRTMIN+9" "SIGRTMIN+10" "SIGRTMIN+11" - "SIGRTMIN+12" "SIGRTMIN+13" "SIGRTMIN+14" "SIGRTMIN+15" "SIGRTMAX-14" "SIGRTMAX-13" - "SIGRTMAX-12" "SIGRTMAX-11" "SIGRTMAX-10" "SIGRTMAX-9" "SIGRTMAX-8" "SIGRTMAX-7" "SIGRTMAX-6" - "SIGRTMAX-5" "SIGRTMAX-4" "SIGRTMAX-3" "SIGRTMAX-2" "SIGRTMAX-1" "SIGRTMAX")) - -((word) @boolean - (#any-of? @boolean "true" "false")) - -(comment) @comment @spell - -(test_operator) @operator - -(command_substitution - "$(" @punctuation.special - ")" @punctuation.special) - -(process_substitution - [ - "<(" - ">(" - ] @punctuation.special - ")" @punctuation.special) - -(arithmetic_expansion - [ - "$((" - "((" - ] @punctuation.special - "))" @punctuation.special) - -(arithmetic_expansion - "," @punctuation.delimiter) - -(ternary_expression - [ - "?" - ":" - ] @keyword.conditional.ternary) - -(binary_expression - operator: _ @operator) - -(unary_expression - operator: _ @operator) - -(postfix_expression - operator: _ @operator) - -(function_definition - name: (word) @function) - -(command_name - (word) @function.call) - -(command_name - (word) @function.builtin - (#any-of? @function.builtin - "alias" "bg" "bind" "break" "builtin" "caller" "cd" "command" "compgen" "complete" "compopt" - "continue" "coproc" "dirs" "disown" "echo" "enable" "eval" "exec" "exit" "fc" "fg" "getopts" - "hash" "help" "history" "jobs" "kill" "let" "logout" "mapfile" "popd" "printf" "pushd" "pwd" - "read" "readarray" "return" "set" "shift" "shopt" "source" "suspend" "test" "time" "times" - "trap" "type" "typeset" "ulimit" "umask" "unalias" "wait")) - -(command - argument: [ - (word) @variable.parameter - (concatenation - (word) @variable.parameter) - ]) - -(number) @number - -((word) @number - (#lua-match? @number "^[0-9]+$")) - -(file_redirect - destination: (word) @variable.parameter) - -(file_descriptor) @operator - -(simple_expansion - "$" @punctuation.special) @none - -(expansion - "${" @punctuation.special - "}" @punctuation.special) @none - -(expansion - operator: _ @punctuation.special) - -(expansion - "@" - . - operator: _ @character.special) - -((expansion - (subscript - index: (word) @character.special)) - (#any-of? @character.special "@" "*")) - -"``" @punctuation.special - -(variable_name) @variable - -((variable_name) @constant - (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) - -(case_item - value: (word) @variable.parameter) - -[ - (regex) - (extglob_pattern) -] @string.regexp - -((program - . - (comment) @keyword.directive @nospell) - (#lua-match? @keyword.directive "^#!/")) diff --git a/runtime/queries/bash/injections.scm b/runtime/queries/bash/injections.scm deleted file mode 100644 index 427b414958..0000000000 --- a/runtime/queries/bash/injections.scm +++ /dev/null @@ -1,3 +0,0 @@ -(heredoc_redirect - (heredoc_body) @injection.content - (heredoc_end) @injection.language) diff --git a/runtime/queries/python/folds.scm b/runtime/queries/python/folds.scm deleted file mode 100644 index ecb9352d78..0000000000 --- a/runtime/queries/python/folds.scm +++ /dev/null @@ -1,28 +0,0 @@ -[ - (function_definition) - (class_definition) - (while_statement) - (for_statement) - (if_statement) - (with_statement) - (try_statement) - (match_statement) - (import_from_statement) - (parameters) - (argument_list) - (parenthesized_expression) - (generator_expression) - (list_comprehension) - (set_comprehension) - (dictionary_comprehension) - (tuple) - (list) - (set) - (dictionary) - (string) -] @fold - -[ - (import_statement) - (import_from_statement) -]+ @fold diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm deleted file mode 100644 index 5e5a2a88de..0000000000 --- a/runtime/queries/python/highlights.scm +++ /dev/null @@ -1,457 +0,0 @@ -; From tree-sitter-python licensed under MIT License -; Copyright (c) 2016 Max Brunsfeld -; Variables -(identifier) @variable - -; Reset highlighting in f-string interpolations -(interpolation) @none - -; Identifier naming conventions -((identifier) @type - (#lua-match? @type "^[A-Z].*[a-z]")) - -((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) - -((identifier) @constant.builtin - (#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) - -((identifier) @constant.builtin - (#any-of? @constant.builtin - ; https://docs.python.org/3/library/constants.html - "NotImplemented" "Ellipsis" "quit" "exit" "copyright" "credits" "license")) - -"_" @constant.builtin ; match wildcard - -((attribute - attribute: (identifier) @variable.member) - (#lua-match? @variable.member "^[%l_].*$")) - -((assignment - left: (identifier) @type.definition - (type - (identifier) @_annotation)) - (#eq? @_annotation "TypeAlias")) - -((assignment - left: (identifier) @type.definition - right: (call - function: (identifier) @_func)) - (#any-of? @_func "TypeVar" "NewType")) - -; Function calls -(call - function: (identifier) @function.call) - -(call - function: (attribute - attribute: (identifier) @function.method.call)) - -((call - function: (identifier) @constructor) - (#lua-match? @constructor "^%u")) - -((call - function: (attribute - attribute: (identifier) @constructor)) - (#lua-match? @constructor "^%u")) - -; Decorators -((decorator - "@" @attribute) - (#set! "priority" 101)) - -(decorator - (identifier) @attribute) - -(decorator - (attribute - attribute: (identifier) @attribute)) - -(decorator - (call - (identifier) @attribute)) - -(decorator - (call - (attribute - attribute: (identifier) @attribute))) - -((decorator - (identifier) @attribute.builtin) - (#any-of? @attribute.builtin "classmethod" "property" "staticmethod")) - -; Builtin functions -((call - function: (identifier) @function.builtin) - (#any-of? @function.builtin - "abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" - "classmethod" "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" - "filter" "float" "format" "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" - "input" "int" "isinstance" "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview" - "min" "next" "object" "oct" "open" "ord" "pow" "print" "property" "range" "repr" "reversed" - "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" "sum" "super" "tuple" "type" - "vars" "zip" "__import__")) - -; Function definitions -(function_definition - name: (identifier) @function) - -(type - (identifier) @type) - -(type - (subscript - (identifier) @type)) ; type subscript: Tuple[int] - -((call - function: (identifier) @_isinstance - arguments: (argument_list - (_) - (identifier) @type)) - (#eq? @_isinstance "isinstance")) - -; Normal parameters -(parameters - (identifier) @variable.parameter) - -; Lambda parameters -(lambda_parameters - (identifier) @variable.parameter) - -(lambda_parameters - (tuple_pattern - (identifier) @variable.parameter)) - -; Default parameters -(keyword_argument - name: (identifier) @variable.parameter) - -; Naming parameters on call-site -(default_parameter - name: (identifier) @variable.parameter) - -(typed_parameter - (identifier) @variable.parameter) - -(typed_default_parameter - name: (identifier) @variable.parameter) - -; Variadic parameters *args, **kwargs -(parameters - (list_splat_pattern ; *args - (identifier) @variable.parameter)) - -(parameters - (dictionary_splat_pattern ; **kwargs - (identifier) @variable.parameter)) - -; Typed variadic parameters -(parameters - (typed_parameter - (list_splat_pattern ; *args: type - (identifier) @variable.parameter))) - -(parameters - (typed_parameter - (dictionary_splat_pattern ; *kwargs: type - (identifier) @variable.parameter))) - -; Lambda parameters -(lambda_parameters - (list_splat_pattern - (identifier) @variable.parameter)) - -(lambda_parameters - (dictionary_splat_pattern - (identifier) @variable.parameter)) - -; Literals -(none) @constant.builtin - -[ - (true) - (false) -] @boolean - -((identifier) @variable.builtin - (#eq? @variable.builtin "self")) - -((identifier) @variable.builtin - (#eq? @variable.builtin "cls")) - -(integer) @number - -(float) @number.float - -(comment) @comment @spell - -((module - . - (comment) @keyword.directive @nospell) - (#lua-match? @keyword.directive "^#!/")) - -(string) @string - -[ - (escape_sequence) - (escape_interpolation) -] @string.escape - -; doc-strings -(module - . - (comment)* - . - (expression_statement - (string) @string.documentation)) - -(class_definition - body: (block - . - (expression_statement - (string) @string.documentation))) - -(function_definition - body: (block - . - (expression_statement - (string) @string.documentation))) - -(module - . - (comment)* - . - (expression_statement - (string - (string_content) @spell))) - -(class_definition - body: (block - . - (expression_statement - (string - (string_content) @spell)))) - -(function_definition - body: (block - . - (expression_statement - (string - (string_content) @spell)))) - -; Tokens -[ - "-" - "-=" - ":=" - "!=" - "*" - "**" - "**=" - "*=" - "/" - "//" - "//=" - "/=" - "&" - "&=" - "%" - "%=" - "^" - "^=" - "+" - "+=" - "<" - "<<" - "<<=" - "<=" - "<>" - "=" - "==" - ">" - ">=" - ">>" - ">>=" - "@" - "@=" - "|" - "|=" - "~" - "->" -] @operator - -; Keywords -[ - "and" - "in" - "is" - "not" - "or" - "is not" - "not in" - "del" -] @keyword.operator - -[ - "def" - "lambda" -] @keyword.function - -[ - "assert" - "exec" - "global" - "nonlocal" - "pass" - "print" - "with" - "as" -] @keyword - -[ - "type" - "class" -] @keyword.type - -[ - "async" - "await" -] @keyword.coroutine - -[ - "return" - "yield" -] @keyword.return - -(yield - "from" @keyword.return) - -(future_import_statement - "from" @keyword.import - "__future__" @constant.builtin) - -(import_from_statement - "from" @keyword.import) - -"import" @keyword.import - -(aliased_import - "as" @keyword.import) - -[ - "if" - "elif" - "else" - "match" - "case" -] @keyword.conditional - -[ - "for" - "while" - "break" - "continue" -] @keyword.repeat - -[ - "try" - "except" - "except*" - "raise" - "finally" -] @keyword.exception - -(raise_statement - "from" @keyword.exception) - -(try_statement - (else_clause - "else" @keyword.exception)) - -[ - "(" - ")" - "[" - "]" - "{" - "}" -] @punctuation.bracket - -(interpolation - "{" @punctuation.special - "}" @punctuation.special) - -(type_conversion) @function.macro - -[ - "," - "." - ":" - ";" - (ellipsis) -] @punctuation.delimiter - -; Class definitions -(class_definition - name: (identifier) @type) - -(class_definition - body: (block - (function_definition - name: (identifier) @function.method))) - -(class_definition - superclasses: (argument_list - (identifier) @type)) - -((class_definition - body: (block - (expression_statement - (assignment - left: (identifier) @variable.member)))) - (#lua-match? @variable.member "^[%l_].*$")) - -((class_definition - body: (block - (expression_statement - (assignment - left: (_ - (identifier) @variable.member))))) - (#lua-match? @variable.member "^[%l_].*$")) - -((class_definition - (block - (function_definition - name: (identifier) @constructor))) - (#any-of? @constructor "__new__" "__init__")) - -((identifier) @type.builtin - (#any-of? @type.builtin - ; https://docs.python.org/3/library/exceptions.html - "BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError" - "AttributeError" "EOFError" "FloatingPointError" "GeneratorExit" "ImportError" - "ModuleNotFoundError" "IndexError" "KeyError" "KeyboardInterrupt" "MemoryError" "NameError" - "NotImplementedError" "OSError" "OverflowError" "RecursionError" "ReferenceError" "RuntimeError" - "StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" "SystemError" - "SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError" - "UnicodeDecodeError" "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError" - "IOError" "WindowsError" "BlockingIOError" "ChildProcessError" "ConnectionError" - "BrokenPipeError" "ConnectionAbortedError" "ConnectionRefusedError" "ConnectionResetError" - "FileExistsError" "FileNotFoundError" "InterruptedError" "IsADirectoryError" - "NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning" - "UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning" - "FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning" - ; https://docs.python.org/3/library/stdtypes.html - "bool" "int" "float" "complex" "list" "tuple" "range" "str" "bytes" "bytearray" "memoryview" - "set" "frozenset" "dict" "type" "object")) - -; Regex from the `re` module -(call - function: (attribute - object: (identifier) @_re) - arguments: (argument_list - . - (string - (string_content) @string.regexp)) - (#eq? @_re "re")) diff --git a/test/functional/treesitter/fold_spec.lua b/test/functional/treesitter/fold_spec.lua index a7f278aa01..278ba17be0 100644 --- a/test/functional/treesitter/fold_spec.lua +++ b/test/functional/treesitter/fold_spec.lua @@ -408,15 +408,15 @@ t3]]) it('handles quantified patterns', function() insert([[ -import hello -import hello -import hello -import hello -import hello -import hello]]) +-- hello +-- hello +-- hello +-- hello +-- hello +-- hello]]) - exec_lua([[vim.treesitter.query.set('python', 'folds', '(import_statement)+ @fold')]]) - parse('python') + exec_lua([[vim.treesitter.query.set('lua', 'folds', '(comment)+ @fold')]]) + parse('lua') eq({ [1] = '>1',