From b7e497228f16afd533a321eef91c5d5acc8c7992 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Tue, 8 Jul 2025 21:08:12 -0500 Subject: [PATCH] completions for "true" "false" and "nil" --- src/fennel-ls/completion.fnl | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/fennel-ls/completion.fnl b/src/fennel-ls/completion.fnl index fb12a65..b87b941 100644 --- a/src/fennel-ls/completion.fnl +++ b/src/fennel-ls/completion.fnl @@ -7,6 +7,14 @@ (local navigate (require :fennel-ls.navigate)) (local {:metadata METADATA} (require :fennel.compiler)) +(local hardcoded-completions + {:nil {:metadata {:fnl/docstring "Represents the absence of a useful value." + :fls/itemKind "Keyword"}} + :true {:metadata {:fnl/docstring "A boolean value representing truth." + :fls/itemKind "Keyword"}} + :false {:metadata {:fnl/docstring "A boolean value representing falsehood." + :fls/itemKind "Keyword"}}}) + (λ textDocument/completion [server _send {: position :textDocument {: uri}}] ;; get the file (let [file (files.get-by-uri server uri) @@ -48,6 +56,9 @@ (add-completion-recursively! (.. name "." field) def))) (set (. seen definition) false))) + (each [name documentation (pairs hardcoded-completions)] + (add-completion! name documentation)) + (local seen-manglings {}) (each [_ global* (ipairs file.allowed-globals)] @@ -92,14 +103,15 @@ results))) (fn completionItem/resolve [server _send completion-item] - (let [{: uri : byte} completion-item.data - file (files.get-by-uri server uri) - (_symbol parents) (analyzer.find-symbol file.ast byte) - scope (or (accumulate [?find nil _ parent (ipairs parents) &until ?find] - (. file.scopes parent)) - file.scope)] - (case (analyzer.search-name-and-scope server file completion-item.label scope) - result (doto completion-item (tset :documentation (format.hover-format server completion-item.label result)))))) + (or (. hardcoded-completions completion-item.label) + (let [{: uri : byte} completion-item.data + file (files.get-by-uri server uri) + (_symbol parents) (analyzer.find-symbol file.ast byte) + scope (or (accumulate [?find nil _ parent (ipairs parents) &until ?find] + (. file.scopes parent)) + file.scope)] + (case (analyzer.search-name-and-scope server file completion-item.label scope) + result (doto completion-item (tset :documentation (format.hover-format server completion-item.label result))))))) {: textDocument/completion : completionItem/resolve}