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

@@ -182,8 +182,9 @@ void ui_refresh(void)
local firstrun = q(1)
local manyruns = q(100)
local factor = is_os('win') and 3 or 4
-- First run should be at least 4x slower.
assert(400 * manyruns < firstrun, ('firstrun: %d ms, manyruns: %d ms'):format(firstrun / 1000, manyruns / 1000))
assert(factor * 100 * manyruns < firstrun, ('firstrun: %d ms, manyruns: %d ms'):format(firstrun / 1000, manyruns / 1000))
end)
it('support query and iter by capture', function()