Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module): broken qual snippet #21

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-15

### 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