small refactor
This commit is contained in:
parent
40605c7bcb
commit
e22f2bba01
@ -1,8 +1,8 @@
|
|||||||
# Creating a new lint
|
# Creating a new lint
|
||||||
To start, you can set up all the plumbing:
|
To start, you can set up all the plumbing:
|
||||||
|
|
||||||
1. Go into `src/fennel-ls/diagnostics.fnl` and create a new function.
|
1. Go into `src/fennel-ls/lint.fnl` and create a new function.
|
||||||
2. At the bottom of `src/fennel-ls/diagnostics.fnl`, add an if statement in the
|
2. At the bottom of `src/fennel-ls/lint.fnl`, add an if statement in the
|
||||||
`check` function.
|
`check` function.
|
||||||
* Choose which `each` loop to put your function in, so your lint can be
|
* Choose which `each` loop to put your function in, so your lint can be
|
||||||
applied to right thing.
|
applied to right thing.
|
||||||
|
|||||||
@ -233,6 +233,7 @@ identifiers are declared / referenced in which places."
|
|||||||
(or (= 1 (msg:find "unknown identifier"))
|
(or (= 1 (msg:find "unknown identifier"))
|
||||||
(= 1 (msg:find "local %S+ was overshadowed by a special form or macro"))
|
(= 1 (msg:find "local %S+ was overshadowed by a special form or macro"))
|
||||||
(= 1 (msg:find "expected var "))
|
(= 1 (msg:find "expected var "))
|
||||||
|
(= 1 (msg:find "expected local "))
|
||||||
(= 1 (msg:find "cannot call literal value"))
|
(= 1 (msg:find "cannot call literal value"))
|
||||||
(= 1 (msg:find "unexpected vararg"))
|
(= 1 (msg:find "unexpected vararg"))
|
||||||
(= 1 (msg:find "expected closing delimiter"))
|
(= 1 (msg:find "expected closing delimiter"))
|
||||||
|
|||||||
@ -132,7 +132,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
|||||||
(λ make-completion-item [self file name scope]
|
(λ make-completion-item [self file name scope]
|
||||||
(case (language.search-name-and-scope self file name scope)
|
(case (language.search-name-and-scope self file name scope)
|
||||||
def (formatter.completion-item-format name def)
|
def (formatter.completion-item-format name def)
|
||||||
_ {:label name :textEdit {:newText name}}))
|
_ {:label name}))
|
||||||
|
|
||||||
(λ scope-completion [self file byte ?symbol parents]
|
(λ scope-completion [self file byte ?symbol parents]
|
||||||
(let [scope (or (accumulate [result nil
|
(let [scope (or (accumulate [result nil
|
||||||
@ -162,7 +162,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
|||||||
(case (values definition (type definition))
|
(case (values definition (type definition))
|
||||||
;; fields of a string are hardcoded to "string"
|
;; fields of a string are hardcoded to "string"
|
||||||
(_str :string) (icollect [label _ (pairs string)]
|
(_str :string) (icollect [label _ (pairs string)]
|
||||||
{: label :kind kinds.Field :textEdit {:newText label}})
|
{: label :kind kinds.Field})
|
||||||
;; fields of a table
|
;; fields of a table
|
||||||
(tbl :table) (let [keys []]
|
(tbl :table) (let [keys []]
|
||||||
(icollect [label _ (pairs tbl) &into keys]
|
(icollect [label _ (pairs tbl) &into keys]
|
||||||
@ -174,7 +174,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
|||||||
(if (= (type label) :string)
|
(if (= (type label) :string)
|
||||||
(case (language.search-ast self file tbl [label] {})
|
(case (language.search-ast self file tbl [label] {})
|
||||||
def (formatter.completion-item-format label def)
|
def (formatter.completion-item-format label def)
|
||||||
_ {: label :kind kinds.Field :textEdit {:newText label}})))))
|
_ {: label :kind kinds.Field})))))
|
||||||
{: metadata : fields}
|
{: metadata : fields}
|
||||||
(icollect [label info (pairs fields)]
|
(icollect [label info (pairs fields)]
|
||||||
(formatter.completion-item-format label info))
|
(formatter.completion-item-format label info))
|
||||||
@ -192,16 +192,16 @@ Every time the client sends a message, it gets handled by a function in the corr
|
|||||||
?completions (scope-completion self file byte ?symbol parents)]
|
?completions (scope-completion self file byte ?symbol parents)]
|
||||||
(if ?completions
|
(if ?completions
|
||||||
(each [_ completion (ipairs ?completions)]
|
(each [_ completion (ipairs ?completions)]
|
||||||
(set completion.textEdit.range input-range)))
|
(set completion.textEdit {:newText completion.label :range input-range})))
|
||||||
?completions)
|
?completions)
|
||||||
|
|
||||||
;; completion from field
|
;; completion from field
|
||||||
[_a _b &as split]
|
[_a _b &as split]
|
||||||
(let [input-range (message.multisym->range self file ?symbol -1)
|
(let [input-range (message.multisym->range self file ?symbol -1)
|
||||||
?completions (field-completion self file ?symbol split input-range)]
|
?completions (field-completion self file ?symbol split)]
|
||||||
(if ?completions
|
(if ?completions
|
||||||
(each [_ completion (ipairs ?completions)]
|
(each [_ completion (ipairs ?completions)]
|
||||||
(set completion.textEdit.range input-range)))
|
(set completion.textEdit {:newText completion.label :range input-range})))
|
||||||
?completions))))
|
?completions))))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -121,7 +121,6 @@ the `file.diagnostics` field, filling it with diagnostics."
|
|||||||
:quickfix #[{:range (message.ast->range self file call)
|
:quickfix #[{:range (message.ast->range self file call)
|
||||||
:newText (view identity)}]}))))
|
:newText (view identity)}]}))))
|
||||||
|
|
||||||
|
|
||||||
(λ multival-in-middle-of-call [self file fun call arg index]
|
(λ multival-in-middle-of-call [self file fun call arg index]
|
||||||
"generally, values and unpack are signs that the user is trying to do
|
"generally, values and unpack are signs that the user is trying to do
|
||||||
something with multiple values. However, multiple values will get
|
something with multiple values. However, multiple values will get
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user