feat(treesitter): allow customizing language symbol name

This commit is contained in:
Thomas Vigouroux
2022-07-25 12:23:04 +02:00
parent 15a768eeb0
commit 3c1d70f20b
4 changed files with 33 additions and 14 deletions

View File

@@ -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