textDocument/rename Filter out when symbol references itself
When a symbol is recorded to be its own reference, fennel-ls accidentally counts the reference twice. That's fine, but we don't want to replace the same words multiple times
This commit is contained in:
parent
364d02b90d
commit
223976194e
@ -191,11 +191,14 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(let [usages (icollect [_ symbol (ipairs definition.referenced-by)
|
||||
&into [{:range (message.multisym->range self def-file definition.binding 1)
|
||||
:newText new-name}]]
|
||||
{:newText new-name
|
||||
:range (message.multisym->range self def-file symbol 1)})]
|
||||
(if (not (rawequal symbol definition.binding))
|
||||
{:newText new-name
|
||||
:range (message.multisym->range self def-file symbol 1)}))]
|
||||
|
||||
;; NOTE: I don't care about encoding here because we just need the relative positions
|
||||
(table.sort usages #(> (utils.position->byte def-file.text $1.range.start :utf-8)
|
||||
(utils.position->byte def-file.text $2.range.start :utf-8)))
|
||||
(table.sort usages
|
||||
#(> (utils.position->byte def-file.text $1.range.start :utf-8)
|
||||
(utils.position->byte def-file.text $2.range.start :utf-8)))
|
||||
{:changes {def-file.uri usages}})
|
||||
(catch _ nil))))
|
||||
|
||||
|
||||
@ -157,6 +157,17 @@ WARNING: this is only used in the test code, not in the real language server"
|
||||
(λ type= [val typ]
|
||||
(= (type val) typ))
|
||||
|
||||
(λ uniq-by [list eq?]
|
||||
"I know the big O of this is bad, but we'll come back to it if it's a performance problem"
|
||||
(let [result []]
|
||||
(each [_ new-item (ipairs list)]
|
||||
(if (not (accumulate [any? nil
|
||||
_ seen-item (ipairs result)
|
||||
&until any?]
|
||||
(eq? seen-item new-item)))
|
||||
(table.insert result new-item)))
|
||||
result))
|
||||
|
||||
{: uri->path
|
||||
: path->uri
|
||||
: pos->position
|
||||
@ -166,4 +177,5 @@ WARNING: this is only used in the test code, not in the real language server"
|
||||
: apply-edits
|
||||
: multi-sym-split
|
||||
: get-ast-info
|
||||
: uniq-by
|
||||
: type=}
|
||||
|
||||
@ -35,6 +35,8 @@
|
||||
|
||||
(it "renames from destructure/args"
|
||||
(check-rename "(fn [{: x}] x)" 0 8 :foo "(fn [{: foo}] foo)")
|
||||
(check-rename "(fn [{:x x}] x)" 0 9 :foo "(fn [{:x foo}] foo)")))
|
||||
|
||||
(check-rename "(fn [{:x x}] x)" 0 9 :foo "(fn [{:x foo}] foo)"))
|
||||
|
||||
(it "renames a sym inside of lambda"
|
||||
(check-rename "(λ [foo] (print foo))" 0 6 :something
|
||||
"(λ [something] (print something))")))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user