From 7c42d1b7b048b33a1c3d8d9ff48ab5329b726a20 Mon Sep 17 00:00:00 2001 From: Grzegorz Milka Date: Sat, 9 Dec 2023 12:00:48 +0100 Subject: [PATCH 1/3] feat(mod): handle case where mod decl exists --- CHANGELOG.md | 5 +++++ lua/haskell-snippets/util.lua | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df54866..e02c63d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ 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). +## [Unreleased] + +- Made the `mod` snippet handle the case where the module declaration already + exists. + ## [1.4.1] - 2023-12-05 ### Fixed diff --git a/lua/haskell-snippets/util.lua b/lua/haskell-snippets/util.lua index ba0e921..3167c82 100644 --- a/lua/haskell-snippets/util.lua +++ b/lua/haskell-snippets/util.lua @@ -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 From 0c0d8ed7d18a3091d872f136e327d62fb7cdda6b Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sat, 9 Dec 2023 14:27:35 +0100 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e02c63d..bb65f51 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### 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 From 4b2273285ee6951b3e8753ac38cfd36328d7fb95 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sat, 9 Dec 2023 14:28:23 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb65f51..0e16b81 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ 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). -## [Unreleased] +## [1.4.2] - 2023-12-09 ### Fixed