aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/query.lua
Commit message (Collapse)AuthorAge
* feat(lua): add vim.func._memoizeLewis Russell2023-09-20
| | | | | | | | | | | | | | | Memoizes a function, using a custom function to hash the arguments. Private for now until: - There are other places in the codebase that could benefit from this (e.g. LSP), but might require other changes to accommodate. - Invalidation of the cache needs to be controllable. Using weak tables is an acceptable invalidation policy, but it shouldn't be the only one. - I don't think the story around `hash_fn` is completely thought out. We may be able to have a good default hash_fn by hashing each argument, so basically a better 'concat'.
* docs: misc #24561Justin M. Keyes2023-09-20
| | | | fix #24699 fix #25253
* feat(treesitter): add lang parameter to the query editor (#25181)Maria José Solano2023-09-16
|
* fix(treesitter): fix trim predicateLewis Russell2023-09-16
|
* perf(treesitter): do not scan past given line for predicate matchL Lllvvuu2023-09-16
| | | | | | | | | | | | | | | Problem --- If a highlighter query returns a significant number of predicate non-matches, the highlighter will scan well past the end of the window. Solution --- In the iterator returned from `iter_captures`, accept an optional parameter `end_line`. If no parameter provided, the behavior is unchanged, hence this is a non-invasive tweak. Fixes: #25113 nvim-treesitter/nvim-treesitter#5057
* refactor(treesitter): rename "preview" => "edit" #25161Maria José Solano2023-09-15
| | | | | | "Edit" more closely describes the generic application than "Preview", though the buffer contents don't (yet) map to an actual file on disk. https://github.com/neovim/neovim/pull/24703#discussion_r1321719133
* docs: replace <pre> with ``` (#25136)Gregory Anders2023-09-14
|
* feat(treesitter)!: incremental injection parsingLewis Russell2023-08-12
| | | | | | | | | | | | | | | | | | | | | Problem: Treesitter highlighting is slow for large files with lots of injections. Solution: Only parse injections we are going to render during a redraw cycle. --- - `LanguageTree:parse()` will no longer parse injections by default and now requires an explicit range argument to be passed. - `TSHighlighter` now parses injections incrementally during on_win callbacks for the line range being rendered. - Plugins which require certain injections to be parsed must run `parser:parse({ start_row, end_row })` before using the tree.
* feat(treesitter): add injection language fallback (#24659)Christian Clason2023-08-11
| | | | | | | | | | | | * feat(treesitter): add injection language fallback Problem: injection languages are often specified via aliases (e.g., filetype or in upper case), requiring custom directives. Solution: include lookup logic (try as parser name, then filetype, then lowercase) in LanguageTree itself and remove `#inject-language` directive. Co-authored-by: Lewis Russell <me@lewisr.dev>
* fix(lua): improve annotations for stricter luals diagnostics (#24609)Christian Clason2023-08-09
| | | | | | | | | | | | | | | Problem: luals returns stricter diagnostics with bundled luarc.json Solution: Improve some function and type annotations: * use recognized uv.* types * disable diagnostic for global `vim` in shared.lua * docs: don't start comment lines with taglink (otherwise LuaLS will interpret it as a type) * add type alias for lpeg pattern * fix return annotation for `vim.secure.trust` * rename local Range object in vim.version (shadows `Range` in vim.treesitter) * fix some "missing fields" warnings * add missing required fields for test functions in eval.lua * rename lsp meta files for consistency
* docs(lua): more improvements (#24387)Lewis Russell2023-07-18
| | | | | | | | | | | | | | | | | * docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes <justinkz@gmail.com> --------- Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* perf(treesitter): cache fold query (#24222)Jaehwang Jung2023-07-02
| | | | | | | | | | | | | | | | | | | | | perf(treesitter): cache vim.treesitter.query.get Problem: vim.treesitter.query.get searches and reads query files every time it's called, if user hasn't overridden the query. So this can incur slowdown when called frequently. This can happen when using treesitter foldexpr. For example, when using `:h :range!` in markdown file to format fenced codeblock, on_changedtree in _fold.lua is triggered many times despite that the tree doesn't have syntactic changes (might be a bug in LanguageTree). (Incidentally, the resulting fold is incorrect due to a bug in `:h range!`.) on_changedtree calls vim.treesitter.query.get for each tree changes. In addition, it may request folds queries for injected languages without fold queries, such as markdown_inline. Solution: * Cache the result of vim.treesitter.query.get. * If query file was not found, fail quickly at later calls.
* feat(treesitter): bundle markdown parser and queries (#22481)Christian Clason2023-07-01
| | | | | | | * bundle split Markdown parser from https://github.com/MDeiml/tree-sitter-markdown * add queries from https://github.com/nvim-treesitter/nvim-treesitter/tree/main * upstream `#trim!` and `#inject-language!` directives Co-authored-by: dundargoc <gocdundar@gmail.com>
* fix(treesitter): update c queriesChristian Clason2023-05-15
|
* docs: small fixesdundargoc2023-05-13
| | | | | | | | | Co-authored-by: Christian Clason <c.clason@uni-graz.at> Co-authored-by: Gregory Anders <greg@gpanders.com> Co-authored-by: HiPhish <hiphish@posteo.de> Co-authored-by: Julio B <julio.bacel@gmail.com> Co-authored-by: T727 <74924917+T-727@users.noreply.github.com> Co-authored-by: camoz <camoz@users.noreply.github.com> Co-authored-by: champignoom <66909116+champignoom@users.noreply.github.com>
* feat(treesitter): add support for setting query depthsLewis Russell2023-05-11
|
* feat(treesitter): upstream query omnifunc from playground (#23394)Christian Clason2023-04-30
| | | and set by default in `ftplugin/query.lua`
* feat(treesitter): add query_linter from nvim-treesitter/playground (#22784)Stephan Seitz2023-04-29
| | | | Co-authored-by: clason <clason@users.noreply.github.com> Co-authored-by: lewis6991 <lewis6991@users.noreply.github.com>
* fix(treesitter): Use the correct replacement args for #gsub! directive (#23015)Scott Ming2023-04-11
| | | fix(treesitter): use the correct replacement args for #gsub! directive
* refactor: rename local API alias from a to apiLewis Russell2023-04-05
| | | | | | | | Problem: Codebase inconsistently binds vim.api onto a or api. Solution: Use api everywhere. a as an identifier is too short to have at the module level.
* fix(treesitter): add missing deprecateLewis Russell2023-03-24
|
* feat(treesitter)!: deprecate top level indexes to modules (#22761)Lewis Russell2023-03-24
| | | | | | | | | | | | | | | | | The following top level Treesitter functions have been moved: - vim.treesitter.inspect_language() -> vim.treesitter.language.inspect() - vim.treesitter.get_query_files() -> vim.treesitter.query.get_files() - vim.treesitter.set_query() -> vim.treesitter.query.set() - vim.treesitter.query.set_query() -> vim.treesitter.query.set() - vim.treesitter.get_query() -> vim.treesitter.query.get() - vim.treesitter.query.get_query() -> vim.treesitter.query.get() - vim.treesitter.parse_query() -> vim.treesitter.query.parse() - vim.treesitter.query.parse_query() -> vim.treesitter.query.parse() - vim.treesitter.add_predicate() -> vim.treesitter.query.add_predicate() - vim.treesitter.add_directive() -> vim.treesitter.query.add_directive() - vim.treesitter.list_predicates() -> vim.treesitter.query.list_predicates() - vim.treesitter.list_directives() -> vim.treesitter.query.list_directives() - vim.treesitter.query.get_range() -> vim.treesitter.get_range() - vim.treesitter.query.get_node_text() -> vim.treesitter.get_node_text()
* refactor(treesitter): add Range type aliase for Range4|Range6Lewis Russell2023-03-11
|
* feat(treesitter)!: consolidate query util functionsLewis Russell2023-03-10
| | | | | | - And address more type errors. - Removed the `concat` option from `get_node_text` since it was applied inconsistently and made typing awkward.
* refactor(treesitter): use byte ranges from treesitter (#22589)Lewis Russell2023-03-09
|
* Revert "refactor(treesitter): delegate region calculation to treesitter" ↵Lewis Russell2023-03-08
| | | | | | | (#22575) Revert "refactor(treesitter): delegate region calculation to treesitter (#22553)" This reverts commit 276b647fdba07bf1762d8dd371c4b655b8a418df.
* refactor(treesitter): delegate region calculation to treesitter (#22553)Lewis Russell2023-03-08
|
* feat(treesitter): use upstream format for injection queriesLewis Russell2023-03-08
|
* docs(treesitter): number → integer (#22513)Jaehwang Jung2023-03-04
|
* docs: fix vim.treesitter tagsJustin M. Keyes2023-03-03
| | | | | | | | | Problem: Help tags like vim.treesitter.language.add() are confusing because `vim.treesitter.language` is (thankfully) not a user-facing module. Solution: Ignore the "fstem" when generating "treesitter" tags.
* perf(treesitter): smarter languagetree invalidationLewis Russell2023-02-23
| | | | | | | | | | | | | | Problem: Treesitter injections are slow because all injected trees are invalidated on every change. Solution: Implement smarter invalidation to avoid reparsing injected regions. - In on_bytes, try and update self._regions as best we can. This PR just offsets any regions after the change. - Add valid flags for each region in self._regions. - Call on_bytes recursively for all children. - We still need to run the query every time for the top level tree. I don't know how to avoid this. However, if the new injection ranges don't change, then we re-use the old trees and avoid reparsing children. This should result in roughly a 2-3x reduction in tree parsing when the comment injections are enabled.
* docs: fix more treesitter parsing errorsChristian Clason2023-02-23
|
* feat(treesitter): add filetype -> lang APILewis Russell2023-02-21
| | | | | | | | | | | | | | | | | | Problem: vim.treesitter does not know how to map a specific filetype to a parser. This creates problems since in a few places (including in vim.treesitter itself), the filetype is incorrectly used in place of lang. Solution: Add an API to enable this: - Add vim.treesitter.language.add() as a replacement for vim.treesitter.language.require_language(). - Optional arguments are now passed via an opts table. - Also takes a filetype (or list of filetypes) so we can keep track of what filetypes are associated with which langs. - Deprecated vim.treesitter.language.require_language(). - Add vim.treesitter.language.get_lang() which returns the associated lang for a given filetype. - Add vim.treesitter.language.register() to associate filetypes to a lang without loading the parser.
* fix(treesitter): make params optionalLewis Russell2023-02-15
|
* feat(treesitter): respect metadata[id].range for offset!figsoda2023-02-04
|
* feat(treesitter): add metadata option for get_node_textfigsoda2023-02-04
|
* feat(treesitter): allow capture text to be transformedfigsoda2023-02-04
| | | | Co-authored-by: Lewis Russell <lewis6991@gmail.com>
* fix(treesitter): fix most diagnosticsLewis Russell2023-02-04
|
* docs: treesitter.add_directive, add_predicate #21206Ching Pei Yang2023-01-16
|
* docs(gen): support language annotation in docstringsChristian Clason2022-12-02
|
* fix(query): fix unnatural order for inherits in treesitter queries (#20298)Sergey Berezhnoy2022-09-29
| | | close #20297
* fix(docs): invalid :help links #20345Justin M. Keyes2022-09-25
| | | | | Fix those naughty single quotes. closes #20159
* docs(treesitter): clean up and update treesitter.txt (#20142)Christian Clason2022-09-14
| | | | | * add type annotations to code * clean up and expand static documentation * consistent use of tags for static and generated docs
* fix(treesitter): prevent endless loop on self-inheritenceThomas Vigouroux2022-09-11
| | | | Fixes #20139
* fix(treesitter): use the right loading order for base queries (#20117)bfredl2022-09-08
| | | | | Use the first, not last, query for a language on runtimepath. Typically, this implies that a user query will override a site plugin query, which will override a bundled runtime query.
* feat(treesitter)!: do not merge queries by default (#20105)Thomas Vigouroux2022-09-08
| | | | | | | | | | Problem: Treesitter queries for a given language in runtime were merged together, leading to errors if they targeted different parser versions (e.g., bundled viml queries and those shipped by nvim-treesitter). Solution: Runtime queries now work as follows: * The last query in the rtp without `; extends` in the header will be used as the base query * All queries (without a specific order) with `; extends` are concatenated with the base query BREAKING CHANGE: queries need to be updated if they are meant to extend other queries
* Use weak tables in tree-sitter code (#17117)Thomas Vigouroux2022-09-07
| | | | | | feat(treesitter): use weak tables when possible Also add the defaulttable function to create a table whose values are created when a key is missing.
* feat(treesitter): add opts.concat to query.get_text_nodeQuentin Rasmont2022-08-25
| | | | | | | As part of the upstream of utility functions from nvim-treesitter, this option when set to false allows to return a table (downstream behavior). Effectively making the switch from the downstream to the upstream function much easier.
* fix(treesitter): don't error when node argument of predicate is nil (#19355)Stephan Seitz2022-07-14
| | | | | | When the node mentioned in a predicate is not required for the query then predicates putting restrictions on that node shouldn't run. Fixes https://github.com/nvim-treesitter/nvim-treesitter/issues/2600
* fix(treesitter): offset directive associates range with capture (#18276)Lewis Russell2022-05-28
| | | | | | | | | Previously the `offset!` directive populated the metadata in such a way that the new range could be attributed to a specific capture. #14046 made it so the directive simply stored just the new range in the metadata and information about what capture the range is based from is lost. This change reverts that whilst also correcting the docs.