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:
Lewis Russell
2023-02-21 17:09:18 +00:00
committed by GitHub
parent 344a1ee8e6
commit 8714a4009c
9 changed files with 141 additions and 44 deletions

View File

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