mirror of
https://github.com/neovim/neovim.git
synced 2026-04-20 06:20:53 +00:00
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.
This commit is contained in:
@@ -252,7 +252,7 @@ end)
|
||||
---
|
||||
---@return Query Parsed query
|
||||
function M.parse_query(lang, query)
|
||||
language.require_language(lang)
|
||||
language.add(lang)
|
||||
local cached = query_cache[lang][query]
|
||||
if cached then
|
||||
return cached
|
||||
|
||||
Reference in New Issue
Block a user