Skip to content

Commit dfb3921

Browse files
authored
fix(tree-sitter): update queries for tree-sitter-haskell rewrite (#27)
1 parent 89a4f68 commit dfb3921

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [1.4.4] - 2024-05-13
10+
11+
### Fixed
12+
13+
- Updated tree-sitter queries to be compatible with the
14+
tree-sitter-haskell v0.21.0 rewrite.
15+
Because there are not many queries, this plugin maintains backward
16+
compatibility with the previous tree-sitter-haskell implementation for now.
17+
918
## [1.4.3] - 2023-12-15
1019

1120
### Fixed

lua/haskell-snippets/module.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ end
3737

3838
---@param apply fun(module_name: string):(string|nil) Callback to apply the module name to. If the callback returns, this function returns.
3939
---@param content string The content to parse from
40-
---@param query_string? string The tree-sitter query string with a '@mod' capture
40+
---@param query_string string The tree-sitter query string with a '@mod' capture (v0.21.0 rewrite)
41+
---@param legacy_query_string string The legacy tree-sitter query string with a '@mod' capture
4142
---@return string|nil
42-
local function treesitter_module_name(apply, content, query_string)
43+
local function treesitter_module_name(apply, content, query_string, legacy_query_string)
4344
assert(has_haskell_parser, 'No tree-sitter parser for Haskell found.')
44-
query_string = query_string or '(module) @mod'
45-
local module_query = vim.treesitter.query.parse(hs_lang, query_string)
45+
local ok, module_query = pcall(vim.treesitter.query.parse, hs_lang, query_string)
46+
if not ok then
47+
module_query = vim.treesitter.query.parse(hs_lang, legacy_query_string)
48+
end
4649
local lang_tree = vim.treesitter.get_string_parser(content, hs_lang, { injections = { [hs_lang] = '' } })
4750
local root = fast_parse(lang_tree):root()
4851
---@diagnostic disable-next-line
@@ -62,7 +65,7 @@ local function get_buf_module_name(_)
6265
local buf_content = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n')
6366
return treesitter_module_name(function(mod)
6467
return mod
65-
end, buf_content, '[(module)(qualified_module)] @mod')
68+
end, buf_content, '(haskell (header module: (module) @mod))', '(haskell module: (module) @mod)')
6669
end
6770

6871
local function get_module_name_node()
@@ -111,7 +114,7 @@ local function get_qualified_name_node(args)
111114
treesitter_module_name(function(mod)
112115
table.insert(choices, 1, text(mod:sub(1, 1)))
113116
table.insert(choices, 1, text(mod))
114-
end, import_stmt)
117+
end, import_stmt, '(module_id) @mod', '(module) @mod')
115118
end
116119
return sn(nil, {
117120
choice(1, choices),

0 commit comments

Comments
 (0)