Fix renames that cover method calls

That was a tough one to debug! I almost thought it was a bug in fennel,
but it, of course, turned out to be a fennel-ls problem.

When you have a symbol like (foo:bar), fennel compiles it by
"macroexpanding" it to (: foo :bar). When fennel macroexpands a macro,
it tries to clean up the output by giving it a best-guess
bytestart/byteend. Fennel-ls was picking up *both* the accurate
`foo:bar` sym and the best-guess virtual `foo` sym as separate
references to `foo`. When computing the renames, the best-guess values
were getting used, which made the replacement range inaccurate.
This commit is contained in:
XeroOl 2024-02-11 23:45:08 -06:00
parent be5e167d67
commit 6f9935a781
3 changed files with 7 additions and 3 deletions

View File

@ -317,8 +317,9 @@ are declared / referenced in which places."
ast (icollect [ok ast parser &until (not ok)] ast)]
(λ collect-everything [ast result]
(when (or (table? ast) (list? ast) (sym? ast))
(tset result ast true))
(when (or (table? ast) (list? ast))
(tset result ast true)
(each [k v (iter ast)]
(collect-everything k result)
(collect-everything v result))))

View File

@ -207,7 +207,8 @@ 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}]]
(if (not (rawequal symbol definition.binding))
(if (and (. file.lexical symbol)
(not (rawequal symbol definition.binding)))
{:newText new-name
:range (message.multisym->range self def-file symbol 1)}))]

View File

@ -31,7 +31,9 @@
(check-rename "(let [old-name {:field 10}] old-name.field)" 0 9 :new-name
"(let [new-name {:field 10}] new-name.field)")
(check-rename "(let [old-name {:field 10}] old-name.field)" 0 30 :new-name
"(let [new-name {:field 10}] new-name.field)"))
"(let [new-name {:field 10}] new-name.field)")
(check-rename "(let [[old-name] [{:field 10}]] (old-name:field 10))" 0 7 :new-name
"(let [[new-name] [{:field 10}]] (new-name:field 10))"))
(it "renames from destructure/args"
(check-rename "(fn [{: x}] x)" 0 8 :foo "(fn [{: foo}] foo)")