Better completions for fields of tables
Now it does a two-level-deep search when creating competions for tables, which means that a completion for module fields have better metadata. the completion code is a bit of a mess, so I want to look into refactoring it soon.
This commit is contained in:
parent
9db2ec7537
commit
364d02b90d
@ -157,13 +157,15 @@ Every time the client sends a message, it gets handled by a function in the corr
|
|||||||
(let [stack (fcollect [i (- (length split) 1) 2 -1]
|
(let [stack (fcollect [i (- (length split) 1) 2 -1]
|
||||||
(. split i))]
|
(. split i))]
|
||||||
(case (language.search-assignment self file ref stack {})
|
(case (language.search-assignment self file ref stack {})
|
||||||
{: definition}
|
({: definition} file)
|
||||||
(case (values definition (type definition))
|
(case (values definition (type definition))
|
||||||
(_str :string) (icollect [k _ (pairs string)]
|
(_str :string) (icollect [label _ (pairs string)]
|
||||||
{:label k :kind kinds.Field})
|
{: label :kind kinds.Field})
|
||||||
(tbl :table) (icollect [k _ (pairs tbl)]
|
(tbl :table) (icollect [label _ (pairs tbl)]
|
||||||
(if (= (type k) :string)
|
(if (= (type label) :string)
|
||||||
{:label k :kind kinds.Field})))
|
(case (language.search self file tbl [label] {})
|
||||||
|
def (formatter.completion-item-format label def)
|
||||||
|
_ {: label :kind kinds.Field}))))
|
||||||
_ nil))))
|
_ nil))))
|
||||||
|
|
||||||
(λ create-completion-item [self file name scope]
|
(λ create-completion-item [self file name scope]
|
||||||
|
|||||||
@ -98,7 +98,7 @@ the data provided by compiler.fnl."
|
|||||||
(sym? item) (search-symbol self file item stack opts)
|
(sym? item) (search-symbol self file item stack opts)
|
||||||
(list? item) (search-list self file item stack opts)
|
(list? item) (search-list self file item stack opts)
|
||||||
(= :table (type item)) (search-table self file item stack opts)
|
(= :table (type item)) (search-table self file item stack opts)
|
||||||
(= 0 (length stack)) {:definition item}))) ;; BASE CASE !!
|
(= 0 (length stack)) (values {:definition item} file)))) ;; BASE CASE !!
|
||||||
;; (error (.. "I don't know what to do with " (view item))))))
|
;; (error (.. "I don't know what to do with " (view item))))))
|
||||||
|
|
||||||
(local {:metadata METADATA
|
(local {:metadata METADATA
|
||||||
|
|||||||
@ -192,25 +192,25 @@
|
|||||||
(is.same (type completion.label) :string "unlabeled completion")
|
(is.same (type completion.label) :string "unlabeled completion")
|
||||||
(is.same (type completion.kind) :number (.. completion.label " needs a kind"))
|
(is.same (type completion.kind) :number (.. completion.label " needs a kind"))
|
||||||
(is.same (type completion.documentation) :table (.. completion.label " needs documentation"))
|
(is.same (type completion.documentation) :table (.. completion.label " needs documentation"))
|
||||||
(is.not.same completion.documentation :nil (.. completion.label " needs documentation"))))))))
|
(is.not.same completion.documentation :nil (.. completion.label " needs documentation"))))))
|
||||||
|
|
||||||
; (it "offers rich information about fields"
|
(it "offers rich information about fields"
|
||||||
; (let [client (doto (create-client)
|
(let [client (doto (create-client)
|
||||||
; (: :open-file! filename "(let [x (fn x [a b c] \"\"\"docstring\"\"\" nil)\n t {: x}]\n (t."))
|
(: :open-file! filename "(let [x (fn x [a b c] \"\"\"docstring\"\"\" nil)\n t {: x}]\n (t."))
|
||||||
; [{:result completions}] (client:completion filename 2 5)
|
[{:result completions}] (client:completion filename 2 5)
|
||||||
; _ (table.sort completions #(< $1.label $2.label))
|
_ (table.sort completions #(< $1.label $2.label))
|
||||||
; missing-docs (icollect [_ completion (ipairs completions)]
|
missing-docs (icollect [_ completion (ipairs completions)]
|
||||||
; (if (not (and (= (type completion.label) :string)
|
(if (not (and (= (type completion.label) :string)
|
||||||
; (= (type completion.kind) :number)
|
(= (type completion.kind) :number)
|
||||||
; (= (type completion.documentation) :table)))
|
(= (type completion.documentation) :table)))
|
||||||
; completion.label))
|
completion.label))
|
||||||
; allowed-missing-docs {}]
|
allowed-missing-docs {}]
|
||||||
; (each [_ completion (ipairs completions)]
|
(each [_ completion (ipairs completions)]
|
||||||
; (when (not (. allowed-missing-docs completion.label))
|
(when (not (. allowed-missing-docs completion.label))
|
||||||
; (is.same (type completion.label) :string "unlabeled completion")
|
(is.same (type completion.label) :string "unlabeled completion")
|
||||||
; (is.same (type completion.kind) :number (.. completion.label " needs a kind"))
|
(is.same (type completion.kind) :number (.. completion.label " needs a kind"))
|
||||||
; (is.same (type completion.documentation) :table (.. completion.label " needs documentation"))
|
(is.same (type completion.documentation) :table (.. completion.label " needs documentation"))
|
||||||
; (is.not.same completion.documentation :nil (.. completion.label " needs documentation"))))))))
|
(is.not.same completion.documentation :nil (.. completion.label " needs documentation"))))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user