From 31c4ed26bc278282898123ad21bb6fead401fd6f Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 11 Aug 2023 17:05:17 +0200 Subject: feat(treesitter): add injection language fallback (#24659) * 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 --- runtime/doc/news.txt | 18 ++++++++++-------- runtime/doc/treesitter.txt | 14 +------------- 2 files changed, 11 insertions(+), 21 deletions(-) (limited to 'runtime/doc') diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 713569e1ad..a1981d5b7f 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -77,15 +77,9 @@ The following new APIs and features were added. • Added |vim.keycode()| for translating keycodes in a string. -• Added |vim.treesitter.query.omnifunc()| for treesitter query files (set by - default). - • |'smoothscroll'| option to scroll by screen line rather than by text line when |'wrap'| is set. -• |Query:iter_matches()| now has the ability to set the maximum start depth - for matches. - • Added inline virtual text support to |nvim_buf_set_extmark()|. • The terminal buffer now supports reflow (wrapped lines adapt when the buffer @@ -120,8 +114,16 @@ The following new APIs and features were added. `client.supports_method()`. It considers both the dynamic capabilities and static `server_capabilities`. -• Bundled treesitter parser and queries (highlight, folds) for Markdown, - Python, and Bash. +• Treesitter + • Bundled parsers and queries (highlight, folds) for Markdown, Python, and + Bash. + • Added |vim.treesitter.query.omnifunc()| for treesitter query files (set by + default). + • |Query:iter_matches()| now has the ability to set the maximum start depth + for matches. + • `@injection.language` now has smarter resolution and will now fallback to language aliases and/or attempt lower case variants of the text. + language via aliases (e.g., filetype) registered via + `vim.treesitter.language.register`. • |vim.ui.open()| opens URIs using the system default handler (macOS `open`, Windows `explorer`, Linux `xdg-open`, etc.) diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index 7c7be5f214..13c0bd024a 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -311,19 +311,7 @@ The following directives are built in: {capture_id} Example: >query - (#inject-language! @_lang) -< - `inject-language!` *treesitter-directive-inject-language!* - Set the injection language from the node text, interpreted first as a - language name, then (if a parser is not found) a filetype. Custom - aliases can be added via |vim.treesitter.language.register()|. This - will set a new `metadata[capture_id]['injection.language']`. - - Parameters: ~ - {capture_id} - - Example: >query - (#inject-language! @_lang) + (#trim! @fold) < Further directives can be added via |vim.treesitter.query.add_directive()|. Use |vim.treesitter.query.list_directives()| to list all available directives. -- cgit