diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/AttributeSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/AttributeSignatureHelpProviderTests.cs index 916e5470af372..6b8ccee8cad0e 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/AttributeSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/AttributeSignatureHelpProviderTests.cs @@ -26,11 +26,6 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task TestInvocationWithoutParameters() { - var expectedOrderedItems = new List - { - new("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0) - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -40,17 +35,13 @@ class SomethingAttribute : System.Attribute class D { } - """, expectedOrderedItems); + """, + [new("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)]); } [Fact] public async Task TestInvocationWithoutParametersMethodXmlComments() { - var expectedOrderedItems = new List - { - new("SomethingAttribute()", "Summary For Attribute", null, currentParameterIndex: 0) - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -62,18 +53,13 @@ public SomethingAttribute() { } class D { } - """, expectedOrderedItems); + """, + [new("SomethingAttribute()", "Summary For Attribute", null, currentParameterIndex: 0)]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickInt() { - var expectedOrderedItems = new List - { - new("SomethingAttribute(int i)", currentParameterIndex: 0, isSelected: true), - new("SomethingAttribute(string i)", currentParameterIndex: 0), - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -83,18 +69,14 @@ class SomethingAttribute : System.Attribute } [[|Something(i: 1$$|])] class D { } - """, expectedOrderedItems); + """, [ + new("SomethingAttribute(int i)", currentParameterIndex: 0, isSelected: true), + new("SomethingAttribute(string i)", currentParameterIndex: 0)]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickString() { - var expectedOrderedItems = new List - { - new("SomethingAttribute(int i)", currentParameterIndex: 0), - new("SomethingAttribute(string i)", currentParameterIndex: 0, isSelected: true), - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -104,17 +86,14 @@ class SomethingAttribute : System.Attribute } [[|Something(i: null$$|])] class D { } - """, expectedOrderedItems); + """, [ + new("SomethingAttribute(int i)", currentParameterIndex: 0), + new("SomethingAttribute(string i)", currentParameterIndex: 0, isSelected: true)]); } [Fact] public async Task TestInvocationWithParametersOn1() { - var expectedOrderedItems = new List - { - new("SomethingAttribute(int someInteger, string someString)", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -125,17 +104,13 @@ public SomethingAttribute(int someInteger, string someString) { } class D { } - """, expectedOrderedItems); + """, + [new("SomethingAttribute(int someInteger, string someString)", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task TestInvocationWithParametersXmlCommentsOn1() { - var expectedOrderedItems = new List - { - new("SomethingAttribute(int someInteger, string someString)", "Summary For Attribute", "Param someInteger", currentParameterIndex: 0) - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -151,17 +126,13 @@ public SomethingAttribute(int someInteger, string someString) { } |]class D { } - """, expectedOrderedItems); + """, + [new("SomethingAttribute(int someInteger, string someString)", "Summary For Attribute", "Param someInteger", currentParameterIndex: 0)]); } [Fact] public async Task TestInvocationWithParametersOn2() { - var expectedOrderedItems = new List - { - new("SomethingAttribute(int someInteger, string someString)", string.Empty, string.Empty, currentParameterIndex: 1) - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -172,17 +143,13 @@ public SomethingAttribute(int someInteger, string someString) { } class D { } - """, expectedOrderedItems); + """, + [new("SomethingAttribute(int someInteger, string someString)", string.Empty, string.Empty, currentParameterIndex: 1)]); } [Fact] public async Task TestInvocationWithParametersXmlComentsOn2() { - var expectedOrderedItems = new List - { - new("SomethingAttribute(int someInteger, string someString)", "Summary For Attribute", "Param someString", currentParameterIndex: 1) - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -198,17 +165,13 @@ public SomethingAttribute(int someInteger, string someString) { } |]class D { } - """, expectedOrderedItems); + """, + [new("SomethingAttribute(int someInteger, string someString)", "Summary For Attribute", "Param someString", currentParameterIndex: 1)]); } [Fact] public async Task TestInvocationWithClosingParen() { - var expectedOrderedItems = new List - { - new("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0) - }; - await TestAsync(""" class SomethingAttribute : System.Attribute { } @@ -217,7 +180,8 @@ class SomethingAttribute : System.Attribute class D { } - """, expectedOrderedItems); + """, + [new("SomethingAttribute()", string.Empty, null, currentParameterIndex: 0)]); } [Fact] @@ -997,7 +961,6 @@ public Task InvokedWithNoToken() [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1081535")] public async Task TestInvocationWithBadParameterList() { - var expectedOrderedItems = new List(); await TestAsync(""" class SomethingAttribute : System.Attribute { @@ -1007,6 +970,6 @@ class SomethingAttribute : System.Attribute class D { } - """, expectedOrderedItems); + """, []); } } diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/ConstructorInitializerSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/ConstructorInitializerSignatureHelpProviderTests.cs index ccb177b567b21..9a458567c7dae 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/ConstructorInitializerSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/ConstructorInitializerSignatureHelpProviderTests.cs @@ -26,11 +26,6 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task TestInvocationWithoutParameters() { - var expectedOrderedItems = new List - { - new("BaseClass()", string.Empty, null, currentParameterIndex: 0) - }; - await TestAsync(""" class BaseClass { @@ -42,17 +37,13 @@ class Derived : BaseClass public Derived() [|: base($$|]) { } } - """, expectedOrderedItems); + """, + [new("BaseClass()", string.Empty, null, currentParameterIndex: 0)]); } [Fact] public async Task TestInvocationWithoutParametersMethodXmlComments() { - var expectedOrderedItems = new List - { - new("BaseClass()", "Summary for BaseClass", null, currentParameterIndex: 0) - }; - await TestAsync(""" class BaseClass { @@ -65,17 +56,13 @@ class Derived : BaseClass public Derived() [|: base($$|]) { } } - """, expectedOrderedItems); + """, + [new("BaseClass()", "Summary for BaseClass", null, currentParameterIndex: 0)]); } [Fact] public async Task TestInvocationWithParametersOn1() { - var expectedOrderedItems = new List - { - new("BaseClass(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class BaseClass { @@ -87,17 +74,13 @@ class Derived : BaseClass public Derived() [|: base($$2, 3|]) { } } - """, expectedOrderedItems); + """, + [new("BaseClass(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task TestInvocationWithParametersXmlCommentsOn1() { - var expectedOrderedItems = new List - { - new("BaseClass(int a, int b)", "Summary for BaseClass", "Param a", currentParameterIndex: 0) - }; - await TestAsync(""" class BaseClass { @@ -112,17 +95,13 @@ class Derived : BaseClass public Derived() [|: base($$2, 3|]) { } } - """, expectedOrderedItems); + """, + [new("BaseClass(int a, int b)", "Summary for BaseClass", "Param a", currentParameterIndex: 0)]); } [Fact] public async Task TestInvocationWithParametersOn2() { - var expectedOrderedItems = new List - { - new("BaseClass(int a, int b)", "Summary for BaseClass", "Param b", currentParameterIndex: 1) - }; - await TestAsync(""" class BaseClass { @@ -138,17 +117,13 @@ class Derived : BaseClass public Derived() [|: base(2, $$3|]) { } } - """, expectedOrderedItems); + """, + [new("BaseClass(int a, int b)", "Summary for BaseClass", "Param b", currentParameterIndex: 1)]); } [Fact] public async Task TestInvocationWithParametersXmlComentsOn2() { - var expectedOrderedItems = new List - { - new("BaseClass(int a, int b)", "Summary for BaseClass", "Param b", currentParameterIndex: 1) - }; - await TestAsync(""" class BaseClass { @@ -163,86 +138,65 @@ class Derived : BaseClass public Derived() [|: base(2, $$3|]) { } } - """, expectedOrderedItems); + """, + [new("BaseClass(int a, int b)", "Summary for BaseClass", "Param b", currentParameterIndex: 1)]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestThisInvocation() { - var expectedOrderedItems = new List - { - new("Goo(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 1) - }; - await TestAsync(""" class Goo { public Goo(int a, int b) { } public Goo() [|: this(2, $$3|]) { } } - """, expectedOrderedItems); + """, + [new("Goo(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 1)]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestThisInvocationWithNonEmptyArgumentList() { - var expectedOrderedItems = new List - { - new("Foo()", string.Empty, null, currentParameterIndex: 0), - }; - await TestAsync(""" class Foo { public Foo(int a, int b) [|: this($$|]) { } public Foo() { } } - """, expectedOrderedItems); + """, + [new("Foo()", string.Empty, null, currentParameterIndex: 0)]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestInvocationWithoutClosingParen() { - var expectedOrderedItems = new List - { - new("Goo(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 1) - }; - await TestAsync(""" class Goo { public Goo(int a, int b) { } public Goo() [|: this(2, $$ |]} - """, expectedOrderedItems); + """, + [new("Goo(int a, int b)", string.Empty, string.Empty, currentParameterIndex: 1)]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2579")] public async Task TestThisInvocationWithoutClosingParenWithNonEmptyArgumentList() { - var expectedOrderedItems = new List - { - new("Foo()", string.Empty, null, currentParameterIndex: 0), - }; - await TestAsync(""" class Foo { public Foo() { } public Foo(int a, int b) [|: this($$ |]} - """, expectedOrderedItems); + """, + [new("Foo()", string.Empty, null, currentParameterIndex: 0)]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickInt() { - var expectedOrderedItems = new List - { - new("D(int i)", currentParameterIndex: 0, isSelected: true), - new("D(string i)", currentParameterIndex: 0), - }; - await TestAsync(""" class D { @@ -252,18 +206,14 @@ class D D(string i) => throw null; D(int i) => throw null; } - """, expectedOrderedItems); + """, [ + new("D(int i)", currentParameterIndex: 0, isSelected: true), + new("D(string i)", currentParameterIndex: 0)]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25830")] public async Task PickCorrectOverload_PickString() { - var expectedOrderedItems = new List - { - new("D(int i)", currentParameterIndex: 0), - new("D(string i)", currentParameterIndex: 0, isSelected: true), - }; - await TestAsync(""" class D { @@ -273,7 +223,9 @@ class D D(string i) => throw null; D(int i) => throw null; } - """, expectedOrderedItems); + """, [ + new("D(int i)", currentParameterIndex: 0), + new("D(string i)", currentParameterIndex: 0, isSelected: true)]); } #endregion diff --git a/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameFullyWrittenSignatureHelpProviderTests.cs b/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameFullyWrittenSignatureHelpProviderTests.cs index 3f48441f2e27d..dbef426582d89 100644 --- a/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameFullyWrittenSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/SignatureHelp/GenericNameFullyWrittenSignatureHelpProviderTests.cs @@ -27,11 +27,6 @@ internal override Type GetSignatureHelpProviderType() [Fact] public async Task NestedGenericTerminated() { - var expectedOrderedItems = new List - { - new("G", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class G { }; @@ -42,17 +37,13 @@ void Goo() G$$> } } - """, expectedOrderedItems); + """, + [new("G", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWith1ParameterTerminated() { - var expectedOrderedItems = new List - { - new("G", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class G { }; @@ -63,17 +54,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWith2ParametersOn1() { - var expectedOrderedItems = new List - { - new("G", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class G { }; @@ -84,17 +71,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWith2ParametersOn2() { - var expectedOrderedItems = new List - { - new("G", string.Empty, string.Empty, currentParameterIndex: 1) - }; - await TestAsync(""" class G { }; @@ -105,20 +88,13 @@ void Goo() [|G } } - """, expectedOrderedItems); + """, + [new("G", string.Empty, string.Empty, currentParameterIndex: 1)]); } [Fact] public async Task DeclaringGenericTypeWith2ParametersOn1XmlDoc() { - var expectedOrderedItems = new List - { - new("G", - "Summary for G", - "TypeParamS. Also see T", - currentParameterIndex: 0) - }; - await TestAsync(""" /// /// Summary for G @@ -134,17 +110,16 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G", + "Summary for G", + "TypeParamS. Also see T", + currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWith2ParametersOn2XmlDoc() { - var expectedOrderedItems = new List - { - new("G", "Summary for G", "TypeParamT. Also see S", currentParameterIndex: 1) - }; - await TestAsync(""" /// /// Summary for G @@ -160,7 +135,8 @@ void Goo() [|G } } - """, expectedOrderedItems); + """, + [new("G", "Summary for G", "TypeParamT. Also see S", currentParameterIndex: 1)]); } #endregion @@ -170,11 +146,6 @@ void Goo() [Fact] public async Task DeclaringGenericTypeWithConstraintsStruct() { - var expectedOrderedItems = new List - { - new("G where S : struct", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class G where S : struct { }; @@ -186,17 +157,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : struct", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsClass() { - var expectedOrderedItems = new List - { - new("G where S : class", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class G where S : class { }; @@ -208,17 +175,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : class", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsNew() { - var expectedOrderedItems = new List - { - new("G where S : new()", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class G where S : new() { }; @@ -230,17 +193,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : new()", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsBase() { - var expectedOrderedItems = new List - { - new("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class Base { } @@ -254,17 +213,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsBaseGenericWithGeneric() { - var expectedOrderedItems = new List - { - new("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class Base { } @@ -278,17 +233,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsBaseGenericWithNonGeneric() { - var expectedOrderedItems = new List - { - new("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class Base { } @@ -302,17 +253,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : Base", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsBaseGenericNested() { - var expectedOrderedItems = new List - { - new("G where S : Base>", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class Base { } @@ -326,17 +273,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : Base>", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsDeriveFromAnotherGenericParameter() { - var expectedOrderedItems = new List - { - new("G where S : T", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class G where S : T { }; @@ -348,17 +291,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : T", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsMixed1() { - var expectedOrderedItems = new List - { - new("G where S : Base, new()", "Summary1", "SummaryS", currentParameterIndex: 0) - }; - await TestAsync(""" /// /// Summary1 @@ -381,17 +320,13 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : Base, new()", "Summary1", "SummaryS", currentParameterIndex: 0)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsMixed2() { - var expectedOrderedItems = new List - { - new("G where T : class, S, IGoo, new()", "Summary1", "SummaryT", currentParameterIndex: 1) - }; - await TestAsync(""" /// /// Summary1 @@ -414,17 +349,13 @@ void Goo() [|G } } - """, expectedOrderedItems); + """, + [new("G where T : class, S, IGoo, new()", "Summary1", "SummaryT", currentParameterIndex: 1)]); } [Fact] public async Task DeclaringGenericTypeWithConstraintsAllowRefStruct() { - var expectedOrderedItems = new List - { - new("G where S : allows ref struct", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class G where S : allows ref struct { }; @@ -436,7 +367,8 @@ void Goo() [|G<$$|]> } } - """, expectedOrderedItems); + """, + [new("G where S : allows ref struct", string.Empty, string.Empty, currentParameterIndex: 0)]); } #endregion @@ -446,11 +378,6 @@ void Goo() [Fact] public async Task InvokingGenericMethodWith1ParameterTerminated() { - var expectedOrderedItems = new List - { - new("void C.Goo()", string.Empty, string.Empty, currentParameterIndex: 0) - }; - await TestAsync(""" class C { @@ -461,18 +388,13 @@ void Bar() [|Goo<$$|]> } } - """, expectedOrderedItems); + """, + [new("void C.Goo()", string.Empty, string.Empty, currentParameterIndex: 0)]); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWith2ParametersOn1() { - var expectedOrderedItems = new List - { - new("void C.Goo(S s, T t)", - "Method summary", "type param S. see T", currentParameterIndex: 0) - }; - await TestAsync(""" class C { @@ -490,17 +412,14 @@ void Bar() [|Goo<$$|]> } } - """, expectedOrderedItems); + """, + [new("void C.Goo(S s, T t)", + "Method summary", "type param S. see T", currentParameterIndex: 0)]); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWith2ParametersOn2() { - var expectedOrderedItems = new List - { - new("void C.Goo(S s, T t)", string.Empty, string.Empty, currentParameterIndex: 1) - }; - await TestAsync(""" class C { @@ -511,17 +430,13 @@ void Bar() [|Goo } } - """, expectedOrderedItems); + """, + [new("void C.Goo(S s, T t)", string.Empty, string.Empty, currentParameterIndex: 1)]); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWith2ParametersOn1XmlDoc() { - var expectedOrderedItems = new List - { - new("void C.Goo(S s, T t)", "SummaryForGoo", "SummaryForS", currentParameterIndex: 0) - }; - await TestAsync(""" class C { @@ -537,17 +452,13 @@ void Bar() [|Goo<$$|]> } } - """, expectedOrderedItems); + """, + [new("void C.Goo(S s, T t)", "SummaryForGoo", "SummaryForS", currentParameterIndex: 0)]); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWith2ParametersOn2XmlDoc() { - var expectedOrderedItems = new List - { - new("void C.Goo(S s, T t)", "SummaryForGoo", "SummaryForT", currentParameterIndex: 1) - }; - await TestAsync(""" class C { @@ -563,17 +474,13 @@ void Bar() [|Goo } } - """, expectedOrderedItems); + """, + [new("void C.Goo(S s, T t)", "SummaryForGoo", "SummaryForT", currentParameterIndex: 1)]); } [Fact] public async Task CallingGenericExtensionMethod() { - var expectedOrderedItems = new List - { - new($"({CSharpFeaturesResources.extension}) void G.Goo()", string.Empty, string.Empty, currentParameterIndex: 0) - }; - // TODO: Enable the script case when we have support for extension methods in scripts await TestAsync(""" class G @@ -592,7 +499,9 @@ static class GooClass { public static void Goo(this G g) { } } - """, expectedOrderedItems, usePreviousCharAsTrigger: false, sourceCodeKind: Microsoft.CodeAnalysis.SourceCodeKind.Regular); + """, + [new($"({CSharpFeaturesResources.extension}) void G.Goo()", string.Empty, string.Empty, currentParameterIndex: 0)], + usePreviousCharAsTrigger: false, sourceCodeKind: SourceCodeKind.Regular); } #endregion @@ -602,11 +511,6 @@ public static void Goo(this G g) { } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWithConstraintsMixed1() { - var expectedOrderedItems = new List - { - new("S C.Goo(S s, T t) where S : Base, new()", "GooSummary", "ParamS", currentParameterIndex: 0) - }; - await TestAsync(""" class Base { } interface IGoo { } @@ -628,17 +532,12 @@ void Bar() [|Goo<$$|]> } } - """, expectedOrderedItems); + """, [new("S C.Goo(S s, T t) where S : Base, new()", "GooSummary", "ParamS", currentParameterIndex: 0)]); } [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544091")] public async Task InvokingGenericMethodWithConstraintsMixed2() { - var expectedOrderedItems = new List - { - new("S C.Goo(S s, T t) where T : class, S, IGoo, new()", "GooSummary", "ParamT", currentParameterIndex: 1) - }; - await TestAsync(""" class Base { } interface IGoo { } @@ -660,7 +559,7 @@ void Bar() [|Goo } } - """, expectedOrderedItems); + """, [new("S C.Goo(S s, T t) where T : class, S, IGoo, new()", "GooSummary", "ParamT", currentParameterIndex: 1)]); } [Fact] @@ -682,9 +581,7 @@ void Bar() } } """, - [ - new SignatureHelpTestItem("void C.M(T arg) where T : unmanaged", "summary headline", "T documentation", currentParameterIndex: 0) - ]); + [new SignatureHelpTestItem("void C.M(T arg) where T : unmanaged", "summary headline", "T documentation", currentParameterIndex: 0)]); #endregion @@ -895,7 +792,6 @@ await TestSignatureHelpInEditorBrowsableContextsAsync(markup: markup, [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1083601")] public async Task DeclaringGenericTypeWithBadTypeArgumentList() { - var expectedOrderedItems = new List(); await TestAsync(""" class G { }; @@ -906,28 +802,12 @@ void Goo() G{$$> } } - """, expectedOrderedItems); + """, []); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/50114")] public async Task DeclaringGenericTypeWithDocCommentList() { - var expectedOrderedItems = new List - { - new("G", """ - List: - - Item 1. - """, - classificationTypeNames: ImmutableArray.Create( - ClassificationTypeNames.Text, - ClassificationTypeNames.WhiteSpace, - ClassificationTypeNames.WhiteSpace, - ClassificationTypeNames.WhiteSpace, - ClassificationTypeNames.Text, - ClassificationTypeNames.WhiteSpace)) - }; - await TestAsync(""" /// /// List: @@ -948,7 +828,19 @@ void Goo() [|G } } - """, expectedOrderedItems); + """, + [new("G", """ + List: + + Item 1. + """, + classificationTypeNames: ImmutableArray.Create( + ClassificationTypeNames.Text, + ClassificationTypeNames.WhiteSpace, + ClassificationTypeNames.WhiteSpace, + ClassificationTypeNames.WhiteSpace, + ClassificationTypeNames.Text, + ClassificationTypeNames.WhiteSpace))]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80233")] diff --git a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb index 9af6ff6690eab..7ab56ceb38b9b 100644 --- a/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb @@ -21,6 +21,7 @@ Imports Microsoft.VisualStudio.Text.Editor Imports Microsoft.VisualStudio.Text.Editor.Commanding.Commands Imports Microsoft.VisualStudio.Text.Projection Imports Moq +Imports Roslyn.Utilities Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense @@ -151,7 +152,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense If provider Is Nothing Then items = If(items, CreateItems(1)) - provider = New MockSignatureHelpProvider(items) + provider = New MockSignatureHelpProvider(items.ToImmutableArray()) End If Dim presenter = New Mock(Of IIntelliSensePresenter(Of ISignatureHelpPresenterSession, ISignatureHelpSession))(MockBehavior.Strict) With {.DefaultValue = DefaultValue.Mock} @@ -194,16 +195,16 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Return controller End Function - Private Shared Function CreateItems(count As Integer) As IList(Of SignatureHelpItem) - Return Enumerable.Range(0, count).Select(Function(i) New SignatureHelpItem(isVariadic:=False, documentationFactory:=Nothing, prefixParts:=New List(Of TaggedText), separatorParts:={}, suffixParts:={}, parameters:={}, descriptionParts:={})).ToList() + Private Shared Function CreateItems(count As Integer) As ImmutableArray(Of SignatureHelpItem) + Return Enumerable.Range(0, count).SelectAsArray(Function(i) New SignatureHelpItem(isVariadic:=False, documentationFactory:=Nothing, prefixParts:=New List(Of TaggedText), separatorParts:={}, suffixParts:={}, parameters:={}, descriptionParts:={})) End Function Friend Class MockSignatureHelpProvider Implements ISignatureHelpProvider - Private ReadOnly _items As IList(Of SignatureHelpItem) + Private ReadOnly _items As ImmutableArray(Of SignatureHelpItem) - Public Sub New(items As IList(Of SignatureHelpItem)) + Public Sub New(items As ImmutableArray(Of SignatureHelpItem)) Me._items = items End Sub @@ -212,8 +213,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense Public Function GetItemsAsync(document As Document, position As Integer, triggerInfo As SignatureHelpTriggerInfo, options As MemberDisplayOptions, cancellationToken As CancellationToken) As Task(Of SignatureHelpItems) Implements ISignatureHelpProvider.GetItemsAsync GetItemsCount += 1 Return Task.FromResult(If(_items.Any(), - New SignatureHelpItems(_items, TextSpan.FromBounds(position, position), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing), - Nothing)) + New SignatureHelpItems(_items, TextSpan.FromBounds(position, position), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing), + Nothing)) End Function Public ReadOnly Property TriggerCharacters As ImmutableArray(Of Char) Implements ISignatureHelpProvider.TriggerCharacters diff --git a/src/EditorFeatures/TestUtilities/SignatureHelp/AbstractSignatureHelpProviderTests.cs b/src/EditorFeatures/TestUtilities/SignatureHelp/AbstractSignatureHelpProviderTests.cs index 9c3b93cf5bfc1..c4baf9342ce5e 100644 --- a/src/EditorFeatures/TestUtilities/SignatureHelp/AbstractSignatureHelpProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/SignatureHelp/AbstractSignatureHelpProviderTests.cs @@ -181,7 +181,7 @@ private async Task VerifyCurrentParameterNameWorkerAsync(string markup, string e private static void CompareAndAssertCollectionsAndCurrentParameter( IEnumerable expectedTestItems, SignatureHelpItems actualSignatureHelpItems) { - Assert.True(expectedTestItems.Count() == actualSignatureHelpItems.Items.Count, $"Expected {expectedTestItems.Count()} items, but got {actualSignatureHelpItems.Items.Count}"); + Assert.True(expectedTestItems.Count() == actualSignatureHelpItems.Items.Length, $"Expected {expectedTestItems.Count()} items, but got {actualSignatureHelpItems.Items.Length}"); for (var i = 0; i < expectedTestItems.Count(); i++) { diff --git a/src/Features/CSharp/Portable/ExternalAccess/Pythia/Api/PythiaSignatureHelpItemWrapper.cs b/src/Features/CSharp/Portable/ExternalAccess/Pythia/Api/PythiaSignatureHelpItemWrapper.cs index 5fbac117c5f38..cc50e0915d45e 100644 --- a/src/Features/CSharp/Portable/ExternalAccess/Pythia/Api/PythiaSignatureHelpItemWrapper.cs +++ b/src/Features/CSharp/Portable/ExternalAccess/Pythia/Api/PythiaSignatureHelpItemWrapper.cs @@ -21,5 +21,5 @@ public static PythiaSignatureHelpItemWrapper CreateFromMethodGroupMethod( int position, SemanticModel semanticModel, IList descriptionParts) - => new(AbstractOrdinaryMethodSignatureHelpProvider.ConvertMethodGroupMethod(document, method, position, semanticModel, descriptionParts)); + => new(AbstractOrdinaryMethodSignatureHelpProvider.ConvertMethodGroupMethod(document, method, position, semanticModel, [.. descriptionParts])); } diff --git a/src/Features/CSharp/Portable/SignatureHelp/AbstractCSharpSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/AbstractCSharpSignatureHelpProvider.cs index 48a9e6f023864..d6ce004565d49 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/AbstractCSharpSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/AbstractCSharpSignatureHelpProvider.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using Microsoft.CodeAnalysis.DocumentationComments; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.SignatureHelp; @@ -33,13 +34,13 @@ protected static SymbolDisplayPart Space() protected static SymbolDisplayPart NewLine() => new(SymbolDisplayPartKind.LineBreak, null, "\r\n"); - private static readonly IList _separatorParts = + private static readonly ImmutableArray _separatorParts = [ Punctuation(SyntaxKind.CommaToken), Space() ]; - protected static IList GetSeparatorParts() => _separatorParts; + protected static ImmutableArray GetSeparatorParts() => _separatorParts; protected static SignatureHelpSymbolParameter Convert( IParameterSymbol parameter, diff --git a/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider.cs index de6a1bb133478..095d961810442 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading; @@ -14,6 +13,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.DocumentationComments; using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.SignatureHelp; using Microsoft.CodeAnalysis.Text; @@ -156,9 +156,9 @@ private static SignatureHelpItem Convert( throw ExceptionUtilities.UnexpectedValue(symbol); } - IList GetTypeArguments(IMethodSymbol method) + ImmutableArray GetTypeArguments(IMethodSymbol method) { - var result = new List(); + using var _ = ArrayBuilder.GetInstance(out var result); // Signature help for generic modern extensions must include the generic type *arguments* for the containing // extension as well. These are fixed given the receiver, and need to be repeated in the method type argument @@ -173,7 +173,7 @@ IList GetTypeArguments(IMethodSymbol method) result.AddRange(method.TypeParameters.Select(p => Convert(p, semanticModel, position, documentationCommentFormattingService))); - return result; + return result.ToImmutableAndClear(); } } @@ -195,12 +195,12 @@ private static SignatureHelpSymbolParameter Convert( selectedDisplayParts: GetSelectedDisplayParts(parameter, semanticModel, position)); } - private static IList GetSelectedDisplayParts( + private static ImmutableArray GetSelectedDisplayParts( ITypeParameterSymbol typeParam, SemanticModel semanticModel, int position) { - var parts = new List(); + using var _ = ArrayBuilder.GetInstance(out var parts); if (TypeParameterHasConstraints(typeParam)) { @@ -276,7 +276,7 @@ private static IList GetSelectedDisplayParts( } } - return parts; + return parts.ToImmutableAndClear(); } private static bool TypeParameterHasConstraints(ITypeParameterSymbol typeParam) diff --git a/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider_Method.cs b/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider_Method.cs index 38690a5a7def4..79fce86ad22d1 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider_Method.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider_Method.cs @@ -2,19 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; +using System.Collections.Immutable; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; namespace Microsoft.CodeAnalysis.CSharp.SignatureHelp; internal partial class AbstractGenericNameSignatureHelpProvider { - private static IList GetPreambleParts( + private static ImmutableArray GetPreambleParts( IMethodSymbol method, SemanticModel semanticModel, int position) { - var result = new List(); + using var _ = ArrayBuilder.GetInstance(out var result); var awaitable = method.GetOriginalUnreducedDefinition().IsAwaitableNonDynamic(semanticModel, position); var extension = method.GetOriginalUnreducedDefinition().IsExtensionMethod(); @@ -55,7 +56,7 @@ private static IList GetPreambleParts( result.Add(new SymbolDisplayPart(SymbolDisplayPartKind.MethodName, method, method.Name)); result.Add(Punctuation(SyntaxKind.LessThanToken)); - return result; + return result.ToImmutableAndClear(); } private static ITypeSymbol? GetContainingType(IMethodSymbol method) @@ -71,13 +72,11 @@ private static IList GetPreambleParts( } } - private static IList GetPostambleParts(IMethodSymbol method, SemanticModel semanticModel, int position) + private static ImmutableArray GetPostambleParts(IMethodSymbol method, SemanticModel semanticModel, int position) { - var result = new List - { - Punctuation(SyntaxKind.GreaterThanToken), - Punctuation(SyntaxKind.OpenParenToken) - }; + using var _ = ArrayBuilder.GetInstance(out var result); + result.Add(Punctuation(SyntaxKind.GreaterThanToken)); + result.Add(Punctuation(SyntaxKind.OpenParenToken)); var first = true; foreach (var parameter in method.Parameters) @@ -93,6 +92,6 @@ private static IList GetPostambleParts(IMethodSymbol method, } result.Add(Punctuation(SyntaxKind.CloseParenToken)); - return result; + return result.ToImmutableAndClear(); } } diff --git a/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider_NamedType.cs b/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider_NamedType.cs index 834a77dd75536..d90fa2f98c200 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider_NamedType.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/AbstractGenericNameSignatureHelpProvider_NamedType.cs @@ -2,13 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; +using System.Collections.Immutable; namespace Microsoft.CodeAnalysis.CSharp.SignatureHelp; internal partial class AbstractGenericNameSignatureHelpProvider { - private static IList GetPreambleParts( + private static ImmutableArray GetPreambleParts( INamedTypeSymbol namedType, SemanticModel semanticModel, int position) @@ -16,6 +16,6 @@ private static IList GetPreambleParts( return [.. namedType.ToMinimalDisplayParts(semanticModel, position, MinimallyQualifiedWithoutTypeParametersFormat), Punctuation(SyntaxKind.LessThanToken)]; } - private static IList GetPostambleParts() + private static ImmutableArray GetPostambleParts() => [Punctuation(SyntaxKind.GreaterThanToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.cs index 290c2cc2d1d8b..de801fca0b063 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.cs @@ -2,10 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis.DocumentationComments; using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.SignatureHelp; @@ -27,7 +28,7 @@ internal static SignatureHelpItem ConvertMethodGroupMethod( IMethodSymbol method, int position, SemanticModel semanticModel, - IList? descriptionParts) + ImmutableArray? descriptionParts) { var structuralTypeDisplayService = document.GetRequiredLanguageService(); var documentationCommentFormattingService = document.GetRequiredLanguageService(); @@ -44,12 +45,12 @@ [.. method.Parameters.Select(p => Convert(p, semanticModel, position, documentat descriptionParts: descriptionParts); } - private static IList GetMethodGroupPreambleParts( + private static ImmutableArray GetMethodGroupPreambleParts( IMethodSymbol method, SemanticModel semanticModel, int position) { - var result = new List(); + using var _ = ArrayBuilder.GetInstance(out var result); var awaitable = method.GetOriginalUnreducedDefinition().IsAwaitableNonDynamic(semanticModel, position); var extension = method.GetOriginalUnreducedDefinition().IsExtensionMethod(); @@ -81,9 +82,9 @@ private static IList GetMethodGroupPreambleParts( result.AddRange(method.ToMinimalDisplayParts(semanticModel, position, MinimallyQualifiedWithoutParametersFormat)); result.Add(Punctuation(SyntaxKind.OpenParenToken)); - return result; + return result.ToImmutableAndClear(); } - private static IList GetMethodGroupPostambleParts() + private static ImmutableArray GetMethodGroupPostambleParts() => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/AttributeSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/AttributeSignatureHelpProvider.cs index bb27965b2b009..30c34711fd57b 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/AttributeSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/AttributeSignatureHelpProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -16,6 +15,7 @@ using Microsoft.CodeAnalysis.DocumentationComments; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.SignatureHelp; using Microsoft.CodeAnalysis.Text; @@ -135,10 +135,10 @@ private static SignatureHelpItem Convert( var position = attribute.SpanStart; var namedParameters = constructor.ContainingType.GetAttributeNamedParameters(semanticModel.Compilation, within) .OrderBy(s => s.Name) - .ToList(); + .ToImmutableArray(); var isVariadic = - constructor.Parameters is [.., { IsParams: true }] && namedParameters.Count == 0; + constructor.Parameters is [.., { IsParams: true }] && namedParameters.IsEmpty; var item = CreateItem( constructor, semanticModel, position, @@ -152,51 +152,45 @@ private static SignatureHelpItem Convert( return item; } - private static IList GetParameters( + private static ImmutableArray GetParameters( IMethodSymbol constructor, SemanticModel semanticModel, int position, - IList namedParameters, + ImmutableArray namedParameters, IDocumentationCommentFormattingService documentationCommentFormatter, CancellationToken cancellationToken) { - var result = new List(); + using var _ = ArrayBuilder.GetInstance(out var result); foreach (var parameter in constructor.Parameters) - { result.Add(Convert(parameter, semanticModel, position, documentationCommentFormatter)); - } - for (var i = 0; i < namedParameters.Count; i++) + for (var i = 0; i < namedParameters.Length; i++) { cancellationToken.ThrowIfCancellationRequested(); var namedParameter = namedParameters[i]; - var type = namedParameter is IFieldSymbol ? ((IFieldSymbol)namedParameter).Type : ((IPropertySymbol)namedParameter).Type; - - var displayParts = new List - { - new( - namedParameter is IFieldSymbol ? SymbolDisplayPartKind.FieldName : SymbolDisplayPartKind.PropertyName, - namedParameter, namedParameter.Name.ToIdentifierToken().ToString()), - Space(), - Punctuation(SyntaxKind.EqualsToken), - Space() - }; - displayParts.AddRange(type.ToMinimalDisplayParts(semanticModel, position)); - + var type = namedParameter is IFieldSymbol field ? field.Type : ((IPropertySymbol)namedParameter).Type; result.Add(new SignatureHelpSymbolParameter( namedParameter.Name, isOptional: true, documentationFactory: namedParameter.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormatter), - displayParts: displayParts, + displayParts: + [ + new(namedParameter is IFieldSymbol ? SymbolDisplayPartKind.FieldName : SymbolDisplayPartKind.PropertyName, + namedParameter, namedParameter.Name.ToIdentifierToken().ToString()), + Space(), + Punctuation(SyntaxKind.EqualsToken), + Space(), + .. type.ToMinimalDisplayParts(semanticModel, position), + ], prefixDisplayParts: GetParameterPrefixDisplayParts(i))); } - return result; + return result.ToImmutableAndClear(); } - private static List? GetParameterPrefixDisplayParts(int i) + private static ImmutableArray? GetParameterPrefixDisplayParts(int i) { if (i == 0) { @@ -211,7 +205,7 @@ private static IList GetParameters( return null; } - private static IList GetPreambleParts( + private static ImmutableArray GetPreambleParts( IMethodSymbol method, SemanticModel semanticModel, int position) @@ -219,6 +213,6 @@ private static IList GetPreambleParts( return [.. method.ContainingType.ToMinimalDisplayParts(semanticModel, position), Punctuation(SyntaxKind.OpenParenToken)]; } - private static IList GetPostambleParts() + private static ImmutableArray GetPostambleParts() => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/ConstructorInitializerSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/ConstructorInitializerSignatureHelpProvider.cs index 9e87eba563fbb..06576d60e5db8 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/ConstructorInitializerSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/ConstructorInitializerSignatureHelpProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Linq; @@ -148,7 +147,7 @@ private static SignatureHelpItem Convert( return item; } - private static IList GetPreambleParts( + private static ImmutableArray GetPreambleParts( IMethodSymbol method, SemanticModel semanticModel, int position) @@ -156,6 +155,6 @@ private static IList GetPreambleParts( return [.. method.ContainingType.ToMinimalDisplayParts(semanticModel, position), Punctuation(SyntaxKind.OpenParenToken)]; } - private static IList GetPostambleParts() + private static ImmutableArray GetPostambleParts() => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/ElementAccessExpressionSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/ElementAccessExpressionSignatureHelpProvider.cs index 16b7815d93d4c..4480f8fcad5fe 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/ElementAccessExpressionSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/ElementAccessExpressionSignatureHelpProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -16,6 +15,7 @@ using Microsoft.CodeAnalysis.DocumentationComments; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.SignatureHelp; using Microsoft.CodeAnalysis.Text; @@ -234,12 +234,12 @@ private static SignatureHelpItem Convert( return item; } - private static IList GetPreambleParts( + private static ImmutableArray GetPreambleParts( IPropertySymbol indexer, int position, SemanticModel semanticModel) { - var result = new List(); + using var _ = ArrayBuilder.GetInstance(out var result); if (indexer.ReturnsByRef) { @@ -266,10 +266,10 @@ private static IList GetPreambleParts( result.Add(Punctuation(SyntaxKind.OpenBracketToken)); - return result; + return result.ToImmutableAndClear(); } - private static IList GetPostambleParts() + private static ImmutableArray GetPostambleParts() => [Punctuation(SyntaxKind.CloseBracketToken)]; private static class CompleteElementAccessExpression diff --git a/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs b/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs index 5b6dcce2a531f..9b2b5143924f0 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs @@ -2,12 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; +using System.Collections.Immutable; using System.Threading; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.DocumentationComments; using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.SignatureHelp; @@ -36,7 +37,7 @@ internal abstract partial class InvocationExpressionSignatureHelpProviderBase return invokeMethod; } - private static IList GetDelegateOrFunctionPointerInvokeItems(InvocationExpressionSyntax invocationExpression, IMethodSymbol invokeMethod, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, IDocumentationCommentFormattingService documentationCommentFormattingService, out int? selectedItem, CancellationToken cancellationToken) + private static ImmutableArray GetDelegateOrFunctionPointerInvokeItems(InvocationExpressionSyntax invocationExpression, IMethodSymbol invokeMethod, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, IDocumentationCommentFormattingService documentationCommentFormattingService, out int? selectedItem, CancellationToken cancellationToken) { var position = invocationExpression.SpanStart; var item = CreateItem( @@ -55,9 +56,9 @@ private static IList GetDelegateOrFunctionPointerInvokeItems( return [item]; } - private static IList GetDelegateOrFunctionPointerInvokePreambleParts(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position) + private static ImmutableArray GetDelegateOrFunctionPointerInvokePreambleParts(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position) { - var displayParts = new List(); + using var _ = ArrayBuilder.GetInstance(out var displayParts); displayParts.AddRange(invokeMethod.ReturnType.ToMinimalDisplayParts(semanticModel, position)); displayParts.Add(Space()); @@ -73,13 +74,13 @@ private static IList GetDelegateOrFunctionPointerInvokePreamb displayParts.Add(Punctuation(SyntaxKind.OpenParenToken)); - return displayParts; + return displayParts.ToImmutableAndClear(); } - private static IList GetDelegateOrFunctionPointerInvokeParameters( + private static ImmutableArray GetDelegateOrFunctionPointerInvokeParameters( IMethodSymbol invokeMethod, SemanticModel semanticModel, int position, IDocumentationCommentFormattingService formattingService, CancellationToken cancellationToken) { - var result = new List(); + using var _ = ArrayBuilder.GetInstance(out var result); foreach (var parameter in invokeMethod.Parameters) { @@ -91,9 +92,9 @@ private static IList GetDelegateOrFunctionPointerI parameter.ToMinimalDisplayParts(semanticModel, position))); } - return result; + return result.ToImmutableAndClear(); } - private static IList GetDelegateOrFunctionPointerInvokePostambleParts() + private static ImmutableArray GetDelegateOrFunctionPointerInvokePostambleParts() => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs b/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs index b25747835e5af..e46a14aafe5d4 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs @@ -2,10 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.SignatureHelp; namespace Microsoft.CodeAnalysis.CSharp.SignatureHelp; @@ -33,21 +33,17 @@ private static ImmutableArray ConvertDelegateTypeConstructor( return [item]; } - private static IList GetDelegateTypePreambleParts(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position) - { - var result = new List(); - - result.AddRange(invokeMethod.ContainingType.ToMinimalDisplayParts(semanticModel, position)); - result.Add(Punctuation(SyntaxKind.OpenParenToken)); - - return result; - } + private static ImmutableArray GetDelegateTypePreambleParts(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position) + => [ + .. invokeMethod.ContainingType.ToMinimalDisplayParts(semanticModel, position), + Punctuation(SyntaxKind.OpenParenToken), + ]; - private static IList GetDelegateTypeParameters(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position) + private static ImmutableArray GetDelegateTypeParameters(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position) { const string TargetName = "target"; - var parts = new List(); + using var _ = ArrayBuilder.GetInstance(out var parts); parts.AddRange(invokeMethod.ReturnType.ToMinimalDisplayParts(semanticModel, position)); parts.Add(Space()); parts.Add(Punctuation(SyntaxKind.OpenParenToken)); @@ -73,9 +69,9 @@ private static IList GetDelegateTypeParameters(IMe TargetName, isOptional: false, documentationFactory: null, - displayParts: parts)]; + displayParts: parts.ToImmutableAndClear())]; } - private static IList GetDelegateTypePostambleParts() + private static ImmutableArray GetDelegateTypePostambleParts() => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_NormalType.cs b/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_NormalType.cs index 01e6979432a4e..c93262a9f2264 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_NormalType.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_NormalType.cs @@ -2,7 +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. -using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -36,19 +36,13 @@ private static SignatureHelpItem ConvertNormalTypeConstructor( return item; } - private static IList GetNormalTypePreambleParts( - IMethodSymbol method, - SemanticModel semanticModel, - int position) - { - var result = new List(); - - result.AddRange(method.ContainingType.ToMinimalDisplayParts(semanticModel, position)); - result.Add(Punctuation(SyntaxKind.OpenParenToken)); - - return result; - } + private static ImmutableArray GetNormalTypePreambleParts( + IMethodSymbol method, SemanticModel semanticModel, int position) + => [ + .. method.ContainingType.ToMinimalDisplayParts(semanticModel, position), + Punctuation(SyntaxKind.OpenParenToken), + ]; - private static IList GetNormalTypePostambleParts() + private static ImmutableArray GetNormalTypePostambleParts() => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProvider.cs index a836df057d065..3e61af4945b5b 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProvider.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; @@ -128,26 +127,16 @@ private static SignatureHelpItem Convert( structuralTypeDisplayService, constructor.IsParams(), constructor.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormattingService), - GetPreambleParts(constructor, semanticModel, position), + GetPreambleParts(), GetSeparatorParts(), GetPostambleParts(), [.. constructor.Parameters.Select(p => Convert(p, semanticModel, position, documentationCommentFormattingService))]); return item; - static IList GetPreambleParts( - IMethodSymbol method, - SemanticModel semanticModel, - int position) - { - var result = new List(); - - result.AddRange(method.ContainingType.ToMinimalDisplayParts(semanticModel, position)); - result.Add(Punctuation(SyntaxKind.OpenParenToken)); - - return result; - } + ImmutableArray GetPreambleParts() + => [.. constructor.ContainingType.ToMinimalDisplayParts(semanticModel, position), Punctuation(SyntaxKind.OpenParenToken)]; - static IList GetPostambleParts() + static ImmutableArray GetPostambleParts() => [Punctuation(SyntaxKind.CloseParenToken)]; } } diff --git a/src/Features/CSharp/Portable/SignatureHelp/TupleConstructionSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/TupleConstructionSignatureHelpProvider.cs index 9b63703f76e2b..f5aef35c99ccc 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/TupleConstructionSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/TupleConstructionSignatureHelpProvider.cs @@ -153,9 +153,8 @@ private bool GetOuterMostParenthesizedExpressionInSpan(SyntaxNode root, int posi var suffixParts = SpecializedCollections.SingletonEnumerable(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, ")")).ToTaggedText(); var separatorParts = GetSeparatorParts().ToTaggedText(); - var items = tupleTypes.Select(tupleType => Convert( - tupleType, prefixParts, suffixParts, separatorParts, semanticModel, position)) - .ToList(); + var items = tupleTypes.SelectAsArray(tupleType => Convert( + tupleType, prefixParts, suffixParts, separatorParts, semanticModel, position)); var state = GetCurrentArgumentState(root, position, syntaxFacts, targetExpression.FullSpan, cancellationToken); return CreateSignatureHelpItems(items, targetExpression.Span, state, selectedItemIndex: null, parameterIndexOverride: -1); @@ -192,7 +191,7 @@ private static IEnumerable ConvertTupleMembers(INamedTyp typeParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.PropertyName, null, elementName)); } - result.Add(new SignatureHelpParameter(name: string.Empty, isOptional: false, documentationFactory: null, displayParts: typeParts)); + result.Add(new SignatureHelpParameter(name: string.Empty, isOptional: false, documentationFactory: null, displayParts: [.. typeParts])); } return result; diff --git a/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/AbstractStructuralTypeDisplayService.cs b/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/AbstractStructuralTypeDisplayService.cs index a8e57e9361cc9..20230877da842 100644 --- a/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/AbstractStructuralTypeDisplayService.cs +++ b/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/AbstractStructuralTypeDisplayService.cs @@ -66,16 +66,12 @@ public StructuralTypeDisplayInfo GetTypeDisplayInfo( int position) { if (directStructuralTypeReferences.Length == 0) - { - return new StructuralTypeDisplayInfo( - SpecializedCollections.EmptyDictionary(), - SpecializedCollections.EmptyList()); - } + return StructuralTypeDisplayInfo.Empty; var transitiveStructuralTypeReferences = GetTransitiveStructuralTypeReferences(directStructuralTypeReferences); transitiveStructuralTypeReferences = OrderStructuralTypes(transitiveStructuralTypeReferences, orderSymbol); - IList typeParts = []; + using var _ = ArrayBuilder.GetInstance(out var typeParts); if (transitiveStructuralTypeReferences.Length > 0) { @@ -112,10 +108,10 @@ public StructuralTypeDisplayInfo GetTypeDisplayInfo( // Finally, assign a name to all the anonymous types. var structuralTypeToName = GenerateStructuralTypeNames(transitiveStructuralTypeReferences); - typeParts = StructuralTypeDisplayInfo.ReplaceStructuralTypes( - typeParts, structuralTypeToName, semanticModel, position); + var typePartsArray = StructuralTypeDisplayInfo.ReplaceStructuralTypes( + typeParts.ToImmutableAndClear(), structuralTypeToName, semanticModel, position); - return new StructuralTypeDisplayInfo(structuralTypeToName, typeParts); + return new StructuralTypeDisplayInfo(structuralTypeToName, typePartsArray); } private static Dictionary GenerateStructuralTypeNames( diff --git a/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/StructuralTypeDisplayInfo.cs b/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/StructuralTypeDisplayInfo.cs index 813d2eff75a5c..9784d4e6333c4 100644 --- a/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/StructuralTypeDisplayInfo.cs +++ b/src/Features/Core/Portable/LanguageServices/AnonymousTypeDisplayService/StructuralTypeDisplayInfo.cs @@ -3,28 +3,26 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Collections.Immutable; +using Microsoft.CodeAnalysis.Collections; +using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.LanguageService; -internal readonly struct StructuralTypeDisplayInfo +internal readonly struct StructuralTypeDisplayInfo( + IDictionary structuralTypeToName, + ImmutableArray typesParts) { - public IDictionary StructuralTypeToName { get; } - public IList TypesParts { get; } + public static readonly StructuralTypeDisplayInfo Empty = default; - public StructuralTypeDisplayInfo( - IDictionary structuralTypeToName, - IList typesParts) - : this() - { - StructuralTypeToName = structuralTypeToName; - TypesParts = typesParts; - } + public IDictionary StructuralTypeToName => structuralTypeToName ?? SpecializedCollections.EmptyDictionary(); + public ImmutableArray TypesParts => typesParts.NullToEmpty(); - public IList ReplaceStructuralTypes(IList parts, SemanticModel semanticModel, int position) + public ImmutableArray ReplaceStructuralTypes(ImmutableArray parts, SemanticModel semanticModel, int position) => ReplaceStructuralTypes(parts, StructuralTypeToName, semanticModel, position); - public static IList ReplaceStructuralTypes( - IList parts, + public static ImmutableArray ReplaceStructuralTypes( + ImmutableArray parts, IDictionary structuralTypeToName, SemanticModel semanticModel, int position) @@ -37,14 +35,14 @@ public static IList ReplaceStructuralTypes( } public static bool ReplaceStructuralTypes( - IList parts, + ImmutableArray parts, IDictionary structuralTypeToName, SemanticModel semanticModel, int position, - out List newParts) + out ImmutableArray newParts) { var changed = false; - newParts = []; + using var _ = ArrayBuilder.GetInstance(out var newPartsBuilder); foreach (var part in parts) { @@ -53,7 +51,7 @@ public static bool ReplaceStructuralTypes( if (structuralTypeToName.TryGetValue(type, out var name) && part.ToString() != name) { - newParts.Add(new SymbolDisplayPart(part.Kind, symbol: null, name)); + newPartsBuilder.Add(new SymbolDisplayPart(part.Kind, symbol: null, name)); changed = true; continue; } @@ -62,15 +60,22 @@ public static bool ReplaceStructuralTypes( if (type.IsTupleType && part.ToString() == "") { var displayParts = type.ToMinimalDisplayParts(semanticModel, position); - newParts.AddRange(displayParts); + newPartsBuilder.AddRange(displayParts); changed = true; continue; } } - newParts.Add(part); + newPartsBuilder.Add(part); + } + + if (!changed) + { + newParts = []; + return false; } - return changed; + newParts = newPartsBuilder.ToImmutableAndClear(); + return true; } } diff --git a/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs b/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs index ce70ce3816c83..8f9c1c2549e6f 100644 --- a/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs +++ b/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs @@ -80,7 +80,7 @@ protected abstract partial class AbstractSymbolDescriptionBuilder private readonly SemanticModel _semanticModel; private readonly int _position; - private readonly Dictionary> _groupMap = []; + private readonly Dictionary> _groupMap = []; private readonly Dictionary> _documentationMap = []; private readonly Func _getNavigationHint; @@ -450,7 +450,7 @@ private async Task AddDescriptionPartAsync(ISymbol symbol) private ImmutableArray BuildDescription(SymbolDescriptionGroups groups) { - var finalParts = new List(); + using var _ = ArrayBuilder.GetInstance(out var finalParts); var orderedGroups = _groupMap.Keys.OrderBy((g1, g2) => g1 - g2); foreach (var group in orderedGroups) @@ -460,14 +460,13 @@ private ImmutableArray BuildDescription(SymbolDescriptionGrou continue; } - if (!finalParts.IsEmpty()) + if (!finalParts.IsEmpty) { var newLines = GetPrecedingNewLineCount(group); finalParts.AddRange(LineBreak(newLines)); } - var parts = _groupMap[group]; - finalParts.AddRange(parts); + finalParts.AddRange(_groupMap[group]); } return finalParts.AsImmutable(); @@ -833,16 +832,12 @@ protected void AddToGroup(SymbolDescriptionGroups group, params SymbolDisplayPar protected void AddToGroup(SymbolDescriptionGroups group, params IEnumerable[] partsArray) { - var partsList = partsArray.Flatten().ToList(); - if (partsList.Count > 0) + var partsList = partsArray.Flatten().ToImmutableArray(); + if (partsList.Length > 0) { - if (!_groupMap.TryGetValue(group, out var existingParts)) - { - existingParts = []; - _groupMap.Add(group, existingParts); - } - - existingParts.AddRange(partsList); + var existingParts = _groupMap.TryGetValue(group, out var temp) ? temp : []; + existingParts = existingParts.AddRange(partsList); + _groupMap[group] = existingParts; } } diff --git a/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AnonymousTypes.cs b/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AnonymousTypes.cs index 91405a4dc2354..64d8eae556699 100644 --- a/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AnonymousTypes.cs +++ b/src/Features/Core/Portable/LanguageServices/SymbolDisplayService/AbstractSymbolDisplayService.AnonymousTypes.cs @@ -33,7 +33,7 @@ where part.Symbol.IsAnonymousType() || part.Symbol.IsTupleType() var info = LanguageServices.GetRequiredService().GetTypeDisplayInfo( firstSymbol, directStructuralTypes.ToImmutableArrayOrEmpty(), _semanticModel, _position); - if (info.TypesParts.Count > 0) + if (info.TypesParts.Length > 0) AddToGroup(SymbolDescriptionGroups.StructuralTypes, info.TypesParts); foreach (var (group, parts) in _groupMap.ToArray()) diff --git a/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs b/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs index 21fa27cee0639..d12319bb6dd0b 100644 --- a/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs +++ b/src/Features/Core/Portable/SignatureHelp/AbstractSignatureHelpProvider.cs @@ -38,9 +38,9 @@ protected AbstractSignatureHelpProvider() protected abstract Task GetItemsWorkerAsync(Document document, int position, SignatureHelpTriggerInfo triggerInfo, MemberDisplayOptions options, CancellationToken cancellationToken); protected static SignatureHelpItems? CreateSignatureHelpItems( - IList items, TextSpan applicableSpan, SignatureHelpState? state, int? selectedItemIndex, int parameterIndexOverride) + ImmutableArray items, TextSpan applicableSpan, SignatureHelpState? state, int? selectedItemIndex, int parameterIndexOverride) { - if (items is null || items.Count == 0 || state == null) + if (items.IsDefaultOrEmpty || state == null) return null; if (selectedItemIndex < 0) @@ -70,7 +70,7 @@ protected AbstractSignatureHelpProvider() } protected static SignatureHelpItems? CreateCollectionInitializerSignatureHelpItems( - IList items, TextSpan applicableSpan, SignatureHelpState? state) + ImmutableArray items, TextSpan applicableSpan, SignatureHelpState? state) { // We will have added all the accessible '.Add' methods that take at least one // arguments. However, in general the one-arg Add method is the least likely for the @@ -94,15 +94,15 @@ protected AbstractSignatureHelpProvider() items, applicableSpan, state, items.IndexOf(i => i.Parameters.Length >= 2), parameterIndexOverride: -1); } - private static (IList items, int? selectedItem) Filter(IList items, ImmutableArray parameterNames, int? selectedItem) + private static (ImmutableArray items, int? selectedItem) Filter(ImmutableArray items, ImmutableArray parameterNames, int? selectedItem) { if (parameterNames.IsDefault) - return (items.ToList(), selectedItem); + return (items, selectedItem); - var filteredList = items.Where(i => Include(i, parameterNames)).ToList(); - var isEmpty = filteredList.Count == 0; + var filteredList = items.WhereAsArray(i => Include(i, parameterNames)); + var isEmpty = filteredList.IsEmpty; if (!selectedItem.HasValue || isEmpty) - return (isEmpty ? [.. items] : filteredList, selectedItem); + return (isEmpty ? items : filteredList, selectedItem); // adjust the selected item var selection = items[selectedItem.Value]; @@ -138,11 +138,11 @@ protected SignatureHelpItem CreateItem( IStructuralTypeDisplayService structuralTypeDisplayService, bool isVariadic, Func> documentationFactory, - IList prefixParts, - IList separatorParts, - IList suffixParts, - IList parameters, - IList? descriptionParts = null) + ImmutableArray prefixParts, + ImmutableArray separatorParts, + ImmutableArray suffixParts, + ImmutableArray parameters, + ImmutableArray? descriptionParts = null) { return CreateItem(orderSymbol, semanticModel, position, structuralTypeDisplayService, isVariadic, documentationFactory, prefixParts, separatorParts, suffixParts, parameters, descriptionParts); @@ -155,11 +155,11 @@ protected static SignatureHelpItem CreateItem( IStructuralTypeDisplayService structuralTypeDisplayService, bool isVariadic, Func>? documentationFactory, - IList prefixParts, - IList separatorParts, - IList suffixParts, - IList parameters, - IList? descriptionParts = null) + ImmutableArray prefixParts, + ImmutableArray separatorParts, + ImmutableArray suffixParts, + ImmutableArray parameters, + ImmutableArray? descriptionParts = null) { return CreateItemImpl(orderSymbol, semanticModel, position, structuralTypeDisplayService, isVariadic, documentationFactory, prefixParts, separatorParts, suffixParts, parameters, descriptionParts); @@ -172,15 +172,13 @@ protected static SignatureHelpItem CreateItemImpl( IStructuralTypeDisplayService structuralTypeDisplayService, bool isVariadic, Func>? documentationFactory, - IList prefixParts, - IList separatorParts, - IList suffixParts, - IList parameters, - IList? descriptionParts) + ImmutableArray prefixParts, + ImmutableArray separatorParts, + ImmutableArray suffixParts, + ImmutableArray parameters, + ImmutableArray? descriptionParts) { - descriptionParts = descriptionParts == null - ? SpecializedCollections.EmptyList() - : descriptionParts; + descriptionParts ??= []; var allParts = prefixParts.Concat(separatorParts) .Concat(suffixParts) @@ -195,7 +193,7 @@ where part.Symbol.IsAnonymousType() || part.Symbol.IsTupleType() var info = structuralTypeDisplayService.GetTypeDisplayInfo( orderSymbol, [.. structuralTypes], semanticModel, position); - if (info.TypesParts.Count > 0) + if (info.TypesParts.Length > 0) { var structuralTypeParts = new List { @@ -260,7 +258,7 @@ private static SignatureHelpSymbolParameter ReplaceStructuralTypes( var semanticModel = await document.ReuseExistingSpeculativeModelAsync(position, cancellationToken).ConfigureAwait(false); var compilation = semanticModel.Compilation; - var finalItems = new List(); + using var _1 = ArrayBuilder.GetInstance(out var finalItems); foreach (var item in itemsForCurrentDocument.Items) { if (item is not SymbolKeySignatureHelpItem symbolKeyItem || @@ -278,7 +276,7 @@ symbolKeyItem.SymbolKey is not SymbolKey symbolKey || symbolKey = SymbolKey.Create(methodSymbol.OriginalDefinition, cancellationToken); } - using var _ = ArrayBuilder.GetInstance(out var invalidProjectsForCurrentSymbol); + using var _2 = ArrayBuilder.GetInstance(out var invalidProjectsForCurrentSymbol); foreach (var relatedDocument in relatedDocuments) { // Try to resolve symbolKey in each related compilation, @@ -295,7 +293,7 @@ symbolKeyItem.SymbolKey is not SymbolKey symbolKey || } return new SignatureHelpItems( - finalItems, + finalItems.ToImmutableAndClear(), itemsForCurrentDocument.ApplicableSpan, itemsForCurrentDocument.SemanticParameterIndex, itemsForCurrentDocument.SyntacticArgumentCount, diff --git a/src/Features/Core/Portable/SignatureHelp/SignatureHelpItems.cs b/src/Features/Core/Portable/SignatureHelp/SignatureHelpItems.cs index 179ea67ea04f3..c135184eaba29 100644 --- a/src/Features/Core/Portable/SignatureHelp/SignatureHelpItems.cs +++ b/src/Features/Core/Portable/SignatureHelp/SignatureHelpItems.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Diagnostics; using System.Linq; using Microsoft.CodeAnalysis.Text; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.SignatureHelp; @@ -16,7 +16,7 @@ internal sealed class SignatureHelpItems /// /// The list of items to present to the user. /// - public IList Items { get; } + public ImmutableArray Items { get; } /// /// The span this session applies to. @@ -59,23 +59,22 @@ internal sealed class SignatureHelpItems public int? SelectedItemIndex { get; } public SignatureHelpItems( - IList items, + ImmutableArray items, TextSpan applicableSpan, int semanticParameterIndex, int syntacticArgumentCount, string? argumentName, int? selectedItem = null) { - Contract.ThrowIfNull(items); - Contract.ThrowIfTrue(items.IsEmpty()); - Contract.ThrowIfTrue(selectedItem.HasValue && selectedItem.Value >= items.Count); + Contract.ThrowIfTrue(items.IsDefaultOrEmpty); + Contract.ThrowIfTrue(selectedItem.HasValue && selectedItem.Value >= items.Length); if (semanticParameterIndex < 0) throw new ArgumentException($"{nameof(semanticParameterIndex)} < 0. {semanticParameterIndex} < 0", nameof(semanticParameterIndex)); // Adjust the `selectedItem` index if duplicates are able to be removed. - var distinctItems = items.Distinct().ToList(); - if (selectedItem.HasValue && items.Count != distinctItems.Count) + var distinctItems = items.Distinct(); + if (selectedItem.HasValue && items.Length != distinctItems.Length) { // `selectedItem` index has already been determined to be valid, it now needs to be adjusted to point // to the equivalent item in the reduced list to account for duplicates being removed diff --git a/src/Features/Core/Portable/SignatureHelp/SignatureHelpParameter.cs b/src/Features/Core/Portable/SignatureHelp/SignatureHelpParameter.cs index 408f15cf50de5..f4066e7a45c15 100644 --- a/src/Features/Core/Portable/SignatureHelp/SignatureHelpParameter.cs +++ b/src/Features/Core/Portable/SignatureHelp/SignatureHelpParameter.cs @@ -4,10 +4,8 @@ using System; using System.Collections.Generic; -using System.Linq; +using System.Collections.Immutable; using System.Threading; -using Microsoft.CodeAnalysis; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.SignatureHelp; @@ -21,10 +19,10 @@ internal sealed class SignatureHelpSymbolParameter( string? name, bool isOptional, Func>? documentationFactory, - IEnumerable displayParts, - IEnumerable? prefixDisplayParts = null, - IEnumerable? suffixDisplayParts = null, - IEnumerable? selectedDisplayParts = null) + ImmutableArray displayParts, + ImmutableArray? prefixDisplayParts = null, + ImmutableArray? suffixDisplayParts = null, + ImmutableArray? selectedDisplayParts = null) { /// /// The name of this parameter. @@ -40,18 +38,18 @@ internal sealed class SignatureHelpSymbolParameter( /// /// Display parts to show before the normal display parts for the parameter. /// - public IList PrefixDisplayParts { get; } = prefixDisplayParts.ToImmutableArrayOrEmpty(); + public ImmutableArray PrefixDisplayParts { get; } = prefixDisplayParts.NullToEmpty(); /// /// Display parts to show after the normal display parts for the parameter. /// - public IList SuffixDisplayParts { get; } = suffixDisplayParts.ToImmutableArrayOrEmpty(); + public ImmutableArray SuffixDisplayParts { get; } = suffixDisplayParts ?? []; /// /// Display parts for this parameter. This should normally be presented to the user as part /// of the entire signature display. /// - public IList DisplayParts { get; } = displayParts.ToImmutableArrayOrEmpty(); + public ImmutableArray DisplayParts { get; } = displayParts.NullToEmpty(); /// /// True if this parameter is optional or not. Optional parameters may be presented in a @@ -63,16 +61,12 @@ internal sealed class SignatureHelpSymbolParameter( /// Display parts for this parameter that should be presented to the user when this /// parameter is selected. /// - public IList SelectedDisplayParts { get; } = selectedDisplayParts.ToImmutableArrayOrEmpty(); + public ImmutableArray SelectedDisplayParts { get; } = selectedDisplayParts ?? []; private static readonly Func> s_emptyDocumentationFactory = _ => []; - internal IEnumerable GetAllParts() - { - return PrefixDisplayParts.Concat(DisplayParts) - .Concat(SuffixDisplayParts) - .Concat(SelectedDisplayParts); - } + internal ImmutableArray GetAllParts() + => [.. PrefixDisplayParts, .. DisplayParts, .. SuffixDisplayParts, .. SelectedDisplayParts]; public static explicit operator SignatureHelpParameter(SignatureHelpSymbolParameter parameter) { @@ -89,10 +83,10 @@ internal sealed class SignatureHelpParameter( string? name, bool isOptional, Func>? documentationFactory, - IEnumerable displayParts, - IEnumerable? prefixDisplayParts = null, - IEnumerable? suffixDisplayParts = null, - IEnumerable? selectedDisplayParts = null) + ImmutableArray displayParts, + ImmutableArray? prefixDisplayParts = null, + ImmutableArray? suffixDisplayParts = null, + ImmutableArray? selectedDisplayParts = null) { /// /// The name of this parameter. @@ -108,18 +102,18 @@ internal sealed class SignatureHelpParameter( /// /// Display parts to show before the normal display parts for the parameter. /// - public IList PrefixDisplayParts { get; } = prefixDisplayParts.ToImmutableArrayOrEmpty(); + public ImmutableArray PrefixDisplayParts { get; } = prefixDisplayParts ?? []; /// /// Display parts to show after the normal display parts for the parameter. /// - public IList SuffixDisplayParts { get; } = suffixDisplayParts.ToImmutableArrayOrEmpty(); + public ImmutableArray SuffixDisplayParts { get; } = suffixDisplayParts ?? []; /// /// Display parts for this parameter. This should normally be presented to the user as part /// of the entire signature display. /// - public IList DisplayParts { get; } = displayParts.ToImmutableArrayOrEmpty(); + public ImmutableArray DisplayParts { get; } = displayParts.NullToEmpty(); /// /// True if this parameter is optional or not. Optional parameters may be presented in a @@ -131,7 +125,7 @@ internal sealed class SignatureHelpParameter( /// Display parts for this parameter that should be presented to the user when this /// parameter is selected. /// - public IList SelectedDisplayParts { get; } = selectedDisplayParts.ToImmutableArrayOrEmpty(); + public ImmutableArray SelectedDisplayParts { get; } = selectedDisplayParts ?? []; private static readonly Func> s_emptyDocumentationFactory = _ => []; @@ -140,10 +134,10 @@ public SignatureHelpParameter( string name, bool isOptional, Func>? documentationFactory, - IEnumerable displayParts, - IEnumerable? prefixDisplayParts = null, - IEnumerable? suffixDisplayParts = null, - IEnumerable? selectedDisplayParts = null) + ImmutableArray displayParts, + ImmutableArray? prefixDisplayParts = null, + ImmutableArray? suffixDisplayParts = null, + ImmutableArray? selectedDisplayParts = null) : this(name, isOptional, documentationFactory is null ? null : c => documentationFactory(c).ToTaggedText(), displayParts.ToTaggedText(), @@ -153,12 +147,8 @@ public SignatureHelpParameter( { } - internal IEnumerable GetAllParts() - { - return PrefixDisplayParts.Concat(DisplayParts) - .Concat(SuffixDisplayParts) - .Concat(SelectedDisplayParts); - } + internal ImmutableArray GetAllParts() + => [.. PrefixDisplayParts, .. DisplayParts, .. SuffixDisplayParts, .. SelectedDisplayParts]; public override string ToString() { diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/AbstractIntrinsicOperatorSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/AbstractIntrinsicOperatorSignatureHelpProvider.vb index ed3d8826fd253..ca9c3bd2fa902 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/AbstractIntrinsicOperatorSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/AbstractIntrinsicOperatorSignatureHelpProvider.vb @@ -5,6 +5,7 @@ Imports System.Threading Imports Microsoft.CodeAnalysis.Collections Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators @@ -37,7 +38,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Return Nothing End If - Dim items As New List(Of SignatureHelpItem) + Dim items = ArrayBuilder(Of SignatureHelpItem).GetInstance() Dim semanticModel = Await document.ReuseExistingSpeculativeModelAsync(node, cancellationToken).ConfigureAwait(False) For Each documentation In Await GetIntrinsicOperatorDocumentationAsync(node, document, cancellationToken).ConfigureAwait(False) @@ -49,12 +50,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim syntaxFacts = document.GetLanguageService(Of ISyntaxFactsService) Return CreateSignatureHelpItems( - items, textSpan, + items.ToImmutableAndFree(), textSpan, GetCurrentArgumentState(root, position, syntaxFacts, textSpan, cancellationToken), selectedItemIndex:=Nothing, parameterIndexOverride:=-1) End Function Friend Shared Function GetSignatureHelpItemForIntrinsicOperator(document As Document, semanticModel As SemanticModel, position As Integer, documentation As AbstractIntrinsicOperatorDocumentation, cancellationToken As CancellationToken) As SignatureHelpItem - Dim parameters As New List(Of SignatureHelpSymbolParameter) + Dim parameters = ArrayBuilder(Of SignatureHelpSymbolParameter).GetInstance() For i = 0 To documentation.ParameterCount - 1 Dim capturedIndex = i @@ -78,7 +79,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp prefixParts:=documentation.PrefixParts, separatorParts:=GetSeparatorParts(), suffixParts:=suffixParts, - parameters:=parameters) + parameters:=parameters.ToImmutableAndFree()) End Function Protected Overridable Function GetCurrentArgumentStateWorker(node As SyntaxNode, position As Integer) As SignatureHelpState diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.vb index 7ff272a7a8f25..c2d65fab1d1c5 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.vb @@ -2,13 +2,15 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp - friend MustInherit class AbstractOrdinaryMethodSignatureHelpProvider - inherits AbstractVisualBasicSignatureHelpProvider + Friend MustInherit Class AbstractOrdinaryMethodSignatureHelpProvider + Inherits AbstractVisualBasicSignatureHelpProvider Protected Shared Function ConvertMemberGroupMember(document As Document, member As ISymbol, @@ -26,11 +28,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp GetMemberGroupPreambleParts(member, semanticModel, position), GetSeparatorParts(), GetMemberGroupPostambleParts(member, semanticModel, position), - member.GetParameters().Select(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService)).ToList()) + member.GetParameters().SelectAsArray(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService))) End Function - Private Shared Function GetMemberGroupPreambleParts(symbol As ISymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetMemberGroupPreambleParts(symbol As ISymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() AddExtensionPreamble(symbol, result) @@ -44,13 +46,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp result.AddRange(symbol.ToMinimalDisplayParts(semanticModel, position, format)) result.Add(Punctuation(SyntaxKind.OpenParenToken)) - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetMemberGroupPostambleParts(symbol As ISymbol, - semanticModel As SemanticModel, - position As Integer) As IList(Of SymbolDisplayPart) - Dim parts = New List(Of SymbolDisplayPart) + Private Shared Function GetMemberGroupPostambleParts( + symbol As ISymbol, + semanticModel As SemanticModel, + position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim parts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() parts.Add(Punctuation(SyntaxKind.CloseParenToken)) If TypeOf symbol Is IMethodSymbol Then @@ -70,7 +73,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp parts.AddRange([property].Type.ToMinimalDisplayParts(semanticModel, position)) End If - Return parts + Return parts.ToImmutableAndFree() End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/AbstractVisualBasicSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/AbstractVisualBasicSignatureHelpProvider.vb index 1421a16fd87ef..cce684ddaf9d5 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/AbstractVisualBasicSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/AbstractVisualBasicSignatureHelpProvider.vb @@ -2,7 +2,9 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable Imports Microsoft.CodeAnalysis.DocumentationComments +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp @@ -34,8 +36,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Return New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, vbCrLf) End Function - Protected Shared Function GetSeparatorParts() As IList(Of SymbolDisplayPart) - Return {Punctuation(SyntaxKind.CommaToken), Space()} + Protected Shared Function GetSeparatorParts() As ImmutableArray(Of SymbolDisplayPart) + Return ImmutableArray.Create(Punctuation(SyntaxKind.CommaToken), Space()) End Function Protected Shared Function Convert(parameter As IParameterSymbol, @@ -48,7 +50,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp parameter.ToMinimalDisplayParts(semanticModel, position)) End Function - Protected Shared Sub AddExtensionPreamble(symbol As ISymbol, result As IList(Of SymbolDisplayPart)) + Protected Shared Sub AddExtensionPreamble(symbol As ISymbol, result As ArrayBuilder(Of SymbolDisplayPart)) If symbol.GetOriginalUnreducedDefinition().IsExtensionMethod() Then result.Add(Punctuation(SyntaxKind.LessThanToken)) result.Add(Text(VBFeaturesResources.Extension)) diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/AttributeSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/AttributeSignatureHelpProvider.vb index e5e5f91776863..5e9c39a25533e 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/AttributeSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/AttributeSignatureHelpProvider.vb @@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -84,8 +85,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim symbolInfo = semanticModel.GetSymbolInfo(attribute, cancellationToken) Dim selectedItem = TryGetSelectedIndex(accessibleConstructors, symbolInfo.Symbol) - Return CreateSignatureHelpItems(accessibleConstructors.Select( - Function(c) Convert(c, within, attribute, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)).ToList(), + Return CreateSignatureHelpItems(accessibleConstructors.SelectAsArray( + Function(c) Convert(c, within, attribute, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)), textSpan, GetCurrentArgumentState(root, position, syntaxFacts, textSpan, cancellationToken), selectedItem, parameterIndexOverride:=-1) End Function @@ -109,7 +110,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim position = attribute.SpanStart Dim namedParameters = constructor.ContainingType.GetAttributeNamedParameters(semanticModel.Compilation, within). OrderBy(Function(s) s.Name). - ToList() + ToImmutableArray() Dim isVariadic = constructor.Parameters.Length > 0 AndAlso constructor.Parameters.Last().IsParams AndAlso namedParameters.Count = 0 @@ -126,12 +127,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Return item End Function - Private Shared Function GetParameters(constructor As IMethodSymbol, - semanticModel As SemanticModel, - position As Integer, - namedParameters As List(Of ISymbol), - documentationCommentFormattingService As IDocumentationCommentFormattingService) As IList(Of SignatureHelpSymbolParameter) - Dim result = New List(Of SignatureHelpSymbolParameter) + Private Shared Function GetParameters( + constructor As IMethodSymbol, + semanticModel As SemanticModel, + position As Integer, + namedParameters As ImmutableArray(Of ISymbol), + documentationCommentFormattingService As IDocumentationCommentFormattingService) As ImmutableArray(Of SignatureHelpSymbolParameter) + Dim result = ArrayBuilder(Of SignatureHelpSymbolParameter).GetInstance() For Each parameter In constructor.Parameters result.Add(Convert(parameter, semanticModel, position, documentationCommentFormattingService)) @@ -144,7 +146,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp DirectCast(namedParameter, IFieldSymbol).Type, DirectCast(namedParameter, IPropertySymbol).Type) - Dim displayParts = New List(Of SymbolDisplayPart) + Dim displayParts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() displayParts.Add(New SymbolDisplayPart( If(TypeOf namedParameter Is IFieldSymbol, SymbolDisplayPartKind.FieldName, SymbolDisplayPartKind.PropertyName), @@ -156,34 +158,33 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp namedParameter.Name, isOptional:=True, documentationFactory:=namedParameter.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormattingService), - displayParts:=displayParts, + displayParts:=displayParts.ToImmutableAndFree(), prefixDisplayParts:=GetParameterPrefixDisplayParts(i))) Next - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetParameterPrefixDisplayParts(i As Integer) As List(Of SymbolDisplayPart) + Private Shared Function GetParameterPrefixDisplayParts(i As Integer) As ImmutableArray(Of SymbolDisplayPart) If i = 0 Then - Return New List(Of SymbolDisplayPart) From { + Return ImmutableArray.Create( New SymbolDisplayPart(SymbolDisplayPartKind.Text, Nothing, FeaturesResources.Properties), Punctuation(SyntaxKind.ColonToken), - Space() - } + Space()) End If Return Nothing End Function - Private Shared Function GetPreambleParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetPreambleParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() result.AddRange(method.ContainingType.ToMinimalDisplayParts(semanticModel, position)) result.Add(Punctuation(SyntaxKind.OpenParenToken)) - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetPostambleParts() As IList(Of SymbolDisplayPart) - Return {Punctuation(SyntaxKind.CloseParenToken)} + Private Shared Function GetPostambleParts() As ImmutableArray(Of SymbolDisplayPart) + Return ImmutableArray.Create(Punctuation(SyntaxKind.CloseParenToken)) End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/CollectionInitializerSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/CollectionInitializerSignatureHelpProvider.vb index 56acafe0aa155..1f79cf7cb1ec2 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/CollectionInitializerSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/CollectionInitializerSignatureHelpProvider.vb @@ -60,7 +60,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim semanticModel = Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False) Return CreateCollectionInitializerSignatureHelpItems( - addMethods.Select(Function(s) ConvertMemberGroupMember(document, s, collectionInitializer.OpenBraceToken.SpanStart, semanticModel)).ToList(), + addMethods.SelectAsArray(Function(s) ConvertMemberGroupMember(document, s, collectionInitializer.OpenBraceToken.SpanStart, semanticModel)), textSpan, GetCurrentArgumentState(root, position, syntaxFacts, textSpan, cancellationToken)) End Function diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/FunctionAggregationSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/FunctionAggregationSignatureHelpProvider.vb index f99edead13eef..fe9493630613f 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/FunctionAggregationSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/FunctionAggregationSignatureHelpProvider.vb @@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.Collections Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -86,7 +87,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim syntaxFacts = document.GetLanguageService(Of ISyntaxFactsService) Return CreateSignatureHelpItems( - accessibleMethods.Select(Function(m) Convert(m, functionAggregation, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)).ToList(), + accessibleMethods.SelectAsArray(Function(m) Convert(m, functionAggregation, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)), textSpan, GetCurrentArgumentState(root, position, syntaxFacts, textSpan, cancellationToken), selectedItemIndex:=Nothing, parameterIndexOverride:=-1) End Function @@ -108,18 +109,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Return item End Function - Private Shared Function GetPreambleParts(method As IMethodSymbol) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetPreambleParts(method As IMethodSymbol) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() AddExtensionPreamble(method, result) result.AddMethodName(method.Name) result.Add(Punctuation(SyntaxKind.OpenParenToken)) - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetPostambleParts(method As IMethodSymbol, - semanticModel As SemanticModel, - position As Integer) As IList(Of SymbolDisplayPart) - Dim parts = New List(Of SymbolDisplayPart) + Private Shared Function GetPostambleParts( + method As IMethodSymbol, + semanticModel As SemanticModel, + position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim parts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() parts.Add(Punctuation(SyntaxKind.CloseParenToken)) If Not method.ReturnsVoid Then @@ -129,14 +131,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp parts.AddRange(method.ReturnType.ToMinimalDisplayParts(semanticModel, position)) End If - Return parts + Return parts.ToImmutableAndFree() End Function - Private Shared Function GetParameterParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer, - documentationCommentFormattingService As IDocumentationCommentFormattingService) As IList(Of SignatureHelpSymbolParameter) + Private Shared Function GetParameterParts( + method As IMethodSymbol, + semanticModel As SemanticModel, + position As Integer, + documentationCommentFormattingService As IDocumentationCommentFormattingService) As ImmutableArray(Of SignatureHelpSymbolParameter) ' Function () As If method.Parameters.Length <> 1 Then - Return SpecializedCollections.EmptyList(Of SignatureHelpSymbolParameter)() + Return ImmutableArray(Of SignatureHelpSymbolParameter).Empty End If ' Function (selector as Func(Of T, R)) As R @@ -148,7 +153,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp delegateInvokeMethod.Parameters.Length = 1 AndAlso Not delegateInvokeMethod.ReturnsVoid Then - Dim parts = New List(Of SymbolDisplayPart) + Dim parts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() parts.Add(Text(VBWorkspaceResources.expression)) parts.Add(Space()) parts.Add(Keyword(SyntaxKind.AsKeyword)) @@ -159,13 +164,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp VBWorkspaceResources.expression, parameter.IsOptional, parameter.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormattingService), - parts) + parts.ToImmutableAndFree()) - Return {sigHelpParameter} + Return ImmutableArray.Create(sigHelpParameter) End If End If - Return SpecializedCollections.EmptyList(Of SignatureHelpSymbolParameter)() + Return ImmutableArray(Of SignatureHelpSymbolParameter).Empty End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.Method.vb b/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.Method.vb index 85fed14828d91..ee66f71255869 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.Method.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.Method.vb @@ -2,12 +2,13 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. -Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp +Imports System.Collections.Immutable +Imports Microsoft.CodeAnalysis.PooledObjects +Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Partial Friend Class GenericNameSignatureHelpProvider - - Private Shared Function GetPreambleParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetPreambleParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() AddExtensionPreamble(method, result) @@ -22,7 +23,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp result.Add(Punctuation(SyntaxKind.OpenParenToken)) result.Add(Keyword(SyntaxKind.OfKeyword)) result.Add(Space()) - Return result + Return result.ToImmutableAndFree() End Function Private Shared Function GetContainingType(method As IMethodSymbol) As ITypeSymbol @@ -35,8 +36,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp End If End Function - Private Shared Function GetPostambleParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetPostambleParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() result.Add(Punctuation(SyntaxKind.CloseParenToken)) result.Add(Punctuation(SyntaxKind.OpenParenToken)) @@ -60,7 +61,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp result.AddRange(method.ReturnType.ToMinimalDisplayParts(semanticModel, position)) End If - Return result + Return result.ToImmutableAndFree() End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.NamedType.vb b/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.NamedType.vb index 48240e10b8756..4dc0f506b400b 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.NamedType.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.NamedType.vb @@ -2,12 +2,15 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable +Imports Microsoft.CodeAnalysis.PooledObjects + Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Partial Friend Class GenericNameSignatureHelpProvider - Private Shared Function GetPreambleParts(namedType As INamedTypeSymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetPreambleParts(namedType As INamedTypeSymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() Dim format = New SymbolDisplayFormat( memberOptions:=SymbolDisplayMemberOptions.IncludeContainingType, miscellaneousOptions:=SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers Or SymbolDisplayMiscellaneousOptions.UseSpecialTypes) @@ -15,11 +18,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp result.Add(Punctuation(SyntaxKind.OpenParenToken)) result.Add(Keyword(SyntaxKind.OfKeyword)) result.Add(Space()) - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetPostambleParts() As IList(Of SymbolDisplayPart) - Return {Punctuation(SyntaxKind.CloseParenToken)} + Private Shared Function GetPostambleParts() As ImmutableArray(Of SymbolDisplayPart) + Return ImmutableArray.Create(Punctuation(SyntaxKind.CloseParenToken)) End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.vb index 1650b1b6f6865..ca768d60b3ed0 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/GenericNameSignatureHelpProvider.vb @@ -8,6 +8,7 @@ Imports System.Threading Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -107,7 +108,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim _syntaxFacts = document.GetLanguageService(Of ISyntaxFactsService) Return CreateSignatureHelpItems( - accessibleSymbols.Select(Function(s) Convert(s, genericName, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)).ToList(), + accessibleSymbols.SelectAsArray(Function(s) Convert(s, genericName, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)), textSpan, GetCurrentArgumentState(root, position, _syntaxFacts, textSpan, cancellationToken), selectedItemIndex:=Nothing, parameterIndexOverride:=-1) End Function @@ -124,7 +125,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp GetPreambleParts(namedType, semanticModel, position), GetSeparatorParts(), GetPostambleParts(), - namedType.TypeParameters.Select(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService)).ToList()) + namedType.TypeParameters.SelectAsArray(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService))) Else Dim method = DirectCast(symbol, IMethodSymbol) item = CreateItem( @@ -135,7 +136,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp GetPreambleParts(method, semanticModel, position), GetSeparatorParts(), GetPostambleParts(method, semanticModel, position), - method.TypeParameters.Select(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService)).ToList()) + method.TypeParameters.SelectAsArray(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService))) End If Return item @@ -144,7 +145,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Private Shared ReadOnly s_minimallyQualifiedFormat As SymbolDisplayFormat = SymbolDisplayFormat.MinimallyQualifiedFormat.WithGenericsOptions(SymbolDisplayFormat.MinimallyQualifiedFormat.GenericsOptions Or SymbolDisplayGenericsOptions.IncludeVariance) Private Overloads Shared Function Convert(parameter As ITypeParameterSymbol, semanticModel As SemanticModel, position As Integer, documentationCommentFormattingService As IDocumentationCommentFormattingService) As SignatureHelpSymbolParameter - Dim parts = New List(Of SymbolDisplayPart) + Dim parts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() parts.AddRange(parameter.ToMinimalDisplayParts(semanticModel, position, s_minimallyQualifiedFormat)) AddConstraints(parameter, parts, semanticModel, position) @@ -152,13 +153,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp parameter.Name, isOptional:=False, documentationFactory:=parameter.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormattingService), - displayParts:=parts) + displayParts:=parts.ToImmutableAndFree()) End Function - Private Shared Function AddConstraints(typeParam As ITypeParameterSymbol, - parts As List(Of SymbolDisplayPart), - semanticModel As SemanticModel, - position As Integer) As IList(Of SymbolDisplayPart) + Private Shared Sub AddConstraints( + typeParam As ITypeParameterSymbol, + parts As ArrayBuilder(Of SymbolDisplayPart), + semanticModel As SemanticModel, + position As Integer) Dim constraintTypes = typeParam.ConstraintTypes Dim constraintCount = TypeParameterSpecialConstraintCount(typeParam) + constraintTypes.Length @@ -203,9 +205,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp parts.Add(Punctuation(SyntaxKind.CloseBraceToken)) End If End If - - Return parts - End Function + End Sub Private Shared Function TypeParameterSpecialConstraintCount(typeParam As ITypeParameterSymbol) As Integer Return If(typeParam.HasReferenceTypeConstraint, 1, 0) + diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.DelegateInvoke.vb b/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.DelegateInvoke.vb index bb409778cc4fd..3452cd42c4323 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.DelegateInvoke.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.DelegateInvoke.vb @@ -2,10 +2,12 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable Imports System.Threading Imports Microsoft.CodeAnalysis.Collections Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -37,8 +39,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Return SpecializedCollections.SingletonEnumerable(item) End Function - Private Shared Function GetDelegateInvokePreambleParts(invokeMethod As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim displayParts = New List(Of SymbolDisplayPart)() + Private Shared Function GetDelegateInvokePreambleParts(invokeMethod As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim displayParts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() If invokeMethod.ContainingType.IsAnonymousType Then displayParts.Add(New SymbolDisplayPart(SymbolDisplayPartKind.MethodName, invokeMethod, invokeMethod.Name)) @@ -47,11 +49,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp End If displayParts.Add(Punctuation(SyntaxKind.OpenParenToken)) - Return displayParts + Return displayParts.ToImmutableAndFree() End Function - Private Shared Function GetDelegateInvokeParameters(invokeMethod As IMethodSymbol, semanticModel As SemanticModel, position As Integer, documentationCommentFormattingService As IDocumentationCommentFormattingService, cancellationToken As CancellationToken) As IList(Of SignatureHelpSymbolParameter) - Dim parameters = New List(Of SignatureHelpSymbolParameter) + Private Shared Function GetDelegateInvokeParameters(invokeMethod As IMethodSymbol, semanticModel As SemanticModel, position As Integer, documentationCommentFormattingService As IDocumentationCommentFormattingService, cancellationToken As CancellationToken) As ImmutableArray(Of SignatureHelpSymbolParameter) + Dim parameters = ArrayBuilder(Of SignatureHelpSymbolParameter).GetInstance() For Each parameter In invokeMethod.Parameters cancellationToken.ThrowIfCancellationRequested() parameters.Add(New SignatureHelpSymbolParameter( @@ -61,13 +63,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp displayParts:=parameter.ToMinimalDisplayParts(semanticModel, position))) Next - Return parameters + Return parameters.ToImmutableAndFree() End Function - Private Shared Function GetDelegateInvokePostambleParts(invokeMethod As IMethodSymbol, - semanticModel As SemanticModel, - position As Integer) As IList(Of SymbolDisplayPart) - Dim parts = New List(Of SymbolDisplayPart) + Private Shared Function GetDelegateInvokePostambleParts( + invokeMethod As IMethodSymbol, + semanticModel As SemanticModel, + position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim parts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() parts.Add(Punctuation(SyntaxKind.CloseParenToken)) @@ -78,7 +81,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp parts.AddRange(invokeMethod.ReturnType.ToMinimalDisplayParts(semanticModel, position)) End If - Return parts + Return parts.ToImmutableAndFree() End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.ElementAccess.vb b/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.ElementAccess.vb index 3fc0bbf04f980..e0a4a95021851 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.ElementAccess.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.ElementAccess.vb @@ -2,10 +2,12 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable Imports System.Threading Imports Microsoft.CodeAnalysis.Collections Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -13,13 +15,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Partial Friend Class InvocationExpressionSignatureHelpProvider - Private Shared Function GetElementAccessItems(leftExpression As ExpressionSyntax, - semanticModel As SemanticModel, - structuralTypeDisplayService As IStructuralTypeDisplayService, - documentationCommentFormattingService As IDocumentationCommentFormattingService, - within As ISymbol, - defaultProperties As IList(Of IPropertySymbol), - cancellationToken As CancellationToken) As IEnumerable(Of SignatureHelpItem) + Private Shared Function GetElementAccessItems( + leftExpression As ExpressionSyntax, + semanticModel As SemanticModel, + structuralTypeDisplayService As IStructuralTypeDisplayService, + documentationCommentFormattingService As IDocumentationCommentFormattingService, + within As ISymbol, + defaultProperties As ImmutableArray(Of IPropertySymbol), + cancellationToken As CancellationToken) As IEnumerable(Of SignatureHelpItem) Dim throughType As ITypeSymbol = Nothing If leftExpression IsNot Nothing Then throughType = semanticModel.GetTypeInfo(leftExpression, cancellationToken).Type @@ -47,21 +50,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp GetIndexerPreambleParts(indexer, semanticModel, position), GetSeparatorParts(), GetIndexerPostambleParts(indexer, semanticModel, position), - indexer.Parameters.Select(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService)).ToList()) + indexer.Parameters.SelectAsArray(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService))) Return item End Function - Private Shared Function GetIndexerPreambleParts(symbol As IPropertySymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetIndexerPreambleParts(symbol As IPropertySymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() result.AddRange(symbol.ContainingType.ToMinimalDisplayParts(semanticModel, position)) result.Add(Punctuation(SyntaxKind.OpenParenToken)) - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetIndexerPostambleParts(symbol As IPropertySymbol, - semanticModel As SemanticModel, - position As Integer) As IList(Of SymbolDisplayPart) - Dim parts = New List(Of SymbolDisplayPart) + Private Shared Function GetIndexerPostambleParts( + symbol As IPropertySymbol, + semanticModel As SemanticModel, + position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim parts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() parts.Add(Punctuation(SyntaxKind.CloseParenToken)) Dim [property] = DirectCast(symbol, IPropertySymbol) @@ -71,8 +75,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp parts.Add(Space()) parts.AddRange([property].Type.ToMinimalDisplayParts(semanticModel, position)) - Return parts + Return parts.ToImmutableAndFree() End Function - End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.vb index 4d223d56bf7a3..1d97feed90612 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/InvocationExpressionSignatureHelpProvider.vb @@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.Collections Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -101,18 +102,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim expressionType = If(typeInfo.Type, typeInfo.ConvertedType) Dim defaultProperties = If(expressionType Is Nothing, - SpecializedCollections.EmptyList(Of IPropertySymbol), - semanticModel.LookupSymbols(position, expressionType, includeReducedExtensionMethods:=True). - OfType(Of IPropertySymbol). - ToImmutableArrayOrEmpty(). - WhereAsArray(Function(p) p.IsIndexer). - FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols(options.HideAdvancedMembers, semanticModel.Compilation). - Sort(semanticModel, invocationExpression.SpanStart)) + ImmutableArray(Of IPropertySymbol).Empty, + semanticModel.LookupSymbols(position, expressionType, includeReducedExtensionMethods:=True). + OfType(Of IPropertySymbol). + ToImmutableArrayOrEmpty(). + WhereAsArray(Function(p) p.IsIndexer). + FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols(options.HideAdvancedMembers, semanticModel.Compilation). + Sort(semanticModel, invocationExpression.SpanStart)) Dim structuralTypeDisplayService = document.GetLanguageService(Of IStructuralTypeDisplayService)() Dim documentationCommentFormattingService = document.GetLanguageService(Of IDocumentationCommentFormattingService)() - Dim items = New List(Of SignatureHelpItem) + Dim items = ArrayBuilder(Of SignatureHelpItem).GetInstance() Dim accessibleMembers = ImmutableArray(Of ISymbol).Empty If memberGroup.Length > 0 Then accessibleMembers = GetAccessibleMembers(invocationExpression, semanticModel, within, memberGroup, cancellationToken) @@ -132,7 +133,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim selectedItem = TryGetSelectedIndex(accessibleMembers, symbolInfo.Symbol) Return CreateSignatureHelpItems( - items, textSpan, GetCurrentArgumentState(root, position, syntaxFacts, textSpan, cancellationToken), + items.ToImmutableAndFree(), textSpan, GetCurrentArgumentState(root, position, syntaxFacts, textSpan, cancellationToken), selectedItem, parameterIndexOverride:=-1) End Function End Class diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider.DelegateType.vb b/src/Features/VisualBasic/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider.DelegateType.vb index 8936e239cec80..dadbe719e489a 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider.DelegateType.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider.DelegateType.vb @@ -2,21 +2,22 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable Imports Microsoft.CodeAnalysis.Collections Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp - Partial Friend Class ObjectCreationExpressionSignatureHelpProvider - - Private Shared Function GetDelegateTypeConstructors(objectCreationExpression As ObjectCreationExpressionSyntax, - semanticModel As SemanticModel, - structuralTypeDisplayService As IStructuralTypeDisplayService, - documentationCommentFormattingService As IDocumentationCommentFormattingService, - delegateType As INamedTypeSymbol) As (items As IList(Of SignatureHelpItem), selectedItem As Integer?) + Private Shared Function GetDelegateTypeConstructors( + objectCreationExpression As ObjectCreationExpressionSyntax, + semanticModel As SemanticModel, + structuralTypeDisplayService As IStructuralTypeDisplayService, + documentationCommentFormattingService As IDocumentationCommentFormattingService, + delegateType As INamedTypeSymbol) As (items As ImmutableArray(Of SignatureHelpItem), selectedItem As Integer?) Dim invokeMethod = delegateType.DelegateInvokeMethod If invokeMethod Is Nothing Then Return (Nothing, Nothing) @@ -33,20 +34,20 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp suffixParts:=GetDelegateTypePostambleParts(), parameters:=GetDelegateTypeParameters(invokeMethod, semanticModel, position)) - Return (SpecializedCollections.SingletonList(item), 0) + Return (ImmutableArray.Create(item), 0) End Function - Private Shared Function GetDelegateTypePreambleParts(invokeMethod As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetDelegateTypePreambleParts(invokeMethod As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() result.AddRange(invokeMethod.ContainingType.ToMinimalDisplayParts(semanticModel, position)) result.Add(Punctuation(SyntaxKind.OpenParenToken)) - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetDelegateTypeParameters(invokeMethod As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SignatureHelpSymbolParameter) + Private Shared Function GetDelegateTypeParameters(invokeMethod As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SignatureHelpSymbolParameter) Const TargetName As String = "target" - Dim parts = New List(Of SymbolDisplayPart)() + Dim parts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() If invokeMethod.ReturnsVoid Then parts.Add(Keyword(SyntaxKind.SubKeyword)) @@ -77,15 +78,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp parts.AddRange(invokeMethod.ReturnType.ToMinimalDisplayParts(semanticModel, position)) End If - Return {New SignatureHelpSymbolParameter( + Return ImmutableArray.Create(New SignatureHelpSymbolParameter( TargetName, isOptional:=False, documentationFactory:=Nothing, - displayParts:=parts)} + displayParts:=parts.ToImmutableAndFree())) End Function - Private Shared Function GetDelegateTypePostambleParts() As IList(Of SymbolDisplayPart) - Return {Punctuation(SyntaxKind.CloseParenToken)} + Private Shared Function GetDelegateTypePostambleParts() As ImmutableArray(Of SymbolDisplayPart) + Return ImmutableArray.Create(Punctuation(SyntaxKind.CloseParenToken)) End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider.NormalType.vb b/src/Features/VisualBasic/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider.NormalType.vb index f2b58e7f0026d..c1be3d8a9637c 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider.NormalType.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider.NormalType.vb @@ -2,10 +2,12 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable Imports System.Threading Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -20,7 +22,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp structuralTypeDisplayService As IStructuralTypeDisplayService, normalType As INamedTypeSymbol, within As ISymbol, - options As MemberDisplayOptions, cancellationToken As CancellationToken) As (items As IList(Of SignatureHelpItem), selectedItem As Integer?) + options As MemberDisplayOptions, cancellationToken As CancellationToken) As (items As ImmutableArray(Of SignatureHelpItem), selectedItem As Integer?) Dim accessibleConstructors = normalType.InstanceConstructors. WhereAsArray(Function(c) c.IsAccessibleWithin(within)). @@ -33,8 +35,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim documentationCommentFormattingService = document.GetLanguageService(Of IDocumentationCommentFormattingService)() - Dim items = accessibleConstructors.Select( - Function(c) ConvertNormalTypeConstructor(c, objectCreationExpression, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)).ToList() + Dim items = accessibleConstructors.SelectAsArray( + Function(c) ConvertNormalTypeConstructor(c, objectCreationExpression, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)) Dim currentConstructor = semanticModel.GetSymbolInfo(objectCreationExpression, cancellationToken) Dim selectedItem = TryGetSelectedIndex(accessibleConstructors, currentConstructor.Symbol) @@ -53,19 +55,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp constructor.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormattingService), GetNormalTypePreambleParts(constructor, semanticModel, position), GetSeparatorParts(), GetNormalTypePostambleParts(), - constructor.Parameters.Select(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService)).ToList()) + constructor.Parameters.SelectAsArray(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService))) Return item End Function - Private Shared Function GetNormalTypePreambleParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As IList(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Private Shared Function GetNormalTypePreambleParts(method As IMethodSymbol, semanticModel As SemanticModel, position As Integer) As ImmutableArray(Of SymbolDisplayPart) + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() result.AddRange(method.ContainingType.ToMinimalDisplayParts(semanticModel, position)) result.Add(Punctuation(SyntaxKind.OpenParenToken)) - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetNormalTypePostambleParts() As IList(Of SymbolDisplayPart) - Return {Punctuation(SyntaxKind.CloseParenToken)} + Private Shared Function GetNormalTypePostambleParts() As ImmutableArray(Of SymbolDisplayPart) + Return ImmutableArray.Create(Punctuation(SyntaxKind.CloseParenToken)) End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/RaiseEventStatementSignatureHelpProvider.vb b/src/Features/VisualBasic/Portable/SignatureHelp/RaiseEventStatementSignatureHelpProvider.vb index acfbe505a74ca..d76944bac93c4 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/RaiseEventStatementSignatureHelpProvider.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/RaiseEventStatementSignatureHelpProvider.vb @@ -8,6 +8,7 @@ Imports System.Threading Imports Microsoft.CodeAnalysis.DocumentationComments Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.LanguageService +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.SignatureHelp Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -93,7 +94,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp Dim syntaxFacts = document.GetLanguageService(Of ISyntaxFactsService) Return CreateSignatureHelpItems( - allowedEvents.Select(Function(e) Convert(e, raiseEventStatement, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)).ToList(), + allowedEvents.SelectAsArray(Function(e) Convert(e, raiseEventStatement, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)), textSpan, GetCurrentArgumentState(root, position, syntaxFacts, textSpan, cancellationToken), selectedItemIndex:=Nothing, parameterIndexOverride:=-1) End Function @@ -117,18 +118,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp GetPreambleParts(eventSymbol, semanticModel, position), GetSeparatorParts(), GetPostambleParts(), - type.DelegateInvokeMethod.GetParameters().Select(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService)).ToList()) + type.DelegateInvokeMethod.GetParameters().SelectAsArray(Function(p) Convert(p, semanticModel, position, documentationCommentFormattingService))) Return item End Function Private Shared Function GetPreambleParts( - eventSymbol As IEventSymbol, - semanticModel As SemanticModel, - position As Integer - ) As IList(Of SymbolDisplayPart) + eventSymbol As IEventSymbol, + semanticModel As SemanticModel, + position As Integer) As ImmutableArray(Of SymbolDisplayPart) - Dim result = New List(Of SymbolDisplayPart)() + Dim result = ArrayBuilder(Of SymbolDisplayPart).GetInstance() result.AddRange(eventSymbol.ContainingType.ToMinimalDisplayParts(semanticModel, position)) result.Add(Punctuation(SyntaxKind.DotToken)) @@ -140,11 +140,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp result.AddRange(eventSymbol.ToMinimalDisplayParts(semanticModel, position, format)) result.Add(Punctuation(SyntaxKind.OpenParenToken)) - Return result + Return result.ToImmutableAndFree() End Function - Private Shared Function GetPostambleParts() As IList(Of SymbolDisplayPart) - Return {Punctuation(SyntaxKind.CloseParenToken)} + Private Shared Function GetPostambleParts() As ImmutableArray(Of SymbolDisplayPart) + Return ImmutableArray.Create(Punctuation(SyntaxKind.CloseParenToken)) End Function End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/SignatureHelp/SignatureHelpUtilities.vb b/src/Features/VisualBasic/Portable/SignatureHelp/SignatureHelpUtilities.vb index 816a7fcb4e0b6..584acf78a4887 100644 --- a/src/Features/VisualBasic/Portable/SignatureHelp/SignatureHelpUtilities.vb +++ b/src/Features/VisualBasic/Portable/SignatureHelp/SignatureHelpUtilities.vb @@ -7,7 +7,6 @@ Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp - Friend Module SignatureHelpUtilities Private ReadOnly s_getArgumentListOpenToken As Func(Of ArgumentListSyntax, SyntaxToken) = Function(list) list.OpenParenToken Private ReadOnly s_getTypeArgumentListOpenToken As Func(Of TypeArgumentListSyntax, SyntaxToken) = Function(list) list.OpenParenToken diff --git a/src/VisualStudio/ExternalAccess/FSharp/Internal/SignatureHelp/FSharpSignatureHelpProvider.cs b/src/VisualStudio/ExternalAccess/FSharp/Internal/SignatureHelp/FSharpSignatureHelpProvider.cs index 6c4fd7505e3c2..c6a503f7769c9 100644 --- a/src/VisualStudio/ExternalAccess/FSharp/Internal/SignatureHelp/FSharpSignatureHelpProvider.cs +++ b/src/VisualStudio/ExternalAccess/FSharp/Internal/SignatureHelp/FSharpSignatureHelpProvider.cs @@ -5,12 +5,12 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.ExternalAccess.FSharp.SignatureHelp; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.SignatureHelp; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.Internal.SignatureHelp; @@ -61,23 +61,23 @@ public FSharpSignatureHelpProvider( if (mappedSignatureHelpItems != null) { return new SignatureHelpItems( - mappedSignatureHelpItems.Items.Select(x => + mappedSignatureHelpItems.Items.SelectAsArray(x => new SignatureHelpItem( x.IsVariadic, x.DocumentationFactory, x.PrefixDisplayParts, x.SeparatorDisplayParts, x.SuffixDisplayParts, - x.Parameters.Select(y => + x.Parameters.SelectAsArray(y => new SignatureHelpParameter( y.Name, y.IsOptional, y.DocumentationFactory, - y.DisplayParts, - y.PrefixDisplayParts, - y.SuffixDisplayParts, - y.SelectedDisplayParts)).ToList(), - x.DescriptionParts)).ToList(), + y.DisplayParts.ToImmutableArrayOrEmpty(), + y.PrefixDisplayParts.ToImmutableArrayOrEmpty(), + y.SuffixDisplayParts.ToImmutableArrayOrEmpty(), + y.SelectedDisplayParts.ToImmutableArrayOrEmpty())), + x.DescriptionParts)), mappedSignatureHelpItems.ApplicableSpan, mappedSignatureHelpItems.ArgumentIndex, mappedSignatureHelpItems.ArgumentCount, diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SymbolDisplayPartExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SymbolDisplayPartExtensions.cs index b52deb8b4fcdc..17060dc98905f 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SymbolDisplayPartExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SymbolDisplayPartExtensions.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.Shared.Extensions; @@ -15,7 +16,7 @@ public static string GetFullText(this IEnumerable parts) public static void AddLineBreak(this IList parts, string text = "\r\n") => parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.LineBreak, null, text)); - public static void AddMethodName(this IList parts, string text) + public static void AddMethodName(this ArrayBuilder parts, string text) => parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.MethodName, null, text)); public static void AddPunctuation(this IList parts, string text) diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/AbstractIntrinsicOperatorDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/AbstractIntrinsicOperatorDocumentation.vb index 07194defb4c6a..0cce47cbe7700 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/AbstractIntrinsicOperatorDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/AbstractIntrinsicOperatorDocumentation.vb @@ -2,8 +2,10 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable Imports System.Threading Imports Microsoft.CodeAnalysis +Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators @@ -19,20 +21,20 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Get End Property - Public MustOverride ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) + Public MustOverride ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) Public MustOverride Function GetParameterName(index As Integer) As String Public MustOverride Function GetParameterDocumentation(index As Integer) As String - Public Overridable Function GetParameterDisplayParts(index As Integer) As IList(Of SymbolDisplayPart) - Return {New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, GetParameterName(index))} + Public Overridable Function GetParameterDisplayParts(index As Integer) As ImmutableArray(Of SymbolDisplayPart) + Return ImmutableArray.Create(New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, GetParameterName(index))) End Function Public Overridable Function TryGetTypeNameParameter(syntaxNode As SyntaxNode, index As Integer) As TypeSyntax Return Nothing End Function - Public Overridable Function GetSuffix(semanticModel As SemanticModel, position As Integer, nodeToBind As SyntaxNode, cancellationToken As CancellationToken) As IList(Of SymbolDisplayPart) - Dim suffixParts As New List(Of SymbolDisplayPart) + Public Overridable Function GetSuffix(semanticModel As SemanticModel, position As Integer, nodeToBind As SyntaxNode, cancellationToken As CancellationToken) As ImmutableArray(Of SymbolDisplayPart) + Dim suffixParts = ArrayBuilder(Of SymbolDisplayPart).GetInstance() If IncludeAsType Then suffixParts.Add(New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, ")")) @@ -44,7 +46,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Dim typeInfo = semanticModel.GetTypeInfo(nodeToBind, cancellationToken) If typeInfo.Type IsNot Nothing Then suffixParts.AddRange(typeInfo.Type.ToMinimalDisplayParts(semanticModel, position)) - Return suffixParts + Return suffixParts.ToImmutableAndFree() End If End If @@ -58,13 +60,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators suffixParts.Add(New SymbolDisplayPart(SymbolDisplayPartKind.Text, Nothing, ReturnTypeMetadataName)) End If - Return suffixParts + Return suffixParts.ToImmutableAndFree() End If suffixParts.Add(New SymbolDisplayPart(SymbolDisplayPartKind.Text, Nothing, VBWorkspaceResources.result)) End If - Return suffixParts + Return suffixParts.ToImmutableAndFree() End Function End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/AddHandlerStatementDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/AddHandlerStatementDocumentation.vb index bec3592ac4431..9ec15860e71af 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/AddHandlerStatementDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/AddHandlerStatementDocumentation.vb @@ -2,15 +2,14 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class AddHandlerStatementDocumentation Inherits AbstractAddRemoveHandlerStatementDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Associates_an_event_with_an_event_handler_delegate_or_lambda_expression_at_run_time - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Associates_an_event_with_an_event_handler_delegate_or_lambda_expression_at_run_time Public Overrides Function GetParameterDocumentation(index As Integer) As String Select Case index @@ -23,12 +22,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return {New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "AddHandler"), - New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " ")} - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "AddHandler"), + New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " ")) End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/BinaryConditionalExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/BinaryConditionalExpressionDocumentation.vb index afb48f4e935f7..89ea2262e8d8f 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/BinaryConditionalExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/BinaryConditionalExpressionDocumentation.vb @@ -2,15 +2,14 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class BinaryConditionalExpressionDocumentation Inherits AbstractIntrinsicOperatorDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.If_expression_evaluates_to_a_reference_or_Nullable_value_that_is_not_Nothing_the_function_returns_that_value_Otherwise_it_calculates_and_returns_expressionIfNothing - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.If_expression_evaluates_to_a_reference_or_Nullable_value_that_is_not_Nothing_the_function_returns_that_value_Otherwise_it_calculates_and_returns_expressionIfNothing Public Overrides Function GetParameterDocumentation(index As Integer) As String Select Case index @@ -34,23 +33,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides ReadOnly Property IncludeAsType As Boolean - Get - Return True - End Get - End Property - - Public Overrides ReadOnly Property ParameterCount As Integer - Get - Return 2 - End Get - End Property - - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return {New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "If"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")} - End Get - End Property + Public Overrides ReadOnly Property IncludeAsType As Boolean = True + + Public Overrides ReadOnly Property ParameterCount As Integer = 2 + + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "If"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/CTypeCastExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/CTypeCastExpressionDocumentation.vb index 0706915921c40..97a175782454e 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/CTypeCastExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/CTypeCastExpressionDocumentation.vb @@ -2,23 +2,17 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class CTypeCastExpressionDocumentation Inherits AbstractCastExpressionDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Returns_the_result_of_explicitly_converting_an_expression_to_a_specified_data_type - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Returns_the_result_of_explicitly_converting_an_expression_to_a_specified_data_type - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return { - New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "CType"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(") - } - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "CType"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/DirectCastExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/DirectCastExpressionDocumentation.vb index 5233f539329f1..c036a33d36c04 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/DirectCastExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/DirectCastExpressionDocumentation.vb @@ -2,23 +2,17 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class DirectCastExpressionDocumentation Inherits AbstractCastExpressionDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Introduces_a_type_conversion_operation_similar_to_CType_The_difference_is_that_CType_succeeds_as_long_as_there_is_a_valid_conversion_whereas_DirectCast_requires_that_one_type_inherit_from_or_implement_the_other_type - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Introduces_a_type_conversion_operation_similar_to_CType_The_difference_is_that_CType_succeeds_as_long_as_there_is_a_valid_conversion_whereas_DirectCast_requires_that_one_type_inherit_from_or_implement_the_other_type - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return { - New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "DirectCast"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(") - } - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "DirectCast"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/GetTypeExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/GetTypeExpressionDocumentation.vb index 333c15ae53834..41202eac35a56 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/GetTypeExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/GetTypeExpressionDocumentation.vb @@ -2,6 +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. +Imports System.Collections.Immutable Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators @@ -26,32 +27,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides ReadOnly Property ParameterCount As Integer - Get - Return 1 - End Get - End Property + Public Overrides ReadOnly Property ParameterCount As Integer = 1 - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Returns_a_System_Type_object_for_the_specified_type_name - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Returns_a_System_Type_object_for_the_specified_type_name - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return { - New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "GetType"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(") - } - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "GetType"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) - Public Overrides ReadOnly Property IncludeAsType As Boolean - Get - Return True - End Get - End Property + Public Overrides ReadOnly Property IncludeAsType As Boolean = True Public Overrides Function TryGetTypeNameParameter(syntaxNode As SyntaxNode, index As Integer) As TypeSyntax Dim getTypeExpression = TryCast(syntaxNode, GetTypeExpressionSyntax) @@ -63,10 +48,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End If End Function - Public Overrides ReadOnly Property ReturnTypeMetadataName As String - Get - Return "System.Type" - End Get - End Property + Public Overrides ReadOnly Property ReturnTypeMetadataName As String = "System.Type" End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/GetXmlNamespaceExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/GetXmlNamespaceExpressionDocumentation.vb index bca09bb0edfd8..f4637306c4b54 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/GetXmlNamespaceExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/GetXmlNamespaceExpressionDocumentation.vb @@ -2,18 +2,19 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class GetXmlNamespaceExpressionDocumentation Inherits AbstractIntrinsicOperatorDocumentation - Public Overrides Function GetParameterDisplayParts(index As Integer) As IList(Of SymbolDisplayPart) + Public Overrides Function GetParameterDisplayParts(index As Integer) As ImmutableArray(Of SymbolDisplayPart) Select Case index Case 0 - Return { + Return ImmutableArray.Create( New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "["), New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, GetParameterName(index)), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "]") - } + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "]")) Case Else Throw New ArgumentException(NameOf(index)) End Select @@ -37,37 +38,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides ReadOnly Property ParameterCount As Integer - Get - Return 1 - End Get - End Property + Public Overrides ReadOnly Property ParameterCount As Integer = 1 - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Returns_the_System_Xml_Linq_XNamespace_object_corresponding_to_the_specified_XML_namespace_prefix - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Returns_the_System_Xml_Linq_XNamespace_object_corresponding_to_the_specified_XML_namespace_prefix - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return { - New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "GetXmlNamespace"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(") - } - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "GetXmlNamespace"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) - Public Overrides ReadOnly Property IncludeAsType As Boolean - Get - Return True - End Get - End Property + Public Overrides ReadOnly Property IncludeAsType As Boolean = True - Public Overrides ReadOnly Property ReturnTypeMetadataName As String - Get - Return "System.Xml.Linq.XNamespace" - End Get - End Property + Public Overrides ReadOnly Property ReturnTypeMetadataName As String = "System.Xml.Linq.XNamespace" End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/MidAssignmentDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/MidAssignmentDocumentation.vb index d3323a51a2272..48d1960c0c21b 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/MidAssignmentDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/MidAssignmentDocumentation.vb @@ -2,17 +2,15 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable Imports System.Threading Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class MidAssignmentDocumentation Inherits AbstractIntrinsicOperatorDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Replaces_a_specified_number_of_characters_in_a_String_variable_with_characters_from_another_string - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Replaces_a_specified_number_of_characters_in_a_String_variable_with_characters_from_another_string Public Overrides Function GetParameterDocumentation(index As Integer) As String Select Case index @@ -40,41 +38,29 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides Function GetParameterDisplayParts(index As Integer) As IList(Of SymbolDisplayPart) + Public Overrides Function GetParameterDisplayParts(index As Integer) As ImmutableArray(Of SymbolDisplayPart) If index = 2 Then - Return {New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, "[" + GetParameterName(2) + "]")} + Return ImmutableArray.Create(New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, "[" + GetParameterName(2) + "]")) Else Return MyBase.GetParameterDisplayParts(index) End If End Function - Public Overrides ReadOnly Property IncludeAsType As Boolean - Get - Return False - End Get - End Property + Public Overrides ReadOnly Property IncludeAsType As Boolean = False - Public Overrides ReadOnly Property ParameterCount As Integer - Get - Return 3 - End Get - End Property + Public Overrides ReadOnly Property ParameterCount As Integer = 3 - Public Overrides Function GetSuffix(semanticModel As SemanticModel, position As Integer, nodeToBind As SyntaxNode, cancellationToken As CancellationToken) As IList(Of SymbolDisplayPart) - Return { + Public Overrides Function GetSuffix(semanticModel As SemanticModel, position As Integer, nodeToBind As SyntaxNode, cancellationToken As CancellationToken) As ImmutableArray(Of SymbolDisplayPart) + Return ImmutableArray.Create( New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, ")"), New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " "), New SymbolDisplayPart(SymbolDisplayPartKind.Operator, Nothing, "="), New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " "), - New SymbolDisplayPart(SymbolDisplayPartKind.Text, Nothing, VBWorkspaceResources.stringExpression) - } + New SymbolDisplayPart(SymbolDisplayPartKind.Text, Nothing, VBWorkspaceResources.stringExpression)) End Function - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return {New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "Mid"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")} - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "Mid"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/NameOfExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/NameOfExpressionDocumentation.vb index 30f466aa2aeb2..40c585805afc1 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/NameOfExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/NameOfExpressionDocumentation.vb @@ -2,34 +2,22 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class NameOfExpressionDocumentation Inherits AbstractIntrinsicOperatorDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Produces_a_string_for_the_name_of_the_specified_type_or_member - End Get - End Property - - Public Overrides ReadOnly Property IncludeAsType As Boolean - Get - Return True - End Get - End Property - - Public Overrides ReadOnly Property ParameterCount As Integer - Get - Return 1 - End Get - End Property - - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return {New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "NameOf"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")} - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Produces_a_string_for_the_name_of_the_specified_type_or_member + + Public Overrides ReadOnly Property IncludeAsType As Boolean = True + + Public Overrides ReadOnly Property ParameterCount As Integer = 1 + + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "NameOf"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) Public Overrides Function GetParameterDocumentation(index As Integer) As String Select Case index @@ -49,11 +37,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides ReadOnly Property ReturnTypeMetadataName As String - Get - Return "System.String" - End Get - End Property - + Public Overrides ReadOnly Property ReturnTypeMetadataName As String = "System.String" End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/PredefinedCastExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/PredefinedCastExpressionDocumentation.vb index c558b64b8b5a3..52189120ce26e 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/PredefinedCastExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/PredefinedCastExpressionDocumentation.vb @@ -2,6 +2,8 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class PredefinedCastExpressionDocumentation Inherits AbstractIntrinsicOperatorDocumentation @@ -38,22 +40,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides ReadOnly Property IncludeAsType As Boolean - Get - Return True - End Get - End Property + Public Overrides ReadOnly Property IncludeAsType As Boolean = True - Public Overrides ReadOnly Property ParameterCount As Integer - Get - Return 1 - End Get - End Property + Public Overrides ReadOnly Property ParameterCount As Integer = 1 - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) Get - Return {New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, _keywordText), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")} + Return ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, _keywordText), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) End Get End Property diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/RemoveHandlerStatementDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/RemoveHandlerStatementDocumentation.vb index 17f497af4b0c0..57938fc18d09d 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/RemoveHandlerStatementDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/RemoveHandlerStatementDocumentation.vb @@ -2,15 +2,14 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class RemoveHandlerStatementDocumentation Inherits AbstractAddRemoveHandlerStatementDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Removes_the_association_between_an_event_and_an_event_handler_or_delegate_at_run_time - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Removes_the_association_between_an_event_and_an_event_handler_or_delegate_at_run_time Public Overrides Function GetParameterDocumentation(index As Integer) As String Select Case index @@ -23,11 +22,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return {New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "RemoveHandler"), - New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " ")} - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "RemoveHandler"), + New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " ")) End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/TernaryConditionalExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/TernaryConditionalExpressionDocumentation.vb index bdcee3f9a58b6..307e7c1dd5e67 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/TernaryConditionalExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/TernaryConditionalExpressionDocumentation.vb @@ -2,25 +2,25 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class TernaryConditionalExpressionDocumentation Inherits AbstractIntrinsicOperatorDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.If_condition_returns_True_the_function_calculates_and_returns_expressionIfTrue_Otherwise_it_returns_expressionIfFalse - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.If_condition_returns_True_the_function_calculates_and_returns_expressionIfTrue_Otherwise_it_returns_expressionIfFalse - Public Overrides Function GetParameterDisplayParts(index As Integer) As IList(Of SymbolDisplayPart) + Public Overrides Function GetParameterDisplayParts(index As Integer) As ImmutableArray(Of SymbolDisplayPart) If index = 0 Then - Return {New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, GetParameterName(index)), - New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " "), - New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "As"), - New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " "), - New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "Boolean")} + Return ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, GetParameterName(index)), + New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " "), + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "As"), + New SymbolDisplayPart(SymbolDisplayPartKind.Space, Nothing, " "), + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "Boolean")) Else - Return {New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, GetParameterName(index))} + Return ImmutableArray.Create(New SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, Nothing, GetParameterName(index))) End If End Function @@ -50,23 +50,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators End Select End Function - Public Overrides ReadOnly Property IncludeAsType As Boolean - Get - Return True - End Get - End Property + Public Overrides ReadOnly Property IncludeAsType As Boolean = True - Public Overrides ReadOnly Property ParameterCount As Integer - Get - Return 3 - End Get - End Property + Public Overrides ReadOnly Property ParameterCount As Integer = 3 - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return {New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "If"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")} - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "If"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) End Class End Namespace diff --git a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/TryCastExpressionDocumentation.vb b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/TryCastExpressionDocumentation.vb index 1465a18832bcd..154a906004fc4 100644 --- a/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/TryCastExpressionDocumentation.vb +++ b/src/Workspaces/VisualBasic/Portable/Utilities/IntrinsicOperators/TryCastExpressionDocumentation.vb @@ -2,23 +2,17 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports System.Collections.Immutable + Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities.IntrinsicOperators Friend NotInheritable Class TryCastExpressionDocumentation Inherits AbstractCastExpressionDocumentation - Public Overrides ReadOnly Property DocumentationText As String - Get - Return VBWorkspaceResources.Introduces_a_type_conversion_operation_that_does_not_throw_an_exception_If_an_attempted_conversion_fails_TryCast_returns_Nothing_which_your_program_can_test_for - End Get - End Property + Public Overrides ReadOnly Property DocumentationText As String = + VBWorkspaceResources.Introduces_a_type_conversion_operation_that_does_not_throw_an_exception_If_an_attempted_conversion_fails_TryCast_returns_Nothing_which_your_program_can_test_for - Public Overrides ReadOnly Property PrefixParts As IList(Of SymbolDisplayPart) - Get - Return { - New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "TryCast"), - New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(") - } - End Get - End Property + Public Overrides ReadOnly Property PrefixParts As ImmutableArray(Of SymbolDisplayPart) = ImmutableArray.Create( + New SymbolDisplayPart(SymbolDisplayPartKind.Keyword, Nothing, "TryCast"), + New SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, Nothing, "(")) End Class End Namespace