Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep only first assignment as declaration #1989

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ private AstVisitAction AddReference(SymbolReference symbol)
_ => new ConcurrentBag<SymbolReference> { symbol },
(_, existing) =>
{
// Keep only the first variable encountered as a declaration marked as such. This
// keeps the first assignment without also counting every reassignment as a
// declaration (cleaning up e.g. Code's outline view).
if (symbol.Type is SymbolType.Variable && symbol.IsDeclaration
&& existing.Any(i => i.IsDeclaration))
{
symbol = symbol with { IsDeclaration = false };
}

existing.Add(symbol);
return existing;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function My-Function ($myInput)

$things = 4

$things
$things = 3

My-Function $things

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ public async Task FindsFunctionDefinitionInWorkspace()
[Fact]
public async Task FindsVariableDefinition()
{
SymbolReference symbol = await GetDefinition(FindsVariableDefinitionData.SourceDetails).ConfigureAwait(true);
IEnumerable<SymbolReference> definitions = await GetDefinitions(FindsVariableDefinitionData.SourceDetails).ConfigureAwait(true);
SymbolReference symbol = Assert.Single(definitions); // Even though it's re-assigned
Assert.Equal("var things", symbol.Id);
Assert.Equal("$things", symbol.Name);
Assert.Equal(SymbolType.Variable, symbol.Type);
Expand Down