fix fennel-ls#22
This is getting messy, but now the same sym can reference multiple places. (. file references mysym) only holds the last one, but (. file definitions <x> :referenced-by) could still hold older references.
This commit is contained in:
parent
5fa5a0a323
commit
311ce2645e
@ -86,14 +86,9 @@ identifiers are declared / referenced in which places."
|
||||
;; find reference
|
||||
(let [name (string.match (tostring symbol) "[^%.:]+")]
|
||||
(case (find-definition (tostring name) scope)
|
||||
target
|
||||
(if (. references symbol)
|
||||
(do ;; already exists
|
||||
(assert (= symbol (. references symbol :symbol)) (.. "the symbol should always be the same")))
|
||||
;; (assert (= target (. references symbol :target)) (.. "different targets: " (view target) (view (. references symbol :target)))))
|
||||
(let [ref {: symbol : target : ref-type}]
|
||||
(tset references symbol ref)
|
||||
(table.insert target.referenced-by ref))))))
|
||||
target (let [ref {: symbol : target : ref-type}]
|
||||
(tset references symbol ref)
|
||||
(table.insert target.referenced-by ref)))))
|
||||
|
||||
(λ symbol-to-expression [ast scope ?reference?]
|
||||
(assert (sym? ast) "symbols only")
|
||||
|
||||
@ -226,7 +226,13 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(table.sort usages
|
||||
#(> (utils.position->byte definition.file.text $1.range.start :utf-8)
|
||||
(utils.position->byte definition.file.text $2.range.start :utf-8)))
|
||||
{:changes {definition.file.uri usages}})
|
||||
(var prev {})
|
||||
(let [usages-dedup (icollect [_ edit (ipairs usages)]
|
||||
(when (or (not= edit.range.start.line prev.line)
|
||||
(not= edit.range.start.character prev.character))
|
||||
(set prev edit.range.start)
|
||||
edit))]
|
||||
{:changes {definition.file.uri usages-dedup}}))
|
||||
(catch _ nil))))
|
||||
|
||||
(fn pos<= [pos-1 pos-2]
|
||||
|
||||
@ -121,9 +121,6 @@ the `file.diagnostics` field, filling it with diagnostics."
|
||||
:quickfix #[{:range (message.ast->range self file call)
|
||||
:newText (view identity)}]}))))
|
||||
|
||||
; (fn quickfix.op-with-no-arguments [item]
|
||||
; {:range item.range
|
||||
; :newText (tostring item.data)})
|
||||
|
||||
(λ multival-in-middle-of-call [self file fun call arg index]
|
||||
"generally, values and unpack are signs that the user is trying to do
|
||||
|
||||
@ -58,6 +58,7 @@
|
||||
:end {:character 6 :line 0}}}] [])
|
||||
;; setting a field without reading is okay
|
||||
(check "(fn [a b] (set a.x 10) (fn b.f []))" [] [{}])
|
||||
(check "(case {:b 1} (where (or {:a x} {:b x})) x)" [] [{}])
|
||||
nil)
|
||||
|
||||
(fn test-ampersand []
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
(check "(fn [{:x x|}] x)" :foo
|
||||
"(fn [{:x foo}] foo)")
|
||||
|
||||
;; issue fennel-ls#8
|
||||
(check "(λ [foo|] (print foo))" :something
|
||||
"(λ [something] (print something))")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user