Resolve atom-dispatched use chains across LSP features - #92
Merged
Conversation
The Phoenix entrypoint form injects nothing itself. It dispatches on an
atom to a sibling function whose body is a `quote do`:
defmacro __using__(which) when is_atom(which), do: apply(__MODULE__, which, [])
def controller do
quote do
import Plug.Conn
end
end
`parseUsingBody` saw an empty body and gave up, so nothing injected by
these blocks resolved. That is 126 `use` sites in Plausible and 305 in
our own monorepo.
Nothing here is inferred. The consumer writes a literal atom, `__MODULE__`
is the file already being parsed, and the target is a `def` of that name in
that file. `usingDispatchParam` gates on apply/3 targeting `__MODULE__` and
dispatching on the clause's own parameter; `parseDispatchBodies` then parses
each `def name do quote do ... end end` into its own `usingBody`, keyed by
name. `entry.bodyFor(which)` selects one at lookup time from the literal
atom, so targets never merge — a `:controller` consumer cannot see `:view`'s
imports. An atom naming no target injects nothing.
Every gate that fails returns what it returns today, so this only adds
resolutions.
The token walker cannot evaluate conditionals, so a `use` inside a
compile-time branch (`on_ee do use X end`) is included unconditionally.
That over-includes candidate names and never removes one, matching how
the indexer already attributes a bare call to every used module.
`findModulesWhoseUsingImports` now scans dispatch bodies too, so
find-references reaches call sites that got their import this way.
No IndexVersion bump: this is all LSP-layer extraction, and the parser
output and store schema are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
use MyAppWeb, :controllerunquote(html_helpers())