提交 d5d90830 编写于 作者: C CyrusNajmabadi

Fix no completion in partially written code before 'await'.

上级 0ec6ea3a
......@@ -2058,6 +2058,48 @@ class Program
await VerifyItemExistsAsync(markup, "CompareTo");
}
[WorkItem(21596, "https://github.com/dotnet/roslyn/issues/21596")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task AmbiguityBetweenExpressionAndLocalFunctionReturnType()
{
var markup = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
AwaitTest test = new AwaitTest();
test.Test1().Wait();
}
}
class AwaitTest
{
List<string> stringList = new List<string>();
public async Task<bool> Test1()
{
stringList.$$
await Test2();
return true;
}
public async Task<bool> Test2()
{
return true;
}
}";
await VerifyItemExistsAsync(markup, "Add");
}
[WorkItem(540750, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540750")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task CompletionAfterNewInScript()
......
......@@ -296,13 +296,21 @@ private static ImmutableArray<ISymbol> GetSymbolsForNamespaceDeclarationNameCont
// int i = 5;
// i. // <-- here
// List<string> ml = new List<string>();
//
// The problem is that "i.List<string>" gets parsed as a type. In this case we need
// to try binding again as if "i" is an expression and not a type. In order to do
// that, we need to speculate as to what 'i' meant if it wasn't part of a local
// declaration's type.
//
// Another interesting case is something like:
//
// stringList.
// await Test2();
//
// Here "stringList.await" is thought of as the return type of a local function.
// The problem is that "i.List<string>" gets parsed as a type. In this case we need to
// try binding again as if "i" is an expression and not a type. In order to do that, we
// need to speculate as to what 'i' meant if it wasn't part of a local declaration's
// type.
if (name.IsFoundUnder<LocalDeclarationStatementSyntax>(d => d.Declaration.Type) ||
if (name.IsFoundUnder<LocalFunctionStatementSyntax>(d => d.ReturnType) ||
name.IsFoundUnder<LocalDeclarationStatementSyntax>(d => d.Declaration.Type) ||
name.IsFoundUnder<FieldDeclarationSyntax>(d => d.Declaration.Type))
{
var speculativeBinding = context.SemanticModel.GetSpeculativeSymbolInfo(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册