File tree Expand file tree Collapse file tree 3 files changed +56
-1
lines changed
src/zen_lang/lsp_server/impl
test-resources/test-project/zrc Expand file tree Collapse file tree 3 files changed +56
-1
lines changed Original file line number Diff line number Diff line change 11(ns zen-lang.lsp-server.impl.autocomplete )
22
3+ (defn gather-confirming-keys
4+ [ztx confirmings]
5+ (when (seq confirmings)
6+ (mapcat #(concat (keys (get-in @ztx [:symbols % :keys ]))
7+ (gather-confirming-keys ztx (:confirms (get-in @ztx [:symbols %]))))
8+ confirmings)))
39
410(defn find-completions [ztx {:keys [uri struct-path]}]
511 (cond
1622 sort
1723 (mapv str)))
1824
25+ ; ; :keys symbol suggestion based on :confirms key
26+ (= :keys (last struct-path))
27+ (let [current-ns (get-in @ztx [:file uri :last-valid-edn 'ns])
28+ pos-ctx-struct (get-in @ztx (into [:file uri :last-valid-edn ] (butlast struct-path)))
29+ confirms (map #(if (nil? (namespace %))
30+ (symbol (str current-ns) (name %))
31+ %)
32+ (:confirms pos-ctx-struct))
33+ confirming-keys (gather-confirming-keys ztx confirms)]
34+ (vec (map str confirming-keys)))
35+
1936 ; ; schema :keys keyword suggestion
2037 :else
2138 (let [pos-ctx-struct (get-in @ztx (into [:file uri :last-valid-edn ] struct-path))
Original file line number Diff line number Diff line change 1+ {ns qux
2+ import #{baz}
3+
4+ grand-parent-schema
5+ {:zen/tags #{zen/schema}
6+ :type zen/map
7+ :keys {:grand-parent-key {:type zen/string}}
8+ :zen/desc " A cool schema" }
9+
10+ parent-schema
11+ {:zen/tags #{zen/schema}
12+ :type zen/map
13+ :confirms #{baz/schema2 grand-parent-schema}
14+ :keys {:parent-key {:type zen/string}}
15+ :zen/desc " A cool schema" }
16+
17+ schema
18+ {:zen/tags #{zen/schema}
19+ :type zen/map
20+ :confirms #{parent-schema}
21+ :keys {:hello {:type zen/string
22+ :confirms #{grand-parent-schema}
23+ :keys {}}
24+ :baz {}}
25+ :zen/desc " A cool schema" }}
Original file line number Diff line number Diff line change 1010 (do (alter-var-root #'server/zen-ctx (constantly (server/new-context )))
1111 (server/initialize-paths {:root " test-resources/test-project" })
1212 (server/load-document (file->message " test-resources/test-project/zrc/baz.edn" ))
13+ (server/load-document (file->message " test-resources/test-project/zrc/foo.edn" ))
1314 server/zen-ctx))
1415
1516(deftest find-completions-test
3132 (is (= (conj (->> @ztx :symbols keys (mapv str) set) " schema" " schema2" )
3233 (let [f " test-resources/test-project/zrc/baz.edn"
3334 path ['schema2 :qux :type ]]
34- (set (zl/find-completions ztx {:uri f :struct-path path}))))) )
35+ (set (zl/find-completions ztx {:uri f :struct-path path}))))))
36+
37+ (testing " following hierarchy of symbols by the :confirm key gather all possible keys"
38+ (is (= (let [parent-keys (get-in @ztx [:symbols 'qux/parent-schema :keys ])
39+ grand-parent-keys (get-in @ztx [:symbols 'qux/grand-parent-schema :keys ])
40+ imported-keys (get-in @ztx [:symbols 'baz/schema2 :keys ])]
41+ (->> (concat parent-keys grand-parent-keys imported-keys)
42+ keys
43+ set
44+ (map str)
45+ vec))
46+ (let [f " test-resources/test-project/zrc/qux.edn" ]
47+ (zl/find-completions ztx {:uri f :struct-path ['schema :keys ]})))))
3548 ))
You can’t perform that action at this time.
0 commit comments