From e020afedb6de193ef4f7de8a9a429782514ea548 Mon Sep 17 00:00:00 2001 From: Jan Hindermann Date: Sun, 8 Oct 2023 15:57:31 +0200 Subject: [PATCH 1/4] Enable keyword recommender for `scoped` --- .../Completion/CompletionProviders/KeywordCompletionProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/KeywordCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/KeywordCompletionProvider.cs index 9e938692bab6e..4d15a80bbd70c 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/KeywordCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/KeywordCompletionProvider.cs @@ -132,6 +132,7 @@ public KeywordCompletionProvider() new RestoreKeywordRecommender(), new ReturnKeywordRecommender(), new SByteKeywordRecommender(), + new ScopedKeywordRecommender(), new SealedKeywordRecommender(), new SelectKeywordRecommender(), new SetKeywordRecommender(), From 37ac6bcd283d1b9ebe3d9d3ed09802fea8029a04 Mon Sep 17 00:00:00 2001 From: Jan Hindermann Date: Sun, 8 Oct 2023 15:57:47 +0200 Subject: [PATCH 2/4] Use primary constructor --- .../KeywordRecommenders/ScopedKeywordRecommender.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ScopedKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ScopedKeywordRecommender.cs index ded0f3e44fcb0..2ac36bb5c355c 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ScopedKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ScopedKeywordRecommender.cs @@ -11,13 +11,8 @@ namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders { - internal class ScopedKeywordRecommender : AbstractSyntacticSingleKeywordRecommender + internal sealed class ScopedKeywordRecommender() : AbstractSyntacticSingleKeywordRecommender(SyntaxKind.ScopedKeyword) { - public ScopedKeywordRecommender() - : base(SyntaxKind.ScopedKeyword) - { - } - protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken) { var syntaxTree = context.SyntaxTree; From 732c1f8220f538348f63042e632f7123fba8003a Mon Sep 17 00:00:00 2001 From: Jan Hindermann Date: Sun, 8 Oct 2023 15:58:02 +0200 Subject: [PATCH 3/4] Remove unused using directives --- .../Completion/KeywordRecommenders/ScopedKeywordRecommender.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ScopedKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ScopedKeywordRecommender.cs index 2ac36bb5c355c..c9b969516e2e0 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ScopedKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/ScopedKeywordRecommender.cs @@ -4,9 +4,6 @@ using System.Threading; using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; -using System.Collections.Generic; -using Microsoft.CodeAnalysis.CSharp.Utilities; -using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders From 40c23072634d175539c96709bd75e19bce041982 Mon Sep 17 00:00:00 2001 From: Jan Hindermann Date: Sun, 8 Oct 2023 21:28:24 +0200 Subject: [PATCH 4/4] Add test to verify that `scoped` keyword is recommended --- .../CSharpCompletionCommandHandlerTests.vb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb b/src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb index 1893290e1c580..4137a3ac380da 100644 --- a/src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb @@ -11994,5 +11994,22 @@ public class C() : Base($$) Await state.AssertCompletionItemsContain("x", ":") End Using End Function + + + Public Async Function TestScopedKeywordRecommender() As Task + Using state = TestStateFactory.CreateCSharpTestState( + + , + languageVersion:=LanguageVersion.CSharp11) + + state.SendInvokeCompletionList() + Await state.AssertCompletionItemsContain("scoped", "") + End Using + End Function End Class End Namespace