aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-02-21 17:09:18 +0000
committerGitHub <noreply@github.com>2023-02-21 17:09:18 +0000
commit8714a4009c0f0be0bb27a6b3eb486eeb3d9f3049 (patch)
treeba930952af970a189e735f3b6f001d92a0fff72f /runtime/doc
parent344a1ee8e6b7d78120f8393d1babfd285e866334 (diff)
downloadrneovim-8714a4009c0f0be0bb27a6b3eb486eeb3d9f3049.tar.gz
rneovim-8714a4009c0f0be0bb27a6b3eb486eeb3d9f3049.tar.bz2
rneovim-8714a4009c0f0be0bb27a6b3eb486eeb3d9f3049.zip
feat(treesitter): add filetype -> lang API
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.
Diffstat (limited to 'runtime/doc')
-rw-r--r--runtime/doc/news.txt5
-rw-r--r--runtime/doc/treesitter.txt50
2 files changed, 39 insertions, 16 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index ae21bc47ca..8b41f2d104 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -164,6 +164,9 @@ The following new APIs or features were added.
• |vim.treesitter.query.get_node_text()| now accepts a `metadata` option for
writing custom directives using |vim.treesitter.query.add_directive()|.
+• |vim.treesitter.language.add()| as a new replacement for
+ `vim.treesitter.language.require_language`.
+
==============================================================================
CHANGED FEATURES *news-changes*
@@ -202,6 +205,8 @@ DEPRECATIONS *news-deprecations*
The following functions are now deprecated and will be removed in the next
release.
+• `vim.treesitter.language.require_language()` has been deprecated in favour
+ of |vim.treesitter.language.add()|.
vim:tw=78:ts=8:sw=2:et:ft=help:norl:
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
index d4799053f7..e35e145301 100644
--- a/runtime/doc/treesitter.txt
+++ b/runtime/doc/treesitter.txt
@@ -666,6 +666,36 @@ stop({bufnr}) *vim.treesitter.stop()*
==============================================================================
Lua module: vim.treesitter.language *lua-treesitter-language*
+add({lang}, {opts}) *vim.treesitter.language.add()*
+ Asserts that a parser for the language {lang} is installed.
+
+ Parsers are searched in the `parser` runtime directory, or the provided
+ {path}
+
+ Parameters: ~
+ • {lang} (string) Language the parser should parse (alphanumerical and
+ `_` only)
+ • {opts} (table|nil) Options:
+ • filetype (string|string[]) Filetype(s) that lang can be
+ parsed with. Note this is not strictly the same as lang
+ since a single lang can parse multiple filetypes. Defaults
+ to lang.
+ • path (string|nil) Optional path the parser is located at
+ • symbol_name (string|nil) Internal symbol name for the
+ language to load
+ • silent (boolean|nil) Don't throw an error if language not
+ found
+
+ Return: ~
+ (boolean) If the specified language is installed
+
+get_lang({filetype}) *vim.treesitter.language.get_lang()*
+ Parameters: ~
+ • {filetype} (string)
+
+ Return: ~
+ (string|nil)
+
inspect_language({lang}) *vim.treesitter.language.inspect_language()*
Inspects the provided language.
@@ -678,24 +708,12 @@ inspect_language({lang}) *vim.treesitter.language.inspect_language()*
Return: ~
(table)
- *vim.treesitter.language.require_language()*
-require_language({lang}, {path}, {silent}, {symbol_name})
- Asserts that a parser for the language {lang} is installed.
-
- Parsers are searched in the `parser` runtime directory, or the provided
- {path}
+register({lang}, {filetype}) *vim.treesitter.language.register()*
+ Register a lang to be used for a filetype (or list of filetypes).
Parameters: ~
- • {lang} (string) Language the parser should parse
- (alphanumerical and `_` only)
- • {path} (string|nil) Optional path the parser is located at
- • {silent} (boolean|nil) Don't throw an error if language not
- found
- • {symbol_name} (string|nil) Internal symbol name for the language to
- load
-
- Return: ~
- (boolean) If the specified language is installed
+ • {lang} (string) Language to register
+ • {filetype} string|string[] Filetype(s) to associate with lang
==============================================================================