diff --git a/src/fennel-ls/utils.fnl b/src/fennel-ls/utils.fnl index 9ac1e0e..c3c95b8 100644 --- a/src/fennel-ls/utils.fnl +++ b/src/fennel-ls/utils.fnl @@ -165,9 +165,13 @@ These functions are all pure functions, which makes me happy." (let [offset (or ?offset (length symbol)) next-separator (or (symbol:find ".[.:]" offset) (length symbol)) - symbol (symbol:sub 1 next-separator)] - (icollect [word (: (.. symbol ".") :gmatch "(.-)[.:]")] - word)))) + symbol (symbol:sub 1 next-separator) + parts (icollect [word (symbol:gmatch "[^.:]+")] + word)] + (if (symbol:match "[.:]+$") + (tset parts (length parts) + (.. (. parts (length parts)) (symbol:match "[.:]+$")))) + parts))) (fn multi-sym-base [symbol] (local symbol (tostring symbol)) diff --git a/test/completion.fnl b/test/completion.fnl index 4e82574..c61c8f7 100644 --- a/test/completion.fnl +++ b/test/completion.fnl @@ -282,6 +282,15 @@ ; [:os]) nil) +;; ensure that we get completions for both the symbol and the table fields +(fn test-sym-ending-in-delimiter [] + (check "(local a {:b 1 :c 2}) + (local a. 3) + (set a.|" + ["a." "a.b" "a.c"] + []) + nil) + ;; ;; Future tests / features ;; ;; Scope Ordering Rules ;; (it "does not suggest locals past the suggestion location when a symbol is partially typed") @@ -308,4 +317,5 @@ : test-module : test-destructure : test-no-completion - : test-compiler-env} + : test-compiler-env + : test-sym-ending-in-delimiter} diff --git a/test/misc.fnl b/test/misc.fnl index f40c003..f72aec4 100644 --- a/test/misc.fnl +++ b/test/misc.fnl @@ -14,6 +14,11 @@ (faith.= ["is" "equal"] (utils.multi-sym-split "is.equal" 5)) (faith.= ["a" "b" "c" "d" "e" "f"] (utils.multi-sym-split "a.b.c.d.e.f")) (faith.= ["obj" "bar"] (utils.multi-sym-split (fennel.sym "obj.bar"))) + (faith.= ["a."] (utils.multi-sym-split (fennel.sym "a."))) + (faith.= [".."] (utils.multi-sym-split (fennel.sym ".."))) + (faith.= ["?."] (utils.multi-sym-split (fennel.sym "?."))) + (faith.= ["b:"] (utils.multi-sym-split (fennel.sym "b:"))) + (faith.= ["b" "a."] (utils.multi-sym-split (fennel.sym "b:a."))) nil) (fn test-find-symbol [] @@ -34,6 +39,11 @@ "[[1 2 sym-one] (match [1 2 4] [1 2 sym-one] sym-one) [(match [1 2 4] [1 2 sym-one] sym-one)]]" (fennel.view parents {:one-line? true}) "bad parents")) + + (let [{: server : uri} (create-client "(local a. 1) (print a.)") + file (. server.files uri) + [symbol _parents] [(analyzer.find-symbol server file 21)]] + (faith.= symbol (fennel.sym "a."))) nil) (fn test-failure []