-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Offer completion for
#nullable enable|disable
(#31171)
- Loading branch information
Showing
10 changed files
with
250 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/EditorFeatures/CSharpTest2/Recommendations/EnableKeywordRecommenderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Test.Utilities; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Recommendations | ||
{ | ||
[Trait(Traits.Feature, Traits.Features.KeywordRecommending)] | ||
public class EnableKeywordRecommenderTests : KeywordRecommenderTests | ||
{ | ||
[Fact] | ||
[WorkItem(31130, "https://github.com/dotnet/roslyn/issues/31130")] | ||
public async Task TestAfterNullable() | ||
{ | ||
await VerifyKeywordAsync(@"#nullable $$"); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(31130, "https://github.com/dotnet/roslyn/issues/31130")] | ||
public async Task TestNotAfterNullableAndNewline() | ||
{ | ||
await VerifyAbsenceAsync(@" | ||
#nullable | ||
$$ | ||
"); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(31130, "https://github.com/dotnet/roslyn/issues/31130")] | ||
public async Task TestNotAfterHash() | ||
{ | ||
await VerifyAbsenceAsync(@"#$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAtRoot_Interactive() | ||
{ | ||
await VerifyAbsenceAsync(SourceCodeKind.Script, @"$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterClass_Interactive() | ||
{ | ||
await VerifyAbsenceAsync(SourceCodeKind.Script, | ||
@"class C { } | ||
$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterGlobalStatement_Interactive() | ||
{ | ||
await VerifyAbsenceAsync(SourceCodeKind.Script, | ||
@"System.Console.WriteLine(); | ||
$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterGlobalVariableDeclaration_Interactive() | ||
{ | ||
await VerifyAbsenceAsync(SourceCodeKind.Script, | ||
@"int i = 0; | ||
$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotInUsingAlias() | ||
{ | ||
await VerifyAbsenceAsync(@"using Goo = $$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotInEmptyStatement() | ||
{ | ||
await VerifyAbsenceAsync(AddInsideMethod(@"$$")); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterPragma() | ||
{ | ||
await VerifyAbsenceAsync(@"#pragma $$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterPragmaWarning() | ||
{ | ||
await VerifyAbsenceAsync(@"#pragma warning $$"); | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/EditorFeatures/CSharpTest2/Recommendations/NullableKeywordRecommenderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Recommendations | ||
{ | ||
[Trait(Traits.Feature, Traits.Features.KeywordRecommending)] | ||
public class NullableKeywordRecommenderTests : KeywordRecommenderTests | ||
{ | ||
[Fact] | ||
public async Task TestNotAtRoot_Interactive() | ||
{ | ||
await VerifyAbsenceAsync(SourceCodeKind.Script, | ||
@"$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterClass_Interactive() | ||
{ | ||
await VerifyAbsenceAsync(SourceCodeKind.Script, | ||
@"class C { } | ||
$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterGlobalStatement_Interactive() | ||
{ | ||
await VerifyAbsenceAsync(SourceCodeKind.Script, | ||
@"System.Console.WriteLine(); | ||
$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterGlobalVariableDeclaration_Interactive() | ||
{ | ||
await VerifyAbsenceAsync(SourceCodeKind.Script, | ||
@"int i = 0; | ||
$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotInUsingAlias() | ||
{ | ||
await VerifyAbsenceAsync( | ||
@"using Goo = $$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotInEmptyStatement() | ||
{ | ||
await VerifyAbsenceAsync(AddInsideMethod( | ||
@"$$")); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAfterHash() | ||
{ | ||
await VerifyKeywordAsync( | ||
@"#$$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAfterHashAndSpace() | ||
{ | ||
await VerifyKeywordAsync( | ||
@"# $$"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestNotAfterHashAndNullable() | ||
{ | ||
await VerifyAbsenceAsync( | ||
@"#nullable $$"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Features/CSharp/Portable/Completion/KeywordRecommenders/EnableKeywordRecommender.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading; | ||
using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders | ||
{ | ||
internal class EnableKeywordRecommender : AbstractSyntacticSingleKeywordRecommender | ||
{ | ||
public EnableKeywordRecommender() | ||
: base(SyntaxKind.EnableKeyword, isValidInPreprocessorContext: true) | ||
{ | ||
} | ||
|
||
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken) | ||
{ | ||
var previousToken1 = context.TargetToken; | ||
var previousToken2 = previousToken1.GetPreviousToken(includeSkipped: true); | ||
|
||
// # nullable | | ||
// # nullable e| | ||
return previousToken1.Kind() == SyntaxKind.NullableKeyword && | ||
previousToken2.Kind() == SyntaxKind.HashToken; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Features/CSharp/Portable/Completion/KeywordRecommenders/NullableKeywordRecommender.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading; | ||
using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders | ||
{ | ||
internal class NullableKeywordRecommender : AbstractSyntacticSingleKeywordRecommender | ||
{ | ||
public NullableKeywordRecommender() | ||
: base(SyntaxKind.NullableKeyword, isValidInPreprocessorContext: true) | ||
{ | ||
} | ||
|
||
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken) | ||
=> context.IsPreProcessorKeywordContext; | ||
} | ||
} |