Skip to content

Commit 25124d9

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

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

doc/tags

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
DataSnippetCollection haskell-snippets.txt /*DataSnippetCollection*
2+
ExpressionSnippetCollection haskell-snippets.txt /*ExpressionSnippetCollection*
3+
FunctionSnippetCollection haskell-snippets.txt /*FunctionSnippetCollection*
4+
HaskellSnippetCollection haskell-snippets.txt /*HaskellSnippetCollection*
5+
ModuleSnippetCollection haskell-snippets.txt /*ModuleSnippetCollection*
6+
PragmaSnippetCollection haskell-snippets.txt /*PragmaSnippetCollection*
7+
QuasiQuoteSnippetCollection haskell-snippets.txt /*QuasiQuoteSnippetCollection*
8+
Snippet haskell-snippets.txt /*Snippet*
9+
data.adt haskell-snippets.txt /*data.adt*
10+
data.cls haskell-snippets.txt /*data.cls*
11+
data.constraint haskell-snippets.txt /*data.constraint*
12+
data.ins haskell-snippets.txt /*data.ins*
13+
data.newtype haskell-snippets.txt /*data.newtype*
14+
data.rec haskell-snippets.txt /*data.rec*
15+
expressions.case haskell-snippets.txt /*expressions.case*
16+
expressions.if_expr haskell-snippets.txt /*expressions.if_expr*
17+
expressions.if_expr_multiline haskell-snippets.txt /*expressions.if_expr_multiline*
18+
expressions.if_expr_multiway haskell-snippets.txt /*expressions.if_expr_multiway*
19+
expressions.lambdacase haskell-snippets.txt /*expressions.lambdacase*
20+
functions.fn haskell-snippets.txt /*functions.fn*
21+
functions.func haskell-snippets.txt /*functions.func*
22+
functions.lambda haskell-snippets.txt /*functions.lambda*
23+
haskell-snippets haskell-snippets.txt /*haskell-snippets*
24+
haskell-snippets.datadat haskell-snippets.txt /*haskell-snippets.datadat*
25+
haskell-snippets.expressions haskell-snippets.txt /*haskell-snippets.expressions*
26+
haskell-snippets.function haskell-snippets.txt /*haskell-snippets.function*
27+
haskell-snippets.module haskell-snippets.txt /*haskell-snippets.module*
28+
haskell-snippets.pragmas haskell-snippets.txt /*haskell-snippets.pragmas*
29+
haskell-snippets.quasiqotes haskell-snippets.txt /*haskell-snippets.quasiqotes*
30+
module.impc haskell-snippets.txt /*module.impc*
31+
module.mod haskell-snippets.txt /*module.mod*
32+
module.qual haskell-snippets.txt /*module.qual*
33+
module.qualc haskell-snippets.txt /*module.qualc*
34+
pragmas.discover haskell-snippets.txt /*pragmas.discover*
35+
pragmas.lang haskell-snippets.txt /*pragmas.lang*
36+
pragmas.nowarn haskell-snippets.txt /*pragmas.nowarn*
37+
pragmas.prag haskell-snippets.txt /*pragmas.prag*
38+
quasiquotes.qq haskell-snippets.txt /*quasiquotes.qq*
39+
quasiquotes.sql haskell-snippets.txt /*quasiquotes.sql*

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)