Skip to content

Commit

Permalink
fix(module): broken qual snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Dec 15, 2023
1 parent 3cd5c1f commit 4c35350
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use flake -Lv
use flake . -Lv
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.3] - 2023-12-05

### Fixed

- Broken `qual` snippet: Constructing only the first
part of the module as an alias choice [[#20](https://github.com/mrcjkb/haskell-snippets.nvim/issues/20)].

## [1.4.2] - 2023-12-09

### Fixed
Expand Down
12 changes: 7 additions & 5 deletions lua/haskell-snippets/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local function fast_parse(lang_tree)
return parser:parse(old_trees[1], lang_tree._source)
end

---@param apply fun(module_name: string):(string|nil) Callback to apply the module name to
---@param apply fun(module_name: string):(string|nil) Callback to apply the module name to. If the callback returns, this function returns.
---@param content string The content to parse from
---@param query_string? string The tree-sitter query string with a '@mod' capture
---@return string|nil
Expand All @@ -48,8 +48,11 @@ local function treesitter_module_name(apply, content, query_string)
---@diagnostic disable-next-line
for _, match in module_query:iter_matches(root, content) do
for _, node in ipairs(match) do
local txt = vim.treesitter.get_node_text(node, content)
return apply(txt)
local txt = vim.print(vim.treesitter.get_node_text(node, content))
local result = apply(txt)
if result then
return result
end
end
end
end
Expand All @@ -58,7 +61,7 @@ end
local function get_buf_module_name(_)
local buf_content = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n')
return treesitter_module_name(function(mod)
return vim.print(mod)
return mod
end, buf_content, '[(module)(qualified_module)] @mod')
end

Expand Down Expand Up @@ -106,7 +109,6 @@ local function get_qualified_name_node(args)
local choices = { insert(1) }
if has_haskell_parser then
treesitter_module_name(function(mod)
vim.print(mod)
table.insert(choices, 1, text(mod:sub(1, 1)))
table.insert(choices, 1, text(mod))
end, import_stmt)
Expand Down

0 comments on commit 4c35350

Please sign in to comment.