Skip to content

Commit 66efa6d

Browse files
author
Marc Jakobi
committed
fix: stop using legacy nvim-treesitter api
1 parent 5ae77ce commit 66efa6d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lua/haskell-snippets/module.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ local choice = ls.choice_node
2121
local dynamic = ls.dynamic_node
2222
local func = ls.function_node
2323

24-
local has_treesitter, parsers = pcall(require, 'nvim-treesitter.parsers')
25-
local hs_lang = has_treesitter and parsers.ft_to_lang('haskell') or 'haskell'
26-
local has_haskell_parser = pcall(vim.treesitter.get_string_parser, '', 'haskell')
24+
---@type fun(ft: string): string? | nil
25+
local get_lang = vim.tbl_get(vim.treesitter, 'language', 'get_lang')
26+
local treesitter_haskell_lang_name = get_lang and get_lang('haskell') or 'haskell'
27+
local has_haskell_parser = pcall(vim.treesitter.get_string_parser, '', treesitter_haskell_lang_name)
2728

2829
--- Parses without injections
2930
local function fast_parse(lang_tree)
@@ -42,11 +43,15 @@ end
4243
---@return string|nil
4344
local function treesitter_module_name(apply, content, query_string, legacy_query_string)
4445
assert(has_haskell_parser, 'No tree-sitter parser for Haskell found.')
45-
local ok, module_query = pcall(vim.treesitter.query.parse, hs_lang, query_string)
46+
local ok, module_query = pcall(vim.treesitter.query.parse, treesitter_haskell_lang_name, query_string)
4647
if not ok then
47-
module_query = vim.treesitter.query.parse(hs_lang, legacy_query_string)
48+
module_query = vim.treesitter.query.parse(treesitter_haskell_lang_name, legacy_query_string)
4849
end
49-
local lang_tree = vim.treesitter.get_string_parser(content, hs_lang, { injections = { [hs_lang] = '' } })
50+
local lang_tree = vim.treesitter.get_string_parser(
51+
content,
52+
treesitter_haskell_lang_name,
53+
{ injections = { [treesitter_haskell_lang_name] = '' } }
54+
)
5055
local root = fast_parse(lang_tree):root()
5156
---@diagnostic disable-next-line
5257
for _, match in module_query:iter_matches(root, content) do

0 commit comments

Comments
 (0)