提交 a3d8ab1b 编写于 作者: V vsadov 提交者: VSadov

Making recommenders work better in tuple expression.

Note: we have to conservatively assume that parenthesized expression could also be a tuple in progress.
上级 b6f64e2c
......@@ -391,9 +391,51 @@ static void Main(string[] args)
Console.CancelKeyPress += new ConsoleCancelEventHandler(((a$$
}
}";
await VerifyNotBuilderAsync(markup);
await VerifyBuilderAsync(markup);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task ParenthesizedExpression()
{
var markup = @"using System;
class Program
{
static void Main(string[] args)
{
var x = (a$$
}
}";
await VerifyBuilderAsync(markup);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task TupleExpressionAfterParen()
{
var markup = @"using System;
class Program
{
static void Main(string[] args)
{
var x = (a$$, b)
}
}";
await VerifyBuilderAsync(markup);
}
public async Task TupleExpressionAfterComma()
{
var markup = @"using System;
class Program
{
static void Main(string[] args)
{
var x = (a, b$$)
}
}";
await VerifyBuilderAsync(markup);
}
[WorkItem(546363, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546363")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task BuilderForLinqExpression()
......
......@@ -47,7 +47,9 @@ protected override async Task<CompletionItem> GetBuilderAsync(Document document,
{
return CreateBuilder(text, position, CSharpFeaturesResources.LambdaExpression, CSharpFeaturesResources.AutoselectDisabledDueToPotentialLambdaDeclaration);
}
else if (IsAnonymousObjectCreation(token))
// PROTOTYPE: tuples in this context are very much like a kind of anonymous type
// I wonder if we need a special CSharpFeaturesResources or just generalize the existing one
else if (IsAnonymousObjectCreation(token) || IsPossibleTupleExpression(token))
{
return CreateBuilder(text, position, CSharpFeaturesResources.MemberName, CSharpFeaturesResources.AutoselectDisabledDueToPossibleExplicitlyNamesAnonTypeMemCreation);
}
......@@ -91,6 +93,20 @@ private bool IsAnonymousObjectCreation(SyntaxToken token)
return false;
}
private bool IsPossibleTupleExpression(SyntaxToken token)
{
// first element in an autocompleted tuple will look like a parenthesized expression (foo )
// so we need to conservatively treat parenthesized expression as apotential tuple
if (token.Parent.IsKind(SyntaxKind.TupleExpression, SyntaxKind.ParenthesizedExpression))
{
// We'll show the builder after an open paren or comma, because that's where the
// user can start declaring new named parts.
return token.Kind() == SyntaxKind.OpenParenToken || token.Kind() == SyntaxKind.CommaToken;
}
return false;
}
private bool IsLambdaExpression(SemanticModel semanticModel, int position, SyntaxToken token, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
{
// Typing a generic type parameter, the tree might look like a binary expression around the < token.
......
......@@ -1839,11 +1839,13 @@ public static bool IsLabelContext(this SyntaxTree syntaxTree, int position, Canc
// Foo(|
// Foo(expr, |
// this[|
// var t = (1, |
// var t = (| , 2)
if (token.IsKind(SyntaxKind.OpenParenToken) ||
token.IsKind(SyntaxKind.OpenBracketToken) ||
token.IsKind(SyntaxKind.CommaToken))
{
if (token.Parent.IsKind(SyntaxKind.ArgumentList, SyntaxKind.BracketedArgumentList))
if (token.Parent.IsKind(SyntaxKind.ArgumentList, SyntaxKind.BracketedArgumentList, SyntaxKind.TupleExpression))
{
return true;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册