Repository navigation
Handle :local_or_var inside struct dot in SurroundContext.to_binding - #345
Merged
Merged
Conversation
Code.Fragment.surround_context/2 reports the inner identifier of
`%nav.foo{}` as {:local_or_var, ~c"nav"}, but inside_dot_to_binding/2 only
matched {:var, _}, raising FunctionClauseError from the hover provider.
Add {:local_or_var, _} clauses mirroring the {:var, _} ones, including the
__MODULE__ special case.
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
ElixirSense.Core.SurroundContext.to_binding/2crashed with aFunctionClauseErrorwhen the cursor was on a dotted identifier inside a struct literal, e.g.%nav.foo{}.Code.Fragment.surround_context/2reports the inner identifier as{:local_or_var, ~c"nav"}, butinside_dot_to_binding/2only handled{:var, _}, so no clause matched.This PR adds
{:local_or_var, _}clauses that mirror the existing{:var, _}clauses, including the__MODULE__special case.Crash
Repro
Before this change it raises; after it returns
{{:variable, :nav, :any}, :foo}.Other shapes checked
Probed every cursor column for
%nav.foo{},%nav.foo.bar{},%mod.foo.bar{},%foo.bar.baz{},%x.y{a: 1},%__MODULE__.foo{},%__MODULE__.foo.bar{},%@attr.foo{},%@a.b.c{},%Foo.bar{},%Foo.Bar.baz{},%Foo.bar().baz{},%foo().bar{},%(x).foo{},%:erlang.foo{}. The only crashing inner shape was{:local_or_var, _}, which the new clauses cover. The other shapes already return a result.Tests
New
test/elixir_sense/core/surround_context_test.exscovers the repro, the other cursor columns, the nested and__MODULE__variants, and the already-working@attr, alias, and call shapes. Against unmodifiedmaster, 9 of these tests fail.