From be5e167d67466c760511facb5eff8afca9a5c966 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Sun, 11 Feb 2024 23:11:45 -0600 Subject: [PATCH] very minor fix for completions --- src/fennel-ls/handlers.fnl | 4 +++- test/completion-test.fnl | 16 ++++++++++++---- test/is.fnl | 4 ++-- test/lust.lua | 6 +++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/fennel-ls/handlers.fnl b/src/fennel-ls/handlers.fnl index a6dacc3..46cdf3f 100644 --- a/src/fennel-ls/handlers.fnl +++ b/src/fennel-ls/handlers.fnl @@ -12,6 +12,8 @@ Every time the client sends a message, it gets handled by a function in the corr (local formatter (require :fennel-ls.formatter)) (local utils (require :fennel-ls.utils)) +(local fennel (require :fennel)) + (local requests []) (local notifications []) @@ -140,7 +142,7 @@ Every time the client sends a message, it gets handled by a function in the corr file.scope) ?parent (. parents 1) result [] - in-call-position? (and ?parent (= ?symbol (. ?parent 1)))] + in-call-position? (and (fennel.list? ?parent) (= ?symbol (. ?parent 1)))] (collect-scope scope :manglings #(doto (make-completion-item self file $ scope) (tset :kind kinds.Variable)) result) (when in-call-position? diff --git a/test/completion-test.fnl b/test/completion-test.fnl index 0dce7d4..afc4c36 100644 --- a/test/completion-test.fnl +++ b/test/completion-test.fnl @@ -85,6 +85,11 @@ (it "suggests function arguments at the top scope of the function" (check-completion "(fn foo [arg1 arg2 arg3]\n (do (do (do ))))" 1 14 [:arg1 :arg2 :arg3] [] 1 14)) + (it "suggests even in a macro" + (check-completion "(local item 10)\n(doto it)" 1 8 [:item] [] 1 6) + (check-completion "(local item 10)\n(case 1 1 it)" 1 12 [:item] [] 1 10) + nil) + ;; ;; Scope Ordering Rules ;; (it "does not suggest locals past the suggestion location when a symbol is partially typed") ;; (it "does not suggest locals past the suggestion location without a symbol") @@ -97,9 +102,13 @@ (check-completion "(do )" 0 4 [] [:do :let :fn :-> :-?>> :?.])) - ;; (it "doesn't suggest specials at the very top level") - ;; (it "doesn't suggest macros in the middle of a list (open paren required)") - ;; (it "doesn't suggest macros at the very top level") + (it "doesn't suggest specials at the very top level, fresh" + (check-completion "\n" + 0 0 [] [:do :let :fn :-> :-?>> :?.])) + + (it "doesn't suggest specials at the very top level, with a symbol" + (check-completion "d\n" + 0 1 [] [:do :let :fn :-> :-?>> :?.])) (it "suggests fields of tables" (check-completion @@ -222,7 +231,6 @@ ;; (it "suggests known keys when using the `.` special") ;; (it "suggests known module names in `require` and `include` and `import-macros` and `require-macros` and friends") ;; (it "knows the fields of the standard lua library.") - ;; (it "suggests special forms for the call position of a list, but not other positions") ;; (it "does not suggest special forms for the \"call\" position when a list isn't actually a call, ie destructuring assignment") ;; (it "suggests keys when typing out destructuring, as in `(local {: typinghere} (require :mod))`") ;; (it "only suggests tables for `ipairs` / begin work on type checking system") diff --git a/test/is.fnl b/test/is.fnl index 0e5e25a..6134421 100644 --- a/test/is.fnl +++ b/test/is.fnl @@ -4,8 +4,8 @@ ;; lust uses weird terminology, but what I say is that "equal" is by __eq, "same" is by recursively having the same contents (setmetatable {:equal #(do ((. (expect $1) :to :be) $2) true) :same #(do ((. (expect $1) :to :equal) $2 $3) true) - :nil #(do ((. (expect $1) :to_not :exist)) true) - :not {:nil #(do ((. (expect $1) :to :exist)) true) + :nil #(do ((. (expect $1) :to_not :exist) $2) true) + :not {:nil #(do ((. (expect $1) :to :exist) $2) true) :same #(do ((. (expect $1) :to_not :equal) $2))} :truthy #(do ((. (expect $1) :to :be :truthy)) true)} {:__call #(do ((. (expect $2) :to :be :truthy)) true)}) diff --git a/test/lust.lua b/test/lust.lua index fc3d2ee..1ef5b10 100644 --- a/test/lust.lua +++ b/test/lust.lua @@ -133,10 +133,10 @@ local paths = { end }, exist = { - test = function(v) + test = function(v, message) return v ~= nil, - 'expected ' .. tostring(v) .. ' to exist', - 'expected ' .. tostring(v) .. ' to not exist' + message or 'expected ' .. tostring(v) .. ' to exist', + message or 'expected ' .. tostring(v) .. ' to not exist' end }, truthy = {