Skip to content

Find Usages misses a variable's uses in later EEx tags #3970

Description

@sh41

Find Usages on a variable bound inside an EEx tag does not find its uses in other tags of the same template. Rename is affected the same way, since it searches the same scope.

Reproduce

block.html.eex:

<%= if @ok do %><p>a</p><% total = 1 %><p><%= total %></p><% end %>

Put the caret on total in <% total = 1 %> and invoke Find Usages. The later <%= total %> is not listed.

Go To Declaration from that later total does reach the binding, so the reference itself resolves correctly — only the search for it comes back short.

What is happening

Callable.variableUseScope handles a match whose parent is an ElixirEexTag by returning the match together with its following siblings. Inside a tag those siblings run out at the tag's closing delimiter, so the scope covers that one tag only, and a use in any later tag falls outside it. ReferencesSearch then honours that scope and finds nothing beyond it.

Measured on main: the declaration's use scope comes back as the match operation plus the %> token, and ReferencesSearch from the declaration returns one result — the declaration's own occurrence. The same bind-and-use shape in a plain .ex file returns two, and its scope extends over the use.

The ElixirEexTag case in that method dates from cacfab9119, "Treat EEx tag the same as StabBody for use scope". Treating the two alike is what narrows it: a stab body's following siblings really are the rest of the block, whereas an EEx tag's siblings end at its delimiter while the block itself continues across the tags that follow.

Not the same as the reports it was found next to

#1772, #1831, #1849 and #1851 all reported Don't know how to find variable use scope on an ElixirEexTagImpl, and 85c0951801 fixed that report in v14.0.1. This is a separate defect in a different branch of the same class, it predates that commit, and it produces no error — Find Usages simply returns an incomplete result.


Filed as part of an AI-assisted review of the backlog. A human checked this one before it was filed, but it might still be wrong — if any of it is, please say so here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions