aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorThomas Vigouroux <thomas.vigouroux@protonmail.com>2022-08-24 15:36:58 +0200
committerGitHub <noreply@github.com>2022-08-24 15:36:58 +0200
commit9be4bfc5f4951976131e5e99ecf05882f6767fb4 (patch)
treea546d16c24309b5e3e369151d5d871bfd9f4d6f2 /runtime
parentf1ea126a6eb1d9cae53eae3fedbfa51f90ee97b1 (diff)
parent3c1d70f20b5d5bad3bec121e589187d15f325a9b (diff)
downloadrneovim-9be4bfc5f4951976131e5e99ecf05882f6767fb4.tar.gz
rneovim-9be4bfc5f4951976131e5e99ecf05882f6767fb4.tar.bz2
rneovim-9be4bfc5f4951976131e5e99ecf05882f6767fb4.zip
Merge pull request #19496 from vigoux/ts_internal_lang
feat(treesitter): allow customizing language symbol name
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/treesitter.txt12
-rw-r--r--runtime/lua/vim/treesitter/language.lua14
2 files changed, 15 insertions, 11 deletions
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
index 52531a1525..06409f9980 100644
--- a/runtime/doc/treesitter.txt
+++ b/runtime/doc/treesitter.txt
@@ -387,16 +387,20 @@ inspect_language({lang}) *inspect_language()*
Parameters: ~
{lang} The language.
-require_language({lang}, {path}, {silent}) *require_language()*
+ *require_language()*
+require_language({lang}, {path}, {silent}, {symbol_name})
Asserts that the provided language is installed, and optionally provide a
path for the parser
Parsers are searched in the `parser` runtime directory.
Parameters: ~
- {lang} The language the parser should parse
- {path} Optional path the parser is located at
- {silent} Don't throw an error if language not found
+ {lang} (string) The language the parser should parse
+ {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
==============================================================================
diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua
index dfb6f5be84..d14b825603 100644
--- a/runtime/lua/vim/treesitter/language.lua
+++ b/runtime/lua/vim/treesitter/language.lua
@@ -6,10 +6,11 @@ local M = {}
---
--- Parsers are searched in the `parser` runtime directory.
---
----@param lang The language the parser should parse
----@param path Optional path the parser is located at
----@param silent Don't throw an error if language not found
-function M.require_language(lang, path, silent)
+---@param lang string The language the parser should parse
+---@param path string|nil Optional path the parser is located at
+---@param silent boolean|nil Don't throw an error if language not found
+---@param symbol_name string|nil Internal symbol name for the language to load
+function M.require_language(lang, path, silent, symbol_name)
if vim._ts_has_language(lang) then
return true
end
@@ -21,7 +22,6 @@ function M.require_language(lang, path, silent)
return false
end
- -- TODO(bfredl): help tag?
error("no parser for '" .. lang .. "' language, see :help treesitter-parsers")
end
path = paths[1]
@@ -29,10 +29,10 @@ function M.require_language(lang, path, silent)
if silent then
return pcall(function()
- vim._ts_add_language(path, lang)
+ vim._ts_add_language(path, lang, symbol_name)
end)
else
- vim._ts_add_language(path, lang)
+ vim._ts_add_language(path, lang, symbol_name)
end
return true