Skip to content

Commit 1ac579c

Browse files
committed
Do not suggest 'nullable' keyword in pragma directive
1 parent dc87952 commit 1ac579c

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

src/EditorFeatures/CSharpTest2/Recommendations/NullableKeywordRecommenderTests.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable disable
6-
75
using System.Threading.Tasks;
86
using Microsoft.CodeAnalysis.Test.Utilities;
7+
using Roslyn.Test.Utilities;
98
using Xunit;
109

1110
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Recommendations
@@ -95,19 +94,22 @@ public async Task TestNotAfterPragmaWarning()
9594
=> await VerifyAbsenceAsync(@"#pragma warning $$");
9695

9796
[Fact]
98-
public async Task TestAfterPragmaWarningDisable()
99-
=> await VerifyKeywordAsync(@"#pragma warning disable $$");
97+
[WorkItem(63594, "https://github.com/dotnet/roslyn/issues/63594")]
98+
public async Task TestNotAfterPragmaWarningDisable()
99+
=> await VerifyAbsenceAsync(@"#pragma warning disable $$");
100100

101101
[Fact]
102-
public async Task TestAfterPragmaWarningEnable()
103-
=> await VerifyKeywordAsync(@"#pragma warning enable $$");
102+
[WorkItem(63594, "https://github.com/dotnet/roslyn/issues/63594")]
103+
public async Task TestNotAfterPragmaWarningEnable()
104+
=> await VerifyAbsenceAsync(@"#pragma warning enable $$");
104105

105106
[Fact]
106-
public async Task TestAfterPragmaWarningRestore()
107-
=> await VerifyKeywordAsync(@"#pragma warning restore $$");
107+
[WorkItem(63594, "https://github.com/dotnet/roslyn/issues/63594")]
108+
public async Task TestNotAfterPragmaWarningRestore()
109+
=> await VerifyAbsenceAsync(@"#pragma warning restore $$");
108110

109111
[Fact]
110-
public async Task TestAfterPragmaWarningSafeOnly()
112+
public async Task TestNotAfterPragmaWarningSafeOnly()
111113
=> await VerifyAbsenceAsync(@"#pragma warning safeonly $$");
112114

113115
[Fact]

src/Features/CSharp/Portable/Completion/KeywordRecommenders/NullableKeywordRecommender.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable disable
6-
75
using System.Threading;
86
using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery;
97

@@ -17,25 +15,6 @@ public NullableKeywordRecommender()
1715
}
1816

1917
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
20-
{
21-
// #nullable
22-
if (context.IsPreProcessorKeywordContext)
23-
{
24-
return true;
25-
}
26-
27-
var previousToken1 = context.TargetToken;
28-
var previousToken2 = previousToken1.GetPreviousToken(includeSkipped: true);
29-
var previousToken3 = previousToken2.GetPreviousToken(includeSkipped: true);
30-
var previousToken4 = previousToken3.GetPreviousToken(includeSkipped: true);
31-
32-
return
33-
// # pragma warning <action> |
34-
(previousToken1.Kind() == SyntaxKind.DisableKeyword || previousToken1.Kind() == SyntaxKind.RestoreKeyword ||
35-
previousToken1.Kind() == SyntaxKind.EnableKeyword) &&
36-
previousToken2.Kind() == SyntaxKind.WarningKeyword &&
37-
previousToken3.Kind() == SyntaxKind.PragmaKeyword &&
38-
previousToken4.Kind() == SyntaxKind.HashToken;
39-
}
18+
=> context.IsPreProcessorKeywordContext;
4019
}
4120
}

0 commit comments

Comments
 (0)