Skip to content

Commit cf8cd30

Browse files
authored
fix(module): broken qual snippet (#21)
1 parent 3cd5c1f commit cf8cd30

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
use flake -Lv
1+
use flake . -Lv

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ 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.3] - 2023-12-15
10+
11+
### Fixed
12+
13+
- Broken `qual` snippet: Constructing only the first
14+
part of the module as an alias choice [[#20](https://github.com/mrcjkb/haskell-snippets.nvim/issues/20)].
15+
916
## [1.4.2] - 2023-12-09
1017

1118
### Fixed

lua/haskell-snippets/module.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ local function fast_parse(lang_tree)
3535
return parser:parse(old_trees[1], lang_tree._source)
3636
end
3737

38-
---@param apply fun(module_name: string):(string|nil) Callback to apply the module name to
38+
---@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
4040
---@param query_string? string The tree-sitter query string with a '@mod' capture
4141
---@return string|nil
@@ -48,8 +48,11 @@ local function treesitter_module_name(apply, content, query_string)
4848
---@diagnostic disable-next-line
4949
for _, match in module_query:iter_matches(root, content) do
5050
for _, node in ipairs(match) do
51-
local txt = vim.treesitter.get_node_text(node, content)
52-
return apply(txt)
51+
local txt = vim.print(vim.treesitter.get_node_text(node, content))
52+
local result = apply(txt)
53+
if result then
54+
return result
55+
end
5356
end
5457
end
5558
end
@@ -58,7 +61,7 @@ end
5861
local function get_buf_module_name(_)
5962
local buf_content = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n')
6063
return treesitter_module_name(function(mod)
61-
return vim.print(mod)
64+
return mod
6265
end, buf_content, '[(module)(qualified_module)] @mod')
6366
end
6467

@@ -106,7 +109,6 @@ local function get_qualified_name_node(args)
106109
local choices = { insert(1) }
107110
if has_haskell_parser then
108111
treesitter_module_name(function(mod)
109-
vim.print(mod)
110112
table.insert(choices, 1, text(mod:sub(1, 1)))
111113
table.insert(choices, 1, text(mod))
112114
end, import_stmt)

0 commit comments

Comments
 (0)