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

Fix completion in out-var with variable directly declared after #66755

Merged
merged 1 commit into from
Feb 8, 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 @@ -11070,5 +11070,28 @@ class Program
Await state.AssertCompletionItemsContain("string", displayTextSuffix:="")
End Using
End Function

<WpfTheory, CombinatorialData, WorkItem(21055, "https://github.com/dotnet/roslyn/issues/21055")>
Public Async Function CompletionInOutParamWithVariableDirectlyAfter(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document>
class Program
{
static void Main(string[] args)
{
if (TryParse("", out $$

Program p = null;
}

static bool TryParse(string s, out Program p) { }
}
</Document>,
showCompletionInArgumentLists:=showCompletionInArgumentLists, languageVersion:=LanguageVersion.Preview)

state.SendTypeChars("P")
Await state.AssertSelectedCompletionItem(displayText:="Program", isHardSelected:=True)
End Using
End Function
End Class
End Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,23 @@ private ImmutableArray<ISymbol> GetSymbolsForExpressionOrStatementContext()
//
// i // <-- here
// I = 0;

//
// The problem is that "i I = 0" causes a local to be in scope called "I". So, later when
// we look up symbols, it masks any other 'I's in scope (i.e. if there's a field with that
// name). If this is the case, we do not want to filter out inaccessible locals.
//
// Similar issue for out-vars. Like:
//
// if (TryParse("", out // <-- here
// X x = null;
var filterOutOfScopeLocals = _filterOutOfScopeLocals;
if (filterOutOfScopeLocals)
filterOutOfScopeLocals = !_context.LeftToken.GetRequiredParent().IsFoundUnder<LocalDeclarationStatementSyntax>(d => d.Declaration.Type);
{
var contextNode = _context.LeftToken.GetRequiredParent();
filterOutOfScopeLocals =
!contextNode.IsFoundUnder<LocalDeclarationStatementSyntax>(d => d.Declaration.Type) &&
!contextNode.IsFoundUnder<DeclarationExpressionSyntax>(d => d.Type);
}

var symbols = !_context.IsNameOfContext && _context.LeftToken.GetRequiredParent().IsInStaticContext()
? _context.SemanticModel.LookupStaticMembers(_context.LeftToken.SpanStart)
Expand All @@ -246,9 +256,7 @@ private ImmutableArray<ISymbol> GetSymbolsForExpressionOrStatementContext()
// should not be included in the completion list, so remove those. Filter them away,
// unless we're in the debugger, where we show all locals in scope.
if (filterOutOfScopeLocals)
{
symbols = symbols.WhereAsArray(symbol => !symbol.IsInaccessibleLocal(_context.Position));
}

return symbols;
}
Expand Down