提交 cad6252d 编写于 作者: R Ravi Chande

Show expression completion within casts

Automatic brace completion of "(" parses as a cast, but the user might
be trying to type a parenthesized expression.
上级 d100acf5
......@@ -7898,5 +7898,25 @@ void M(bool x)
VerifyItemExists(markup, "x");
}
[WorkItem(717, "https://github.com/dotnet/roslyn/issues/717")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public void ExpressionContextCompletionWithinCast()
{
var markup = @"
class Program
{
void M()
{
for (int i = 0; i < 5; i++)
{
var x = ($$)
var y = 1;
}
}
}
";
VerifyItemExists(markup, "i");
}
}
}
......@@ -75,8 +75,13 @@ internal class CSharpRecommendationService : AbstractRecommendationService
// Script and interactive
return GetSymbolsForGlobalStatementContext(context, cancellationToken);
}
else if (context.IsAnyExpressionContext || context.IsStatementContext)
else if (context.IsAnyExpressionContext ||
context.IsStatementContext ||
context.SyntaxTree.IsDefiniteCastTypeContext(context.Position, context.LeftToken, cancellationToken))
{
// GitHub #717: With automatic brace completion active, typing '(i' produces "(i)", which gets parsed as
// as cast. The user might be trying to type a parenthesized expression, so even though a cast
// is a type-only context, we'll show all symbols anyway.
return GetSymbolsForExpressionOrStatementContext(context, filterOutOfScopeLocals, cancellationToken);
}
else if (context.IsTypeContext || context.IsNamespaceContext)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册