From c78f5411bfc0ab31939e570d5c864da92bd082f2 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Sat, 26 Jul 2025 19:21:26 -0500 Subject: [PATCH] insert/replace completion support LSP protocol describes two types of completion: insert, and replace. It turns out its really easy to support this. The hard part is just checking if the client actually wants it. --- src/fennel-ls/completion.fnl | 6 +++++- src/fennel-ls/config.fnl | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fennel-ls/completion.fnl b/src/fennel-ls/completion.fnl index 0cf1ff3..f98886d 100644 --- a/src/fennel-ls/completion.fnl +++ b/src/fennel-ls/completion.fnl @@ -136,7 +136,11 @@ is set to true and we report that we support completionItem/resolve." (expression-completions))) (if server.can-do-good-completions? - {:itemDefaults {:editRange range :data {: uri : byte}} + {:itemDefaults {:editRange (if server.can-do-insert-replace-completions? + {:insert {:start range.start :end position} + :replace range} + range) + :data {: uri : byte}} :items results} results))) diff --git a/src/fennel-ls/config.fnl b/src/fennel-ls/config.fnl index 4e0ab5e..5cf35a2 100644 --- a/src/fennel-ls/config.fnl +++ b/src/fennel-ls/config.fnl @@ -132,6 +132,7 @@ However, when not an option, fennel-ls will fall back to positionEncoding=\"utf- (case (?. params :capabilities :textDocument :completion :completionList :itemDefaults) completion-item-defaults (and (accumulate [found nil _ v (ipairs completion-item-defaults) &until found] (= v :editRange)) (accumulate [found nil _ v (ipairs completion-item-defaults) &until found] (= v :data))))) + (set server.can-do-insert-replace-completions? (?. params :capabilities :textDocument :completion :completionItem :insertReplaceSupport)) (reload server)) {: initialize