Skip to content

Commit

Permalink
fix(mod): handle case where mod decl exists (#19)
Browse files Browse the repository at this point in the history
* feat(mod): handle case where mod decl exists

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Marc Jakobi <[email protected]>
  • Loading branch information
gregorias and mrcjkb committed Dec 9, 2023
1 parent db2d7b9 commit 86c8a0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ 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.2] - 2023-12-09

### Fixed

- Made the `mod` snippet handle the case where the module declaration already
exists.
Thanks [@gregorias](https://github.com/gregorias)!

## [1.4.1] - 2023-12-05

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion lua/haskell-snippets/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ local get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients
function util.lsp_get_module_name()
if #get_clients { bufnr = 0 } > 0 then
for _, lens in pairs(vim.lsp.codelens.get(0)) do
local name = lens.command.title:match('module (.*) where')
-- Strings to match taken from the module name plugin:
-- https://github.com/haskell/haskell-language-server/blob/f0c16469046bd554828ea057b5e1f047ad02348e/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs#L129-L136
local name_module_decl_absent = lens.command.title:match('module (.*) where')
local name_module_decl_present = lens.command.title:match('Set module name to (.*)')
local name = name_module_decl_absent or name_module_decl_present
if name then
return name
end
Expand Down

0 comments on commit 86c8a0b

Please sign in to comment.