Skip to content

Commit

Permalink
Merge pull request #54493 from MaStr11/TypeCompletionAfterLocalFuncti…
Browse files Browse the repository at this point in the history
…onKeywords

Completion: Suggest types after keywords indicating a local function
  • Loading branch information
CyrusNajmabadi committed Jul 28, 2021
2 parents e5eb961 + 2dd919e commit e36e194
Show file tree
Hide file tree
Showing 38 changed files with 390 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,99 @@ void M(String parameter)
await VerifyItemIsAbsentAsync(markup, "parameter");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
public async Task AfterStaticLocalFunction_TypeOnly()
{
var markup = @"
using System;
class C
{
void M(String parameter)
{
static $$
}
}
";
await VerifyItemExistsAsync(markup, "String");
await VerifyItemIsAbsentAsync(markup, "parameter");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.Completion)]
[InlineData("extern")]
[InlineData("static extern")]
[InlineData("extern static")]
[InlineData("async")]
[InlineData("static async")]
[InlineData("async static")]
[InlineData("unsafe")]
[InlineData("static unsafe")]
[InlineData("unsafe static")]
[InlineData("async unsafe")]
[InlineData("unsafe async")]
[InlineData("unsafe extern")]
[InlineData("extern unsafe")]
[InlineData("extern unsafe async static")]
public async Task AfterLocalFunction_TypeOnly(string keyword)
{
var markup = $@"
using System;
class C
{{
void M(String parameter)
{{
{keyword} $$
}}
}}
";
await VerifyItemExistsAsync(markup, "String");
await VerifyItemIsAbsentAsync(markup, "parameter");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
public async Task NotAfterAsyncLocalFunctionWithTwoAsyncs()
{
var markup = @"
using System;
class C
{
void M(String parameter)
{
async async $$
}
}
";
await VerifyItemIsAbsentAsync(markup, "String");
await VerifyItemIsAbsentAsync(markup, "parameter");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.Completion)]
[InlineData("void")]
[InlineData("string")]
[InlineData("String")]
[InlineData("(int, int)")]
[InlineData("async void")]
[InlineData("async System.Threading.Tasks.Task")]
[InlineData("int Function")]
public async Task NotAfterReturnTypeInLocalFunction(string returnType)
{
var markup = @$"
using System;
class C
{{
void M(String parameter)
{{
static {returnType} $$
}}
}}
";
await VerifyItemIsAbsentAsync(markup, "String");
await VerifyItemIsAbsentAsync(markup, "parameter");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(25569, "https://github.com/dotnet/roslyn/issues/25569")]
public async Task AfterRefInMemberContext_TypeOnly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,51 @@ public void M()
await VerifyProviderCommitAsync(markup, "C", expected, commitChar: commitChar, sourceCodeKind: SourceCodeKind.Regular);
}

[InlineData(SourceCodeKind.Regular)]
[InlineData(SourceCodeKind.Script)]
[WpfTheory, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(54493, "https://github.com/dotnet/roslyn/issues/54493")]
public async Task CommitInLocalFunctionContext(SourceCodeKind kind)
{
var markup = @"
namespace Foo
{
public class MyClass { }
}
namespace Test
{
class Program
{
public static void Main()
{
static $$
}
}
}";

var expectedCodeAfterCommit = @"
using Foo;
namespace Foo
{
public class MyClass { }
}
namespace Test
{
class Program
{
public static void Main()
{
static MyClass
}
}
}";

await VerifyProviderCommitAsync(markup, "MyClass", expectedCodeAfterCommit, commitChar: null, sourceCodeKind: kind);
}

private Task VerifyTypeImportItemExistsAsync(string markup, string expectedItem, int glyph, string inlineDescription, string displayTextSuffix = null, string expectedDescriptionOrNull = null, CompletionItemFlags? flags = null)
=> VerifyItemExistsAsync(markup, expectedItem, displayTextSuffix: displayTextSuffix, glyph: glyph, inlineDescription: inlineDescription, expectedDescriptionOrNull: expectedDescriptionOrNull, isComplexTextEdit: true, flags: flags);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3477,6 +3477,36 @@ static void Main(string[] args)
}
}
internal class Goo
{
}",
index: 1);
}

[WorkItem(54493, "https://github.com/dotnet/roslyn/pull/54493")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public async Task TestInLocalFunction()
{
await TestInRegularAndScriptAsync(
@"using System;
class Program
{
static void Main(string[] args)
{
static [|Goo|]
}
}",
@"using System;
class Program
{
static void Main(string[] args)
{
static Goo
}
}
internal class Goo
{
}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,5 +783,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -784,5 +784,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -813,5 +813,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -777,5 +777,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,19 @@ public async Task TestNotAfterSealed()
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestAfterStatic()
{
await VerifyAbsenceAsync(SourceCodeKind.Regular, @"static $$");
await VerifyKeywordAsync(SourceCodeKind.Regular, @"static $$");
await VerifyKeywordAsync(SourceCodeKind.Script, @"static $$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(SourceCodeKind.Regular, AddInsideMethod(@$"{keyword} $$"));
await VerifyKeywordAsync(SourceCodeKind.Script, AddInsideMethod(@$"{keyword} $$"));
}

[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestAfterStaticPublic()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,5 +761,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -734,5 +734,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -848,5 +848,14 @@ public async Task TestInMixedDeclarationAndAssignmentInDeconstruction()
await VerifyKeywordAsync(AddInsideMethod(
@"(x, $$) = (0, 0);"));
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -761,5 +761,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Recommendations
Expand Down Expand Up @@ -299,5 +300,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -782,5 +782,14 @@ public async Task TestInMixedDeclarationAndAssignmentInDeconstruction()
await VerifyKeywordAsync(AddInsideMethod(
@"(x, $$) = (0, 0);"));
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -761,5 +761,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -757,5 +757,14 @@ class C
{
delegate*$$");
}

[WorkItem(53585, "https://github.com/dotnet/roslyn/issues/53585")]
[Theory, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[ClassData(typeof(TheoryDataKeywordsIndicatingLocalFunction))]
public async Task TestAfterKeywordIndicatingLocalFunction(string keyword)
{
await VerifyKeywordAsync(AddInsideMethod($@"
{keyword} $$"));
}
}
}
Loading

0 comments on commit e36e194

Please sign in to comment.