From 38cfd9a2496eee0764172d581ce2f9a2ea772950 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Wed, 30 Jul 2025 15:59:43 -0500 Subject: [PATCH] tricky macro hidden scope completions it's hard to tell which scope something is in. This makes completions a little better but it misses docs during good completion --- src/fennel-ls/compiler.fnl | 1 + src/fennel-ls/completion.fnl | 6 ++++-- test/completion.fnl | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index bfe141c..4908047 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -112,6 +112,7 @@ identifiers are declared / referenced in which places." (λ symbol-to-expression [ast scope ?reference?] (assert (sym? ast) "symbols only") + (tset scopes ast scope) (reference ast scope (if ?reference? :read (not (multisym? ast)) diff --git a/src/fennel-ls/completion.fnl b/src/fennel-ls/completion.fnl index 68579bc..8523a69 100644 --- a/src/fennel-ls/completion.fnl +++ b/src/fennel-ls/completion.fnl @@ -57,7 +57,8 @@ is set to true and we report that we support completionItem/resolve." &until ?find] (= (. ast 1) symbol))) ;; find the first parent that contains a scope - scope (or (accumulate [?find nil _ parent (ipairs parents) &until ?find] + scope (or (. file.scopes symbol) + (accumulate [?find nil _ parent (ipairs parents) &until ?find] (. file.scopes parent)) file.scope) range (case (message.ast->range server file symbol) @@ -157,7 +158,8 @@ is set to true and we report that we support completionItem/resolve." (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] + scope (or (. file.scopes _symbol) + (accumulate [?find nil _ parent (ipairs parents) &until ?find] (. file.scopes parent)) file.scope) result (analyzer.search-name-and-scope server file completion-item.label scope)] diff --git a/test/completion.fnl b/test/completion.fnl index 125f804..58fa148 100644 --- a/test/completion.fnl +++ b/test/completion.fnl @@ -178,6 +178,11 @@ {:kind #(= nil $)} {:label #(= nil $)}]) + (check "(case {} + identifier |" + [:identifier] + []) ; TODO [{:documentation #(= nil $)}]) + (each [_ mode (ipairs [true false])] (check "(fn x [a b c] \"docstring\"