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.
there should now be no cases where multivals and table destructures are
confused. ie, (local [_ x] (values 1 2)) and (local (_ x) [1 2]) are recognized
as nonsense.
Now unused variables and var-not-set lints use a different system.
References are now of type:
{:symbol sym :target ast :ref-type (or :read :write :mutate)}
instead of ast.
unused var will warn if all the references are :write references.
They'll look like this now:
src/fennel-ls/compiler.fnl:123:15 unused definition: ?definition
src/fennel-ls/compiler.fnl:5:52 unused definition: view
src/fennel-ls/compiler.fnl:197:13 unused definition: i
src/fennel-ls/compiler.fnl:271:25 unnecessary : call; use multisym
src/fennel-ls/handlers.fnl:14:10 unused definition: view
src/fennel-ls/handlers.fnl:170:3 unused definition: create-completion-item
src/fennel-ls/language.fnl:187:3 unused definition: does-not-contain?
src/fennel-ls/language.fnl:221:28 unused definition: i
src/fennel-ls/language.fnl:4:51 unused definition: view
src/fennel-ls/language.fnl:171:3 unused definition: past?
src/fennel-ls/language.fnl:208:23 unused definition: i
src/fennel-ls/searcher.fnl:12:4 unnecessary : call; use multisym
src/fennel-ls/state.fnl:23:3 unused definition: get-by-path
src/fennel-ls/state.fnl:12:2 unnecessary : call; use multisym
src/fennel-ls/utils.fnl:15:16 unused definition: i
This has the advantage of making it so that existing tooling will work
with it; for example, Emacs can hyperlink these and jump right to the
code causing the issue.
Use 1-indexed line numbers instead of 0-indexing because Emacs and Vim
expect this.
Also cleans up repeated path options in the makefile, and cleans up
warnings where fennel-ls warns on itself.
There were some unused functions; I just put a _ before their name but
that might be a bit silly. Maybe they should be removed? Or just left alone?
I kept the test from Tibor Classen's patch, but the code is fixed by
preventing & from ever being a definition, instead of ignoring it only
in the diagnostic.
Co-authored-by: Tibor Claassen <tc@codebeige.net>
This isn't a great fix, but now finding the definition of a number
doesn't cause a crash.
It used to crash because there's no way to get metadata about the
source-code location of a number.
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
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.