diff --git a/src/EditorFeatures/CSharpTest/Classification/AbstractCSharpClassifierTests.cs b/src/EditorFeatures/CSharpTest/Classification/AbstractCSharpClassifierTests.cs index 20479759207ee..f7570e05680aa 100644 --- a/src/EditorFeatures/CSharpTest/Classification/AbstractCSharpClassifierTests.cs +++ b/src/EditorFeatures/CSharpTest/Classification/AbstractCSharpClassifierTests.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.UnitTests; using Microsoft.CodeAnalysis.Editor.UnitTests.Classification; @@ -14,12 +13,30 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Classification; public abstract class AbstractCSharpClassifierTests : AbstractClassifierTests { - protected static EditorTestWorkspace CreateWorkspace(string code, ParseOptions options, TestHost testHost) + protected static EditorTestWorkspace CreateWorkspace( + string code, ParseOptions? options, TestHost testHost) { var composition = EditorTestCompositions.EditorFeatures.WithTestHostParts(testHost); return EditorTestWorkspace.CreateCSharp(code, parseOptions: options, composition: composition, isMarkup: false); } + protected new Task TestAsync( + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string code, + TestHost testHost, + params FormattedClassification[] expected) + { + return base.TestAsync(code, testHost, expected); + } + + protected new Task TestAsync( + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string code, + TestHost testHost, + ParseOptions? parseOptions, + params FormattedClassification[] expected) + { + return base.TestAsync(code, testHost, parseOptions, expected); + } + protected override async Task DefaultTestAsync(string code, string allCode, TestHost testHost, FormattedClassification[] expected) { await TestAsync(code, allCode, testHost, parseOptions: null, expected); @@ -27,27 +44,35 @@ protected override async Task DefaultTestAsync(string code, string allCode, Test } protected override string WrapInClass(string className, string code) -=> $@"class {className} {{ - {code} -}}"; + => $$""" + class {{className}} { + {{code}} + } + """; protected override string WrapInExpression(string code) -=> $@"class C {{ - void M() {{ - var q = - {code} - }} -}}"; + => $$""" + class C { + void M() { + var q = + {{code}} + } + } + """; protected override string WrapInMethod(string className, string methodName, string code) -=> $@"class {className} {{ - void {methodName}() {{ - {code} - }} -}}"; + => $$""" + class {{className}} { + void {{methodName}}() { + {{code}} + } + } + """; protected override string WrapInNamespace(string code) -=> $@"namespace N {{ - {code} -}}"; + => $$""" + namespace N { + {{code}} + } + """; } diff --git a/src/EditorFeatures/CSharpTest/Classification/SemanticClassifierTests.cs b/src/EditorFeatures/CSharpTest/Classification/SemanticClassifierTests.cs index 02027819001aa..2884b7a147c0f 100644 --- a/src/EditorFeatures/CSharpTest/Classification/SemanticClassifierTests.cs +++ b/src/EditorFeatures/CSharpTest/Classification/SemanticClassifierTests.cs @@ -31,7 +31,8 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Classification; [Trait(Traits.Feature, Traits.Features.Classification)] public sealed partial class SemanticClassifierTests : AbstractCSharpClassifierTests { - protected override async Task> GetClassificationSpansAsync(string code, ImmutableArray spans, ParseOptions? options, TestHost testHost) + protected override async Task> GetClassificationSpansAsync( + string code, ImmutableArray spans, ParseOptions? options, TestHost testHost) { using var workspace = CreateWorkspace(code, options, testHost); var document = workspace.CurrentSolution.GetRequiredDocument(workspace.Documents.First().Id); @@ -39,14 +40,6 @@ protected override async Task> GetClassificationS return await GetSemanticClassificationsAsync(document, spans); } - private new Task TestAsync( - [StringSyntax("C#-Test")] string code, - TestHost testHost, - params FormattedClassification[] expected) - { - return base.TestAsync(code, testHost, expected); - } - [Theory, CombinatorialData] public async Task GenericClassDeclaration(TestHost testHost) { diff --git a/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs b/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs index 2875ad6455030..c79d47b0c3460 100644 --- a/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs +++ b/src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs @@ -7,6 +7,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Classification; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Tagging; using Microsoft.CodeAnalysis.Editor.UnitTests.Classification; @@ -41,7 +43,7 @@ protected override async Task> GetClassificationS public async Task VarAsUsingAliasForNamespace(TestHost testHost) { await TestAsync( -@"using var = System;", + @"using var = System;", testHost, Keyword("using"), Namespace("var"), @@ -3233,4 +3235,64 @@ void M() Punctuation.CloseCurly, ], actualFormatted); } + + [Theory, CombinatorialData] + public async Task TestModernExtension1(TestHost testHost) + { + await TestAsync( + """ + static class C + { + extension(string s) + { + public bool IsNullOrEmpty() => false; + } + + void M(string s) + { + var v = s.IsNullOrEmpty(); + } + } + """, + testHost, + CSharpParseOptions.Default.WithLanguageVersion(LanguageVersionExtensions.CSharpNext), + Keyword("static"), + Keyword("class"), + Class("C"), + Static("C"), + Punctuation.OpenCurly, + Keyword("extension"), + Punctuation.OpenParen, + Keyword("string"), + Parameter("s"), + Punctuation.CloseParen, + Punctuation.OpenCurly, + Keyword("public"), + Keyword("bool"), + ExtensionMethod("IsNullOrEmpty"), + Punctuation.OpenParen, + Punctuation.CloseParen, + Operators.EqualsGreaterThan, + Keyword("false"), + Punctuation.Semicolon, + Punctuation.CloseCurly, + Keyword("void"), + Method("M"), + Punctuation.OpenParen, + Keyword("string"), + Parameter("s"), + Punctuation.CloseParen, + Punctuation.OpenCurly, + Keyword("var"), + Local("v"), + Operators.Equals, + Parameter("s"), + Operators.Dot, + ExtensionMethod("IsNullOrEmpty"), + Punctuation.OpenParen, + Punctuation.CloseParen, + Punctuation.Semicolon, + Punctuation.CloseCurly, + Punctuation.CloseCurly); + } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AbstractCSharpCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AbstractCSharpCompletionProviderTests.cs index 1f5e19957748a..cbe49be4bcd03 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AbstractCSharpCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AbstractCSharpCompletionProviderTests.cs @@ -5,6 +5,7 @@ #nullable disable using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Completion; @@ -29,7 +30,8 @@ public abstract class AbstractCSharpCompletionProviderTests : { protected const string NonBreakingSpaceString = "\x00A0"; - protected static string GetMarkup(string source, LanguageVersion languageVersion) + protected static string GetMarkup( + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string source, LanguageVersion languageVersion) => $@" @@ -40,17 +42,17 @@ protected static string GetMarkup(string source, LanguageVersion languageVersion "; - protected override EditorTestWorkspace CreateWorkspace(string fileContents) + protected override EditorTestWorkspace CreateWorkspace([StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string fileContents) => EditorTestWorkspace.CreateCSharp(fileContents, composition: GetComposition()); internal override CompletionService GetCompletionService(Project project) => Assert.IsType(base.GetCompletionService(project)); private protected override Task BaseVerifyWorkerAsync( - string code, int position, + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, + Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) @@ -63,7 +65,7 @@ private protected override Task BaseVerifyWorkerAsync( } private protected override Task BaseVerifyWorkerAsync( - string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool? hasSuggestionItem, + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool? hasSuggestionItem, SourceCodeKind sourceCodeKind, ItemExpectation[] expectedResults, List matchingFilters, CompletionItemFlags? flags, CompletionOptions options, bool skipSpeculation = false) { @@ -73,10 +75,10 @@ private protected override Task BaseVerifyWorkerAsync( } private protected override async Task VerifyWorkerAsync( - string code, int position, + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, - bool checkForAbsence, int? glyph, int? matchPriority, + bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) @@ -99,9 +101,9 @@ protected override string ItemPartiallyWritten(string expectedItemOrNull) => expectedItemOrNull[0] == '@' ? expectedItemOrNull.Substring(1, 1) : expectedItemOrNull[..1]; private async Task VerifyInFrontOfCommentAsync( - string code, int position, string insertText, bool usePreviousCharAsTrigger, char? deletedCharTrigger, + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string code, int position, string insertText, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, - SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph, + SourceCodeKind sourceCodeKind, bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription, bool? isComplexTextEdit, List matchingFilters, CompletionOptions options, bool skipSpeculation = false) @@ -118,9 +120,9 @@ await base.VerifyWorkerAsync( } private async Task VerifyInFrontOfCommentAsync( - string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, - SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph, + SourceCodeKind sourceCodeKind, bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription, bool? isComplexTextEdit, List matchingFilters, CompletionOptions options, bool skipSpeculation = false) @@ -133,9 +135,9 @@ await VerifyInFrontOfCommentAsync( } private protected async Task VerifyInFrontOfComment_ItemPartiallyWrittenAsync( - string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, - SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph, + SourceCodeKind sourceCodeKind, bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription, bool? isComplexTextEdit, List matchingFilters, CompletionOptions options, bool skipSpeculation = false) @@ -147,7 +149,7 @@ await VerifyInFrontOfCommentAsync( displayTextPrefix, inlineDescription, isComplexTextEdit, matchingFilters, options, skipSpeculation: skipSpeculation); } - protected static string AddInsideMethod(string text) + protected static string AddInsideMethod([StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string text) { return """ @@ -162,7 +164,8 @@ void F() """; } - protected static string AddUsingDirectives(string usingDirectives, string text) + protected static string AddUsingDirectives( + string usingDirectives, [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string text) { return usingDirectives + @@ -172,7 +175,9 @@ protected static string AddUsingDirectives(string usingDirectives, string text) text; } - protected async Task VerifySendEnterThroughToEnterAsync(string initialMarkup, string textTypedSoFar, EnterKeyRule sendThroughEnterOption, bool expected) + protected async Task VerifySendEnterThroughToEnterAsync( + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string initialMarkup, + string textTypedSoFar, EnterKeyRule sendThroughEnterOption, bool expected) { using var workspace = CreateWorkspace(initialMarkup); var hostDocument = workspace.DocumentWithCursor; diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AwaitCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AwaitCompletionProviderTests.cs index 9d29cc887002d..504178d5e2130 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AwaitCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/AwaitCompletionProviderTests.cs @@ -46,12 +46,12 @@ private async Task VerifyKeywordAsync( var expectedDescription = dotAwait ? GetDescription(CompletionDisplayTextAwait, FeaturesResources.Await_the_preceding_expression) : GetDescription(CompletionDisplayTextAwait, FeaturesResources.Asynchronously_waits_for_the_task_to_finish); - await VerifyItemExistsAsync(GetMarkup(code, languageVersion), CompletionDisplayTextAwait, glyph: (int)Glyph.Keyword, expectedDescriptionOrNull: expectedDescription, inlineDescription: inlineDescription); + await VerifyItemExistsAsync(GetMarkup(code, languageVersion), CompletionDisplayTextAwait, glyph: Glyph.Keyword, expectedDescriptionOrNull: expectedDescription, inlineDescription: inlineDescription); if (dotAwaitf) { expectedDescription = string.Format(FeaturesResources.Await_the_preceding_expression_and_add_ConfigureAwait_0, "false"); - await VerifyItemExistsAsync(GetMarkup(code, languageVersion), CompletionDisplayTextAwaitAndConfigureAwait, glyph: (int)Glyph.Keyword, expectedDescriptionOrNull: expectedDescription, inlineDescription: inlineDescription); + await VerifyItemExistsAsync(GetMarkup(code, languageVersion), CompletionDisplayTextAwaitAndConfigureAwait, glyph: Glyph.Keyword, expectedDescriptionOrNull: expectedDescription, inlineDescription: inlineDescription); } else { diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ConversionCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ConversionCompletionProviderTests.cs index c737ec9ba21a2..fb8a9a18a260d 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ConversionCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ConversionCompletionProviderTests.cs @@ -105,7 +105,7 @@ public static void Main() c.$$ } } - """, "float", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); + """, "float", displayTextPrefix: "(", displayTextSuffix: ")", glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -126,7 +126,7 @@ public static void Main() c.fl$$ } } - """, "float", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); + """, "float", displayTextPrefix: "(", displayTextSuffix: ")", glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -359,7 +359,7 @@ public static void Main() s.$$ } } - """, "int?", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); + """, "int?", displayTextPrefix: "(", displayTextSuffix: ")", glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -384,7 +384,7 @@ public static void Main() } """; await VerifyItemExistsAsync(Markup, "int", displayTextPrefix: "(", displayTextSuffix: ")", - glyph: (int)Glyph.Operator, + glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter], expectedDescriptionOrNull: """ @@ -415,7 +415,7 @@ public static void Main() } """; await VerifyItemExistsAsync(Markup, "int?", displayTextPrefix: "(", displayTextSuffix: ")", - glyph: (int)Glyph.Operator, + glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter], expectedDescriptionOrNull: """ @@ -468,7 +468,7 @@ public static void Main() } """; await VerifyItemExistsAsync(Markup, "byte", displayTextPrefix: "(", displayTextSuffix: ")", - glyph: (int)Glyph.Operator, + glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter], expectedDescriptionOrNull: $@"int.explicit operator byte(int value) @@ -489,7 +489,7 @@ public static void Main() } """; await VerifyItemExistsAsync(Markup, "byte?", displayTextPrefix: "(", displayTextSuffix: ")", - glyph: (int)Glyph.Operator, + glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter], expectedDescriptionOrNull: $@"int.explicit operator byte?(int? value) @@ -531,7 +531,7 @@ public static void Main() } """; await VerifyItemExistsAsync(Markup, "int", displayTextPrefix: "(", displayTextSuffix: ")", - glyph: (int)Glyph.Operator, + glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter], expectedDescriptionOrNull: $@"E.explicit operator int(E value) @@ -553,7 +553,7 @@ public static void Main() } """; await VerifyItemExistsAsync(Markup, "int?", displayTextPrefix: "(", displayTextSuffix: ")", - glyph: (int)Glyph.Operator, + glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter], expectedDescriptionOrNull: $@"E.explicit operator int?(E? value) @@ -581,7 +581,7 @@ public static void Main() } """; await VerifyItemExistsAsync(Markup, "int", displayTextPrefix: "(", displayTextSuffix: ")", - glyph: (int)Glyph.Operator, + glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter], expectedDescriptionOrNull: @$"B.E.explicit operator int(B.E value) @@ -631,7 +631,7 @@ public static void Main() var i = d.$$ } } - """, "int", displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); + """, "int", displayTextPrefix: "(", displayTextSuffix: ")", glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); } [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -649,7 +649,7 @@ public static void Main() var i = test.$$ }} }} -", expected, displayTextPrefix: "(", displayTextSuffix: ")", glyph: (int)Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); +", expected, displayTextPrefix: "(", displayTextSuffix: ")", glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/CrefCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/CrefCompletionProviderTests.cs index dec84e03949a1..22a46e81f0bc6 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/CrefCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/CrefCompletionProviderTests.cs @@ -27,7 +27,7 @@ internal override Type GetCompletionProviderType() private protected override async Task VerifyWorkerAsync(string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, - bool checkForAbsence, int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, + bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string? inlineDescription = null, bool? isComplexTextEdit = null, List? matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions? options = null, bool skipSpeculation = false) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs index 6a4431a4e22db..e0960c046f70e 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs @@ -344,7 +344,7 @@ public class MyClass public {{record}} R(MyClass $$ """; - await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic); + await VerifyItemExistsAsync(markup, "MyClass", glyph: Glyph.PropertyPublic); } [Theory] @@ -371,9 +371,9 @@ public class MyClass MyClass $$ } """; - await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.FieldPublic); - await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic); - await VerifyItemExistsAsync(markup, "GetMyClass", glyph: (int)Glyph.MethodPublic); + await VerifyItemExistsAsync(markup, "myClass", glyph: Glyph.FieldPublic); + await VerifyItemExistsAsync(markup, "MyClass", glyph: Glyph.PropertyPublic); + await VerifyItemExistsAsync(markup, "GetMyClass", glyph: Glyph.MethodPublic); } [Fact] @@ -500,7 +500,7 @@ public class C void Goo(CancellationToken $$ } """; - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); } [Fact] @@ -513,7 +513,7 @@ public class C void Goo(int x, CancellationToken c$$ } """; - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); } [Fact] @@ -526,7 +526,7 @@ public class C void Goo(CancellationToken c$$) {} } """; - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45492")] @@ -540,7 +540,7 @@ void Other(CancellationToken cancellationToken) {} void Goo(CancellationToken c$$) {} } """; - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); } [Fact] @@ -553,7 +553,7 @@ public class C void Goo(CancellationToken cancellationToken, CancellationToken c$$) {} } """; - await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45492")] @@ -565,7 +565,7 @@ public async Task Parameter6() void Other(CancellationToken cancellationToken) {} void Goo(CancellationToken c$$) {} """; - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); } [Fact] @@ -576,7 +576,7 @@ public async Task Parameter7() void Goo(CancellationToken cancellationToken, CancellationToken c$$) {} """; - await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45492")] @@ -590,7 +590,7 @@ public class C int this[CancellationToken c$$] => throw null; } """; - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45492")] @@ -604,7 +604,7 @@ public class C int this[CancellationToken cancellationToken, CancellationToken c$$] => throw null; } """; - await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken1", glyph: Glyph.Parameter); } [InlineData(LanguageVersion.CSharp7)] @@ -624,16 +624,16 @@ void InnerGoo(DbContext $$) { } } """; var markup = GetMarkup(source, languageVersion); - await VerifyItemExistsAsync(markup, "dbContext", glyph: (int)Glyph.Parameter); - await VerifyItemExistsAsync(markup, "db", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "dbContext", glyph: Glyph.Parameter); + await VerifyItemExistsAsync(markup, "db", glyph: Glyph.Parameter); if (languageVersion.MapSpecifiedToEffectiveVersion() >= LanguageVersion.CSharp8) { - await VerifyItemExistsAsync(markup, "context", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "context", glyph: Glyph.Parameter); } else { - await VerifyItemExistsAsync(markup, "context1", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "context1", glyph: Glyph.Parameter); } } @@ -655,16 +655,16 @@ void InnerGoo(DbContext $$) { } } """; var markup = GetMarkup(source, languageVersion); - await VerifyItemExistsAsync(markup, "dbContext", glyph: (int)Glyph.Parameter); - await VerifyItemExistsAsync(markup, "db", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "dbContext", glyph: Glyph.Parameter); + await VerifyItemExistsAsync(markup, "db", glyph: Glyph.Parameter); if (languageVersion.MapSpecifiedToEffectiveVersion() >= LanguageVersion.CSharp8) { - await VerifyItemExistsAsync(markup, "context", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "context", glyph: Glyph.Parameter); } else { - await VerifyItemExistsAsync(markup, "context1", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "context1", glyph: Glyph.Parameter); } } @@ -686,16 +686,16 @@ void InnerGoo(DbContext $$) { } } """; var markup = GetMarkup(source, languageVersion); - await VerifyItemExistsAsync(markup, "dbContext", glyph: (int)Glyph.Parameter); - await VerifyItemExistsAsync(markup, "db", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "dbContext", glyph: Glyph.Parameter); + await VerifyItemExistsAsync(markup, "db", glyph: Glyph.Parameter); if (languageVersion.MapSpecifiedToEffectiveVersion() >= LanguageVersion.CSharp8) { - await VerifyItemExistsAsync(markup, "context", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "context", glyph: Glyph.Parameter); } else { - await VerifyItemExistsAsync(markup, "context1", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "context1", glyph: Glyph.Parameter); } } @@ -717,7 +717,7 @@ public class C void Goo(CancellationToken $$ } """; - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); await VerifyItemIsAbsentAsync(markup, "CancellationToken"); } @@ -733,8 +733,8 @@ void M(CancellationToken myTok) { } void M(CancellationToken $$ } """; - await VerifyItemExistsAsync(markup, "myTok", glyph: (int)Glyph.Parameter); - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "myTok", glyph: Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52534")] @@ -749,8 +749,8 @@ public C(string firstName, string middleName, string lastName) { } public C(string firstName, string $$) } """; - await VerifyItemExistsAsync(markup, "middleName", glyph: (int)Glyph.Parameter); - await VerifyItemExistsAsync(markup, "lastName", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "middleName", glyph: Glyph.Parameter); + await VerifyItemExistsAsync(markup, "lastName", glyph: Glyph.Parameter); await VerifyItemIsAbsentAsync(markup, "firstName"); } @@ -779,7 +779,7 @@ void M2(CancellationToken $$ } """; await VerifyItemIsAbsentAsync(markup, "myTok"); - await VerifyItemExistsAsync(markup, "cancellationToken", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "cancellationToken", glyph: Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52534")] @@ -823,9 +823,9 @@ public class C void Goo(StringBuilder $$) {} } """; - await VerifyItemExistsAsync(markup, "stringBuilder", glyph: (int)Glyph.Parameter); - await VerifyItemExistsAsync(markup, "@string", glyph: (int)Glyph.Parameter); - await VerifyItemExistsAsync(markup, "builder", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "stringBuilder", glyph: Glyph.Parameter); + await VerifyItemExistsAsync(markup, "@string", glyph: Glyph.Parameter); + await VerifyItemExistsAsync(markup, "builder", glyph: Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19260")] @@ -838,7 +838,7 @@ public class C void Goo(For $$) {} } """; - await VerifyItemExistsAsync(markup, "@for", glyph: (int)Glyph.Parameter); + await VerifyItemExistsAsync(markup, "@for", glyph: Glyph.Parameter); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/19260")] @@ -1183,9 +1183,9 @@ public class MyClass MyClass $$ } """; - await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.FieldPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); - await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); - await VerifyItemExistsAsync(markup, "GetMyClass", glyph: (int)Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "myClass", glyph: Glyph.FieldPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "MyClass", glyph: Glyph.PropertyPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "GetMyClass", glyph: Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } [Fact] @@ -1200,7 +1200,7 @@ void M() } } """; - await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "myClass", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemIsAbsentAsync(markup, "MyClass"); await VerifyItemIsAbsentAsync(markup, "GetMyClass"); } @@ -2366,11 +2366,11 @@ class Configuration Configuration $$ } """; - await VerifyItemExistsAsync(markup, "ConfigurationField", glyph: (int)Glyph.FieldPublic, + await VerifyItemExistsAsync(markup, "ConfigurationField", glyph: Glyph.FieldPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); - await VerifyItemExistsAsync(markup, "ConfigurationProperty", glyph: (int)Glyph.PropertyPublic, + await VerifyItemExistsAsync(markup, "ConfigurationProperty", glyph: Glyph.PropertyPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); - await VerifyItemExistsAsync(markup, "ConfigurationMethod", glyph: (int)Glyph.MethodPublic, + await VerifyItemExistsAsync(markup, "ConfigurationMethod", glyph: Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemIsAbsentAsync(markup, "ConfigurationLocal"); await VerifyItemIsAbsentAsync(markup, "ConfigurationLocalFunction"); @@ -2397,9 +2397,9 @@ void M() } } """; - await VerifyItemExistsAsync(markup, "ConfigurationLocal", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "ConfigurationLocal", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); - await VerifyItemExistsAsync(markup, "ConfigurationLocalFunction", glyph: (int)Glyph.MethodPublic, + await VerifyItemExistsAsync(markup, "ConfigurationLocalFunction", glyph: Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemIsAbsentAsync(markup, "ConfigurationField"); await VerifyItemIsAbsentAsync(markup, "ConfigurationMethod"); @@ -2426,7 +2426,7 @@ void M() } """; await VerifyItemIsAbsentAsync(markup, "classB"); - await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB1", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2445,7 +2445,7 @@ void M(ClassB classB) } """; await VerifyItemIsAbsentAsync(markup, "classB"); - await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB1", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2465,7 +2465,7 @@ void M() } } """; - await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2485,7 +2485,7 @@ void M() } } """; - await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2505,7 +2505,7 @@ void M() } """; await VerifyItemIsAbsentAsync(markup, "classB"); - await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB1", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2527,7 +2527,7 @@ void M() """; await VerifyItemIsAbsentAsync(markup, "classB"); await VerifyItemIsAbsentAsync(markup, "classB1"); - await VerifyItemExistsAsync(markup, "classB2", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB2", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2550,7 +2550,7 @@ void M(bool flag) } """; await VerifyItemIsAbsentAsync(markup, "classB"); - await VerifyItemExistsAsync(markup, "classB1", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB1", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2566,7 +2566,7 @@ void M() } } """; - await VerifyItemExistsAsync(markup, "classA", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classA", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2589,7 +2589,7 @@ void M2() } } """; - await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2615,7 +2615,7 @@ void LocalM1(ClassB $$) { } if (languageVersion.MapSpecifiedToEffectiveVersion() >= LanguageVersion.CSharp8) { - await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Parameter, + await VerifyItemExistsAsync(markup, "classB", glyph: Glyph.Parameter, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } else @@ -2708,7 +2708,7 @@ void LocalM2(ClassB $$) { } } } """; - await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Parameter, + await VerifyItemExistsAsync(markup, "classB", glyph: Glyph.Parameter, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2729,7 +2729,7 @@ void LocalM2(ClassB $$) { } } } """; - await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Parameter, + await VerifyItemExistsAsync(markup, "classB", glyph: Glyph.Parameter, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2750,7 +2750,7 @@ void LocalM2() } } """; - await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2774,7 +2774,7 @@ void LocalM2() } } """; - await VerifyItemExistsAsync(markup, "classB", glyph: (int)Glyph.Local, + await VerifyItemExistsAsync(markup, "classB", glyph: Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } @@ -2814,7 +2814,7 @@ void M() } } """; - await VerifyItemExistsAsync(markup, "myClass1", glyph: (int)Glyph.Local); + await VerifyItemExistsAsync(markup, "myClass1", glyph: Glyph.Local); } [Fact] diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/EnumAndCompletionListTagCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/EnumAndCompletionListTagCompletionProviderTests.cs index 2f1fd3d137aff..4b39e3095fd14 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/EnumAndCompletionListTagCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/EnumAndCompletionListTagCompletionProviderTests.cs @@ -543,7 +543,7 @@ void Goo() } } """; - await VerifyItemExistsAsync(markup, "string", glyph: (int)Glyph.ClassPublic); + await VerifyItemExistsAsync(markup, "string", glyph: Glyph.ClassPublic); } [Fact] diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExtensionMethodImportCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExtensionMethodImportCompletionProviderTests.cs index 3b667dd79e46f..7ccbef1c21a8a 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExtensionMethodImportCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ExtensionMethodImportCompletionProviderTests.cs @@ -124,7 +124,7 @@ public void M({type2} x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -164,7 +164,7 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -204,7 +204,7 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -244,7 +244,7 @@ public void M(Exception x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -284,7 +284,7 @@ public void M(System.Collections.Generic.List x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -323,7 +323,7 @@ public void M(DateTime x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -364,7 +364,7 @@ await VerifyImportItemExistsAsync( markup, "ExtentionMethod", displayTextSuffix: "<>", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -404,7 +404,7 @@ public void M(MyInt x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -443,7 +443,7 @@ public void M(MyType x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -482,7 +482,7 @@ public void M(MyType x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -526,7 +526,7 @@ public void M({tupleType} x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -570,7 +570,7 @@ public void M(MyType x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -617,7 +617,7 @@ public void M({type} x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } public static IEnumerable TypeParameterWithRefTypeData => CombineWithReferenceTypeData( @@ -666,7 +666,7 @@ await VerifyImportItemExistsAsync( markup, "ExtentionMethod", displayTextSuffix: "<>", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -743,7 +743,7 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodInternal, // This is based on declared accessibility + glyph: Glyph.ExtensionMethodInternal, // This is based on declared accessibility inlineDescription: "Foo"); } @@ -782,7 +782,7 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodInternal, + glyph: Glyph.ExtensionMethodInternal, inlineDescription: "Foo"); } @@ -825,7 +825,7 @@ public void M(MyGeneric x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -864,7 +864,7 @@ public void M() await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -931,7 +931,7 @@ public void M({csType} x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "NS"); } @@ -968,7 +968,7 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Root"); } @@ -1043,7 +1043,7 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodInternal, // This is based on declared accessibility + glyph: Glyph.ExtensionMethodInternal, // This is based on declared accessibility inlineDescription: "Foo"); } @@ -1093,7 +1093,7 @@ public void M({type} x) await VerifyImportItemExistsAsync( markup, expectedMethodname, - glyph: (int)Glyph.ExtensionMethodInternal, + glyph: Glyph.ExtensionMethodInternal, inlineDescription: expectedNamespace); } @@ -1135,7 +1135,7 @@ public void M({type} x) await VerifyImportItemExistsAsync( markup, "ExtMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -1219,13 +1219,13 @@ public void M(string x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod1", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); await VerifyImportItemExistsAsync( markup, "ExtentionMethod2", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -1280,13 +1280,13 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod1", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); await VerifyImportItemExistsAsync( markup, "ExtentionMethod2", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -1337,13 +1337,13 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod1", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); await VerifyImportItemExistsAsync( markup, "ExtentionMethod2", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -1387,7 +1387,7 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } else @@ -1455,7 +1455,7 @@ public void M(int{rank} x) await VerifyImportItemExistsAsync( markup, expectedName, - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -1516,7 +1516,7 @@ await VerifyImportItemExistsAsync( markup, expectedName, displayTextSuffix: "<>", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -1564,7 +1564,7 @@ public void M(T x) where T : C1 await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "NS2"); } @@ -1607,7 +1607,7 @@ public void M({tupleType}[] x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "NS2"); } @@ -1650,7 +1650,7 @@ public void M({tupleType} x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "NS2"); } @@ -1694,7 +1694,7 @@ await VerifyImportItemExistsAsync( markup, "ExtentionMethod", displayTextSuffix: "<>", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "NS2", expectedDescriptionOrNull: $"({CSharpFeaturesResources.extension}) bool int.ExtentionMethod()"); } @@ -1743,7 +1743,7 @@ public void M(int x) await VerifyImportItemExistsAsync( markup, "ExtentionMethod", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "NS2", expectedDescriptionOrNull: $"({CSharpFeaturesResources.extension}) bool int.ExtentionMethod() (+{NonBreakingSpaceString}2{NonBreakingSpaceString}{FeaturesResources.overloads_})"); @@ -1751,7 +1751,7 @@ await VerifyImportItemExistsAsync( markup, "ExtentionMethod", displayTextSuffix: "<>", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "NS2", expectedDescriptionOrNull: $"({CSharpFeaturesResources.extension}) bool int.ExtentionMethod(T a) (+{NonBreakingSpaceString}2{NonBreakingSpaceString}{FeaturesResources.generic_overloads})"); } @@ -1798,7 +1798,7 @@ public static void Bar(this Goo goo, int x) await VerifyImportItemExistsAsync( markup, "Bar", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } @@ -1846,7 +1846,7 @@ public static void Bar(this Goo goo, int x) await VerifyImportItemExistsAsync( markup, "Bar", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } else @@ -1907,7 +1907,7 @@ public static void Bar(this Goo goo, int x) await VerifyImportItemExistsAsync( markup, "Bar", - glyph: (int)Glyph.ExtensionMethodPublic, + glyph: Glyph.ExtensionMethodPublic, inlineDescription: "Foo"); } else @@ -2034,7 +2034,7 @@ await VerifyImportItemExistsAsync( expectedDescriptionOrNull: expectedDescription); } - private Task VerifyImportItemExistsAsync(string markup, string expectedItem, string inlineDescription, int? glyph = null, string displayTextSuffix = null, string expectedDescriptionOrNull = null, List expectedFilters = null) + private Task VerifyImportItemExistsAsync(string markup, string expectedItem, string inlineDescription, Glyph? glyph = null, string displayTextSuffix = null, string expectedDescriptionOrNull = null, List expectedFilters = null) => VerifyItemExistsAsync(markup, expectedItem, displayTextSuffix: displayTextSuffix, glyph: glyph, inlineDescription: inlineDescription, expectedDescriptionOrNull: expectedDescriptionOrNull, isComplexTextEdit: true, matchingFilters: expectedFilters); private Task VerifyImportItemIsAbsentAsync(string markup, string expectedItem, string inlineDescription, string displayTextSuffix = null) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/FunctionPointerUnmanagedCallingConventionCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/FunctionPointerUnmanagedCallingConventionCompletionProviderTests.cs index a335dd252cc10..4b23996b6254b 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/FunctionPointerUnmanagedCallingConventionCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/FunctionPointerUnmanagedCallingConventionCompletionProviderTests.cs @@ -72,6 +72,6 @@ class C """; - await VerifyItemExistsAsync(markup, callingConvention, glyph: (int)Glyph.Keyword); + await VerifyItemExistsAsync(markup, callingConvention, glyph: Glyph.Keyword); } } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/LoadDirectiveCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/LoadDirectiveCompletionProviderTests.cs index c6d3eff4bb39a..03ee442447bff 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/LoadDirectiveCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/LoadDirectiveCompletionProviderTests.cs @@ -31,7 +31,7 @@ protected override IEqualityComparer GetStringComparer() private protected override Task VerifyWorkerAsync( string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, + Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) { diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OperatorCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OperatorCompletionProviderTests.cs index 43e0a9e3ac402..cfa9383de476b 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OperatorCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/OperatorCompletionProviderTests.cs @@ -105,7 +105,7 @@ public static void Main() c.$$; } } - """, "+", inlineDescription: "x + y", glyph: (int)Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); + """, "+", inlineDescription: "x + y", glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); } [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -711,7 +711,7 @@ public static void Main() d.$$ } } - """, "+", inlineDescription: "x + y", glyph: (int)Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); + """, "+", inlineDescription: "x + y", glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] @@ -729,7 +729,7 @@ public static void Main() r.$$ } } - """, "==", inlineDescription: "x == y", glyph: (int)Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); + """, "==", inlineDescription: "x == y", glyph: Glyph.Operator, matchingFilters: [FilterSet.OperatorFilter]); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/47511")] diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ReferenceDirectiveCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ReferenceDirectiveCompletionProviderTests.cs index 870a14f78b1bf..a67e716d96093 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ReferenceDirectiveCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/ReferenceDirectiveCompletionProviderTests.cs @@ -34,7 +34,7 @@ protected override IEqualityComparer GetStringComparer() private protected override Task VerifyWorkerAsync( string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, + Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) { diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs index f790fd9fb1280..8f0e44eee1a8f 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Completion.Providers; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Completion.Providers; +using Microsoft.CodeAnalysis.CSharp.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders; using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion; using Microsoft.CodeAnalysis.Test.Utilities; @@ -13289,7 +13290,7 @@ void M(int parameter) { } """; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: LanguageVersion.CSharp10), "parameter"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60812")] @@ -13368,7 +13369,7 @@ void local(int parameter) { } """; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: LanguageVersion.CSharp10), "parameter"); } [Fact] @@ -13385,7 +13386,7 @@ void local([Some(nameof(p$$))] int parameter) { } """; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: LanguageVersion.CSharp10), "parameter"); } [Fact] @@ -13402,7 +13403,7 @@ void M() """; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: LanguageVersion.CSharp10), "parameter"); } [Fact] @@ -13419,7 +13420,7 @@ void M() """; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: LanguageVersion.CSharp10), "parameter"); } [Fact] @@ -13431,7 +13432,7 @@ public async Task ParameterAvailableInDelegateAttributeNameof() """; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: LanguageVersion.CSharp10), "parameter"); } [Fact] @@ -13442,7 +13443,7 @@ public async Task ParameterAvailableInDelegateParameterAttributeNameof() """; await VerifyItemExistsAsync(MakeMarkup(source), "parameter"); - await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: "10"), "parameter"); + await VerifyItemExistsAsync(MakeMarkup(source, languageVersion: LanguageVersion.CSharp10), "parameter"); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/64585")] @@ -15096,11 +15097,37 @@ await VerifyExpectedItemsAsync(markup, [ ]); } - private static string MakeMarkup([StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string source, string languageVersion = "Preview") + [Fact] + public async Task ModernExtensionMethod1() + { + var source = """ + static class C + { + extension(string s) + { + public bool IsNullOrEmpty() => false; + } + + void M(string s) + { + s.$$ + } + } + """; + await VerifyItemExistsAsync( + MakeMarkup(source), + "IsNullOrEmpty", + sourceCodeKind: SourceCodeKind.Regular, + glyph: Glyph.ExtensionMethodPublic); + } + + private static string MakeMarkup( + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string source, + LanguageVersion languageVersion = LanguageVersion.Preview) { return $$""" - + {{source}} @@ -15110,14 +15137,5 @@ private static string MakeMarkup([StringSyntax(PredefinedEmbeddedLanguageNames.C } public static IEnumerable ValidEnumUnderlyingTypeNames() - { - yield return new object[] { "Byte" }; - yield return new object[] { "SByte" }; - yield return new object[] { "Int16" }; - yield return new object[] { "UInt16" }; - yield return new object[] { "Int32" }; - yield return new object[] { "UInt32" }; - yield return new object[] { "Int64" }; - yield return new object[] { "UInt64" }; - } + => [["Byte"], ["SByte"], ["Int16"], ["UInt16"], ["Int32"], ["UInt32"], ["Int64"], ["UInt64"]]; } diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs index 6a46467938a01..9605f91f3aefb 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs @@ -30,7 +30,7 @@ internal override Type GetCompletionProviderType() private protected override Task VerifyWorkerAsync( string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, + Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription, bool? isComplexTextEdit, List matchingFilters, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) { diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TypeImportCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TypeImportCompletionProviderTests.cs index 8f11227e7e23d..2362a89450db1 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TypeImportCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TypeImportCompletionProviderTests.cs @@ -1834,7 +1834,7 @@ enum E : $$ } 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); + => VerifyItemExistsAsync(markup, expectedItem, displayTextSuffix: displayTextSuffix, glyph: (Glyph)glyph, inlineDescription: inlineDescription, expectedDescriptionOrNull: expectedDescriptionOrNull, isComplexTextEdit: true, flags: flags); private Task VerifyTypeImportItemIsAbsentAsync(string markup, string expectedItem, string inlineDescription, string displayTextSuffix = null) => VerifyItemIsAbsentAsync(markup, expectedItem, displayTextSuffix: displayTextSuffix, inlineDescription: inlineDescription); diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs index 809ac9d11f50c..887c9a4dc4163 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/XmlDocumentationCommentCompletionProviderTests.cs @@ -42,7 +42,7 @@ private async Task VerifyItemsAbsentAsync(string markup, params string[] items) private protected override async Task VerifyWorkerAsync( string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, + Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) { @@ -894,7 +894,7 @@ static void Goo() } else { - await VerifyItemExistsAsync(source, keywordText, glyph: (int)Glyph.Keyword); + await VerifyItemExistsAsync(source, keywordText, glyph: Glyph.Keyword); } } } diff --git a/src/EditorFeatures/Test2/NavigationBar/CSharpNavigationBarTests.vb b/src/EditorFeatures/Test2/NavigationBar/CSharpNavigationBarTests.vb index 5bac824ee61aa..081fc1bebde50 100644 --- a/src/EditorFeatures/Test2/NavigationBar/CSharpNavigationBarTests.vb +++ b/src/EditorFeatures/Test2/NavigationBar/CSharpNavigationBarTests.vb @@ -388,7 +388,7 @@ static class C , host, Item("C.extension(string)", Glyph.ClassPublic), False, - Item("Goo()", Glyph.MethodPublic), False) + Item("Goo()", Glyph.ExtensionMethodPublic), False) End Function End Class End Namespace diff --git a/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs b/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs index f00ca3625df37..bfc3492feea70 100644 --- a/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs @@ -120,7 +120,7 @@ internal static ImmutableHashSet GetRoles(Document document) private protected abstract Task BaseVerifyWorkerAsync( string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, + Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription, bool? isComplexTextEdit, List matchingFilters, CompletionItemFlags? flags, CompletionOptions options, bool skipSpeculation = false); @@ -142,7 +142,7 @@ private protected async Task CheckResultsAsync( Document document, int position, string expectedItemOrNull, string expectedDescriptionOrNull, bool usePreviousCharAsTrigger, char? deletedCharTrigger, - bool checkForAbsence, int? glyph, int? matchPriority, + bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionModeItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription, bool? isComplexTextEdit, @@ -254,7 +254,7 @@ bool Predicate(RoslynCompletion.CompletionItem c) return false; if (result.ExpectedDescription != null && completionService.GetDescriptionAsync(document, c, options, displayOptions).Result.Text != result.ExpectedDescription) return false; - if (result.Glyph.HasValue && !c.Tags.SequenceEqual(GlyphTags.GetTags((Glyph)result.Glyph.Value))) + if (result.Glyph.HasValue && !c.Tags.SequenceEqual(GlyphTags.GetTags(result.Glyph.Value))) return false; if (result.MatchPriority.HasValue && c.Rules.MatchPriority != result.MatchPriority.Value) return false; @@ -270,11 +270,11 @@ bool Predicate(RoslynCompletion.CompletionItem c) } } - private protected sealed record ItemExpectation( + private protected record ItemExpectation( string Name, bool IsAbsent, string ExpectedDescription = null, - int? Glyph = null, + Glyph? Glyph = null, int? MatchPriority = null, string DisplayTextSuffix = null, string DisplayTextPrefix = null, @@ -312,7 +312,7 @@ private static bool FiltersMatch(List expectedMatchingFilters, private async Task VerifyAsync( string markup, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind? sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionModeItem, string displayTextSuffix, + Glyph? glyph, int? matchPriority, bool? hasSuggestionModeItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription, bool? isComplexTextEdit, List matchingFilters, CompletionItemFlags? flags, CompletionOptions options, bool skipSpeculation = false) { @@ -430,7 +430,7 @@ protected virtual IEqualityComparer GetStringComparer() private protected async Task VerifyItemExistsAsync( string markup, string expectedItem, string expectedDescriptionOrNull = null, SourceCodeKind? sourceCodeKind = null, bool usePreviousCharAsTrigger = false, char? deletedCharTrigger = null, - int? glyph = null, int? matchPriority = null, bool? hasSuggestionModeItem = null, + Glyph? glyph = null, int? matchPriority = null, bool? hasSuggestionModeItem = null, string displayTextSuffix = null, string displayTextPrefix = null, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) @@ -506,7 +506,7 @@ private protected virtual async Task VerifyWorkerAsync( string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, char? deletedCharTrigger, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionModeItem, + Glyph? glyph, int? matchPriority, bool? hasSuggestionModeItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription, bool? isComplexTextEdit, List matchingFilters, CompletionItemFlags? flags, @@ -1101,7 +1101,7 @@ private protected async Task VerifyAtPositionAsync( string code, int position, string insertText, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool checkForAbsence, - int? glyph, int? matchPriority, bool? hasSuggestionItem, + Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) { @@ -1118,7 +1118,7 @@ await BaseVerifyWorkerAsync(code, position, private protected async Task VerifyAtPositionAsync( string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, - SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph, + SourceCodeKind sourceCodeKind, bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, CompletionOptions options = null, bool skipSpeculation = false) @@ -1133,7 +1133,7 @@ await VerifyAtPositionAsync( private protected async Task VerifyAtPosition_ItemPartiallyWrittenAsync( string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, - SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph, + SourceCodeKind sourceCodeKind, bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, @@ -1189,7 +1189,7 @@ await VerifyAtEndOfFileAsync(code, position, string.Empty, private protected async Task VerifyAtEndOfFileAsync( string code, int position, string insertText, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, - SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph, + SourceCodeKind sourceCodeKind, bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, @@ -1214,7 +1214,7 @@ await BaseVerifyWorkerAsync( private protected async Task VerifyAtEndOfFileAsync( string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, - SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph, + SourceCodeKind sourceCodeKind, bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, @@ -1240,7 +1240,7 @@ await VerifyAtEndOfFileAsync( private protected async Task VerifyAtEndOfFile_ItemPartiallyWrittenAsync( string code, int position, bool usePreviousCharAsTrigger, char? deletedCharTrigger, string expectedItemOrNull, string expectedDescriptionOrNull, - SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph, + SourceCodeKind sourceCodeKind, bool checkForAbsence, Glyph? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string displayTextPrefix, string inlineDescription = null, bool? isComplexTextEdit = null, List matchingFilters = null, CompletionItemFlags? flags = null, diff --git a/src/EditorFeatures/TestUtilities/Workspaces/EditorTestWorkspace_Create.cs b/src/EditorFeatures/TestUtilities/Workspaces/EditorTestWorkspace_Create.cs index e23d6e3a33d85..4059a5ec4ceb2 100644 --- a/src/EditorFeatures/TestUtilities/Workspaces/EditorTestWorkspace_Create.cs +++ b/src/EditorFeatures/TestUtilities/Workspaces/EditorTestWorkspace_Create.cs @@ -4,6 +4,7 @@ #nullable disable +using System.Diagnostics.CodeAnalysis; using System.Xml.Linq; using Microsoft.CodeAnalysis.Host; @@ -113,7 +114,7 @@ internal static EditorTestWorkspace CreateWithSingleEmptySourceFile( #region C# public static EditorTestWorkspace CreateCSharp( - string file, + [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string file, ParseOptions parseOptions = null, CompilationOptions compilationOptions = null, TestComposition composition = null, diff --git a/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/AbstractVisualBasicCompletionProviderTests.vb b/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/AbstractVisualBasicCompletionProviderTests.vb index e34ac4a375f62..935139ce149df 100644 --- a/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/AbstractVisualBasicCompletionProviderTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/AbstractVisualBasicCompletionProviderTests.vb @@ -27,7 +27,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet code As String, position As Integer, expectedItemOrNull As String, expectedDescriptionOrNull As String, sourceCodeKind As SourceCodeKind, usePreviousCharAsTrigger As Boolean, deletedCharTrigger As Char?, - checkForAbsence As Boolean, glyph As Integer?, matchPriority As Integer?, + checkForAbsence As Boolean, glyph As Glyph?, matchPriority As Integer?, hasSuggestionItem As Boolean?, displayTextSuffix As String, displayTextPrefix As String, inlineDescription As String, isComplexTextEdit As Boolean?, matchingFilters As List(Of CompletionFilter), flags As CompletionItemFlags?, options As CompletionOptions, Optional skipSpeculation As Boolean = False) As Task Return MyBase.VerifyWorkerAsync( @@ -50,7 +50,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet code As String, position As Integer, expectedItemOrNull As String, expectedDescriptionOrNull As String, sourceCodeKind As SourceCodeKind, usePreviousCharAsTrigger As Boolean, deletedCharTrigger As Char?, - checkForAbsence As Boolean, glyph As Integer?, matchPriority As Integer?, + checkForAbsence As Boolean, glyph As Glyph?, matchPriority As Integer?, hasSuggestionItem As Boolean?, displayTextSuffix As String, displayTextPrefix As String, inlineDescription As String, isComplexTextEdit As Boolean?, matchingFilters As List(Of CompletionFilter), flags As CompletionItemFlags?, options As CompletionOptions, Optional skipSpeculation As Boolean = False) As Task ' Script/interactive support removed for now. diff --git a/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/ObjectInitializerCompletionProviderTests.vb b/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/ObjectInitializerCompletionProviderTests.vb index 1f20bd2471455..184f9c62ba854 100644 --- a/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/ObjectInitializerCompletionProviderTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/ObjectInitializerCompletionProviderTests.vb @@ -17,7 +17,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet code As String, position As Integer, expectedItemOrNull As String, expectedDescriptionOrNull As String, sourceCodeKind As SourceCodeKind, usePreviousCharAsTrigger As Boolean, deletedCharTrigger As Char?, - checkForAbsence As Boolean, glyph As Integer?, matchPriority As Integer?, + checkForAbsence As Boolean, glyph As Glyph?, matchPriority As Integer?, hasSuggestionItem As Boolean?, displayTextSuffix As String, displayTextPrefix As String, inlineDescription As String, isComplexTextEdit As Boolean?, matchingFilters As List(Of CompletionFilter), flags As CompletionItemFlags?, options As CompletionOptions, Optional skipSpeculation As Boolean = False) As Task diff --git a/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/XmlDocCommentCompletionProviderTests.vb b/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/XmlDocCommentCompletionProviderTests.vb index fd2787213ceaa..09df4d66d5131 100644 --- a/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/XmlDocCommentCompletionProviderTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Completion/CompletionProviders/XmlDocCommentCompletionProviderTests.vb @@ -21,7 +21,7 @@ Namespace Tests code As String, position As Integer, expectedItemOrNull As String, expectedDescriptionOrNull As String, sourceCodeKind As SourceCodeKind, usePreviousCharAsTrigger As Boolean, deletedCharTrigger As Char?, - checkForAbsence As Boolean, glyph As Integer?, matchPriority As Integer?, + checkForAbsence As Boolean, glyph As Glyph?, matchPriority As Integer?, hasSuggestionItem As Boolean?, displayTextSuffix As String, displayTextPrefix As String, inlineDescription As String, isComplexTextEdit As Boolean?, matchingFilters As List(Of CompletionFilter), flags As CompletionItemFlags?, options As CompletionOptions, Optional skipSpeculation As Boolean = False) As Task diff --git a/src/Features/Core/Portable/Shared/Extensions/ISymbolExtensions_2.cs b/src/Features/Core/Portable/Shared/Extensions/ISymbolExtensions_2.cs index 71b8b98c413aa..7440ed1aa5421 100644 --- a/src/Features/Core/Portable/Shared/Extensions/ISymbolExtensions_2.cs +++ b/src/Features/Core/Portable/Shared/Extensions/ISymbolExtensions_2.cs @@ -96,14 +96,13 @@ public static Glyph GetGlyph(this ISymbol symbol) { var methodSymbol = (IMethodSymbol)symbol; - if (methodSymbol.MethodKind is MethodKind.UserDefinedOperator or - MethodKind.Conversion or - MethodKind.BuiltinOperator) + if (methodSymbol.MethodKind is MethodKind.UserDefinedOperator or MethodKind.Conversion or MethodKind.BuiltinOperator) { return Glyph.Operator; } else if (methodSymbol.IsExtensionMethod || - methodSymbol.MethodKind == MethodKind.ReducedExtension) + methodSymbol.MethodKind == MethodKind.ReducedExtension || + methodSymbol.ContainingType?.IsExtension is true) { publicIcon = Glyph.ExtensionMethodPublic; } diff --git a/src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs b/src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs index 3868dec964e1b..1294c4d239e2e 100644 --- a/src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs +++ b/src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs @@ -205,7 +205,13 @@ private static bool IsVerbatimStringToken(SyntaxToken token) } else if (token.Parent is MethodDeclarationSyntax methodDeclaration && methodDeclaration.Identifier == token) { - return IsExtensionMethod(methodDeclaration) ? ClassificationTypeNames.ExtensionMethodName : ClassificationTypeNames.MethodName; + if (methodDeclaration.ParameterList.Parameters is [var parameter, ..] && parameter.Modifiers.Any(SyntaxKind.ThisKeyword)) + return ClassificationTypeNames.ExtensionMethodName; + + if (methodDeclaration.Parent is ExtensionDeclarationSyntax) + return ClassificationTypeNames.ExtensionMethodName; + + return ClassificationTypeNames.MethodName; } else if (token.Parent is ConstructorDeclarationSyntax constructorDeclaration && constructorDeclaration.Identifier == token) { @@ -328,9 +334,6 @@ public static bool IsStaticallyDeclared(SyntaxToken token) return parentNode.GetModifiers().Any(SyntaxKind.StaticKeyword); } - private static bool IsExtensionMethod(MethodDeclarationSyntax methodDeclaration) - => methodDeclaration.ParameterList.Parameters.FirstOrDefault()?.Modifiers.Any(SyntaxKind.ThisKeyword) == true; - private static string? GetClassificationForTypeDeclarationIdentifier(SyntaxToken identifier) => identifier.Parent!.Kind() switch { diff --git a/src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.cs b/src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.cs index 2ef45cd853a96..cb55f3a0f4c11 100644 --- a/src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.cs +++ b/src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.cs @@ -254,16 +254,20 @@ private static string GetClassificationForMethod(IMethodSymbol methodSymbol) // destructors because their declaration is handled by syntactic classification // and they cannot be invoked, so their is no usage to semantically classify. if (methodSymbol.MethodKind == MethodKind.Constructor) - { return methodSymbol.ContainingType?.GetClassification() ?? ClassificationTypeNames.MethodName; - } // Note: We only classify an extension method if it is in reduced form. // If an extension method is called as a static method invocation (e.g. Enumerable.Select(...)), // it is classified as an ordinary method. - return methodSymbol.MethodKind == MethodKind.ReducedExtension - ? ClassificationTypeNames.ExtensionMethodName - : ClassificationTypeNames.MethodName; + if (methodSymbol.MethodKind == MethodKind.ReducedExtension) + return ClassificationTypeNames.ExtensionMethodName; + + // If calling an extension method through the extension container (not the static class container) then it's + // definitely an extension method. + if (methodSymbol.ContainingType.IsExtension) + return ClassificationTypeNames.ExtensionMethodName; + + return ClassificationTypeNames.MethodName; } private static bool IsInVarContext(SimpleNameSyntax name) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ISymbolExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ISymbolExtensions.cs index f0160d218e069..296735de1944e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ISymbolExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ISymbolExtensions.cs @@ -180,9 +180,7 @@ public static bool IsOverridable([NotNullWhen(true)] this ISymbol? symbol) public static bool IsImplementableMember([NotNullWhen(true)] this ISymbol? symbol) { - if (symbol != null && - symbol.ContainingType != null && - symbol.ContainingType.TypeKind == TypeKind.Interface) + if (symbol is { ContainingType.TypeKind: TypeKind.Interface }) { if (symbol.Kind == SymbolKind.Event) { @@ -230,7 +228,7 @@ public static bool IsInterfaceType([NotNullWhen(true)] this ISymbol? symbol) => symbol is ITypeSymbol { TypeKind: TypeKind.Interface }; public static bool IsArrayType([NotNullWhen(true)] this ISymbol? symbol) - => symbol?.Kind == SymbolKind.ArrayType; + => symbol is { Kind: SymbolKind.ArrayType }; public static bool IsTupleType([NotNullWhen(true)] this ISymbol? symbol) => symbol is ITypeSymbol { IsTupleType: true }; @@ -266,7 +264,7 @@ public static bool IsReducedExtension([NotNullWhen(true)] this ISymbol? symbol) => symbol is IMethodSymbol { MethodKind: MethodKind.ReducedExtension }; public static bool IsEnumMember([NotNullWhen(true)] this ISymbol? symbol) - => symbol?.Kind == SymbolKind.Field && symbol.ContainingType.IsEnumType(); + => symbol is { Kind: SymbolKind.Field, ContainingType.TypeKind: TypeKind.Enum }; public static bool IsExtensionMethod(this ISymbol symbol) => symbol is IMethodSymbol { IsExtensionMethod: true };