Skip to content

Commit fa70ea6

Browse files
authored
Merge pull request #9 from fnurk/feat/binding-types-in-completion
feat: add basic CompletionItemKind
2 parents 6d35bb1 + 2f1692f commit fa70ea6

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/main.janet

+49-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,57 @@
6565

6666
[:noresponse])
6767

68+
(defn binding-type
69+
[x]
70+
(case (type (eval x))
71+
:symbol 12 :boolean 6
72+
:function 3 :cfunction 3
73+
:string 6 :buffer 6
74+
:number 6 :keyword 6
75+
:core/file 17 :core/peg 6
76+
:struct 6 :table 6
77+
:tuple 6 :array 6
78+
:fiber 6 :nil 6))
79+
80+
(defn binding-to-lsp-item
81+
"Takes a binding and returns a CompletionItem"
82+
[name]
83+
{:label name :kind (binding-type name)})
84+
85+
(deftest "test binding-to-lsp-item"
86+
(defglobal 'anil nil)
87+
(defglobal 'hello 'world)
88+
(defglobal 'atuple [:a 1])
89+
90+
(def test-cases @[['hello :symbol] [true :boolean] [% :function]
91+
[abstract? :cfunction] ["Hello world" :string]
92+
[@"Hello world":buffer] [123 :number]
93+
[:keyword :keyword] [stderr :core/file]
94+
[(peg/compile 1) :core/peg] [{:a 1} :struct]
95+
[@{:a 1} :table] ['atuple :tuple]
96+
[@[:a 1]:array] # [(coro) :fiber]
97+
['anil :nil]])
98+
99+
(test (map (juxt 1 |(binding-to-lsp-item (first $))) test-cases)
100+
@[[:symbol {:kind 12 :label hello}]
101+
[:boolean {:kind 6 :label true}]
102+
[:function {:kind 3 :label @%}]
103+
[:cfunction {:kind 3 :label @abstract?}]
104+
[:string {:kind 6 :label "Hello world"}]
105+
[:buffer {:kind 6 :label @"Hello world"}]
106+
[:number {:kind 6 :label 123}]
107+
[:keyword {:kind 6 :label :keyword}]
108+
[:core/file {:kind 17 :label "<core/file 0x1>"}]
109+
[:core/peg {:kind 6 :label "<core/peg 0x2>"}]
110+
[:struct {:kind 6 :label {:a 1}}]
111+
[:table {:kind 6 :label @{:a 1}}]
112+
[:tuple {:kind 6 :label atuple}]
113+
[:array {:kind 6 :label @[:a 1]}]
114+
[:nil {:kind 6 :label anil}]]))
115+
68116
(defn on-completion [state params]
69117
[:ok state {:isIncomplete true
70-
:items (map (fn [x] {:label x}) (all-bindings))}])
118+
:items (map binding-to-lsp-item (all-bindings))}])
71119

72120
(defn on-completion-item-resolve [state params]
73121
(let [label (get params "label")]

0 commit comments

Comments
 (0)