aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2024-09-15 14:19:08 +0200
committerChristian Clason <c.clason@uni-graz.at>2024-09-29 15:27:16 +0200
commit99e0facf3a001608287ec6db69b01c77443c7b9d (patch)
tree2416eb7ab7dbac974fa095536add9fe18dd0a25c /runtime/doc
parent041d98fe8d892a81ed659c32be5360d4f80e7d18 (diff)
downloadrneovim-99e0facf3a001608287ec6db69b01c77443c7b9d.tar.gz
rneovim-99e0facf3a001608287ec6db69b01c77443c7b9d.tar.bz2
rneovim-99e0facf3a001608287ec6db69b01c77443c7b9d.zip
feat(treesitter)!: use return values in `language.add()`
Problem: No clear way to check whether parsers are available for a given language. Solution: Make `language.add()` return `true` if a parser was successfully added and `nil` otherwise. Use explicit `assert` instead of relying on thrown errors.
Diffstat (limited to 'runtime/doc')
-rw-r--r--runtime/doc/news.txt4
-rw-r--r--runtime/doc/treesitter.txt11
2 files changed, 12 insertions, 3 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 77345e6b19..6a29efdd9c 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -97,12 +97,12 @@ TREESITTER
capture IDs to a list of nodes that need to be iterated over. For
backwards compatibility, an option `all=false` (only return the last
matching node) is provided that will be removed in a future release.
-
• |vim.treesitter.language.get_filetypes()| always includes the {language}
argument in addition to explicitly registered filetypes.
-
• |vim.treesitter.language.get_lang()| falls back to the {filetype} argument
if no languages are explicitly registered.
+• |vim.treesitter.language.add()| returns `true` if a parser was loaded
+ successfully and `nil,errmsg` otherwise instead of throwing an error.
TUI
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
index e0f7536712..a83b80d9ad 100644
--- a/runtime/doc/treesitter.txt
+++ b/runtime/doc/treesitter.txt
@@ -964,7 +964,12 @@ add({lang}, {opts}) *vim.treesitter.language.add()*
Load parser with name {lang}
Parsers are searched in the `parser` runtime directory, or the provided
- {path}
+ {path}. Can be used to check for available parsers before enabling
+ treesitter features, e.g., >lua
+ if vim.treesitter.language.add('markdown') then
+ vim.treesitter.start(bufnr, 'markdown')
+ end
+<
Parameters: ~
• {lang} (`string`) Name of the parser (alphanumerical and `_` only)
@@ -973,6 +978,10 @@ add({lang}, {opts}) *vim.treesitter.language.add()*
• {symbol_name}? (`string`) Internal symbol name for the
language to load
+ Return (multiple): ~
+ (`boolean?`) True if parser is loaded
+ (`string?`) Error if parser cannot be loaded
+
get_filetypes({lang}) *vim.treesitter.language.get_filetypes()*
Returns the filetypes for which a parser named {lang} is used.