diff --git a/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs b/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs index b2d1b0ee10c1314db471c97bed2c5400bd53dda4..7b2cb470f6ef943d9ef21f6ebea3f3448352d41a 100644 --- a/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs +++ b/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs @@ -58,14 +58,16 @@ internal partial class CSharpCodeModelService : AbstractCodeModelService private static readonly SymbolDisplayFormat s_externalNameFormat = new SymbolDisplayFormat( - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers); + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers, + parameterOptions: SymbolDisplayParameterOptions.IncludeName); private static readonly SymbolDisplayFormat s_externalFullNameFormat = new SymbolDisplayFormat( typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, memberOptions: SymbolDisplayMemberOptions.IncludeContainingType | SymbolDisplayMemberOptions.IncludeExplicitInterface, genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers); + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers, + parameterOptions: SymbolDisplayParameterOptions.IncludeName); private static readonly SymbolDisplayFormat s_setTypeFormat = new SymbolDisplayFormat( diff --git a/src/VisualStudio/Core/Impl/CodeModel/ExternalElements/ExternalCodeParameter.cs b/src/VisualStudio/Core/Impl/CodeModel/ExternalElements/ExternalCodeParameter.cs index 09b1ce5ca9fa0865c6273dacd2dddbc3ba1f04df..65a929554379948746895b991732ac2910387ec2 100644 --- a/src/VisualStudio/Core/Impl/CodeModel/ExternalElements/ExternalCodeParameter.cs +++ b/src/VisualStudio/Core/Impl/CodeModel/ExternalElements/ExternalCodeParameter.cs @@ -2,7 +2,6 @@ using System.Runtime.InteropServices; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServices.Implementation.Interop; using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities; diff --git a/src/VisualStudio/Core/Test/CodeModel/AbstractCodeParameterTests.vb b/src/VisualStudio/Core/Test/CodeModel/AbstractCodeParameterTests.vb index 181ae85288e34c4045d04be083b2c6b6fccbbe1c..356b428af6f1a65039bfd438cc44913ec72e2838 100644 --- a/src/VisualStudio/Core/Test/CodeModel/AbstractCodeParameterTests.vb +++ b/src/VisualStudio/Core/Test/CodeModel/AbstractCodeParameterTests.vb @@ -2,7 +2,6 @@ Imports EnvDTE Imports EnvDTE80 -Imports Microsoft.CodeAnalysis.Editor.UnitTests.Extensions Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel Public MustInherit Class AbstractCodeParameterTests diff --git a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeParameterTests.vb b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeParameterTests.vb index 8a1cccdd0c8cbc4cff4ce477e41f04b2045dff3a..2e05f341645f4a0116ec0e1f1fd4d60cfe37e701 100644 --- a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeParameterTests.vb +++ b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeParameterTests.vb @@ -102,6 +102,55 @@ class C : System.Console #End Region +#Region "Name tests" + + + Public Async Function TestName1() As Task + Dim code = + +class C +{ + void Foo(string $$s) + { + } +} + + + Await TestName(code, "s") + End Function + + + Public Async Function TestName2() As Task + Dim code = + +class C +{ + void Foo(ref string $$s) + { + } +} + + + Await TestName(code, "s") + End Function + + + Public Async Function TestName3() As Task + Dim code = + +class C +{ + void Foo(out string $$s) + { + } +} + + + Await TestName(code, "s") + End Function + +#End Region + #Region "FullName tests" @@ -114,6 +163,36 @@ class C { } } + + + Await TestFullName(code, "s") + End Function + + + Public Async Function TestFullName2() As Task + Dim code = + +class C +{ + void Foo(ref string $$s) + { + } +} + + + Await TestFullName(code, "s") + End Function + + + Public Async Function TestFullName3() As Task + Dim code = + +class C +{ + void Foo(out string $$s) + { + } +} Await TestFullName(code, "s") diff --git a/src/VisualStudio/Core/Test/CodeModel/CSharp/ExternalCodeFunctionTests.vb b/src/VisualStudio/Core/Test/CodeModel/CSharp/ExternalCodeFunctionTests.vb new file mode 100644 index 0000000000000000000000000000000000000000..bf08a7a47eb28654dd6028f4ba9f39e7d822ea7c --- /dev/null +++ b/src/VisualStudio/Core/Test/CodeModel/CSharp/ExternalCodeFunctionTests.vb @@ -0,0 +1,51 @@ +Imports System.Threading.Tasks +Imports Microsoft.CodeAnalysis +Imports Roslyn.Test.Utilities + +Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel.CSharp + Public Class ExternalCodeFunctionTests + Inherits AbstractCodeFunctionTests + +#Region "FullName tests" + + + Public Async Function TestFullName1() As Task + Dim code = + +class C +{ + void $$Foo(string s) + { + } +} + + + Await TestFullName(code, "C.Foo") + End Function + +#End Region + +#Region "Name tests" + + + Public Async Function TestName1() As Task + Dim code = + +class C +{ + void $$Foo(string s) + { + } +} + + + Await TestName(code, "Foo") + End Function + +#End Region + + Protected Overrides ReadOnly Property LanguageName As String = LanguageNames.CSharp + Protected Overrides ReadOnly Property TargetExternalCodeElements As Boolean = True + + End Class +End Namespace \ No newline at end of file diff --git a/src/VisualStudio/Core/Test/CodeModel/CSharp/ExternalCodeParameterTests.vb b/src/VisualStudio/Core/Test/CodeModel/CSharp/ExternalCodeParameterTests.vb new file mode 100644 index 0000000000000000000000000000000000000000..cb3e0cd161504a2513ff682fc825f336e2e57509 --- /dev/null +++ b/src/VisualStudio/Core/Test/CodeModel/CSharp/ExternalCodeParameterTests.vb @@ -0,0 +1,113 @@ +' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +Imports System.Threading.Tasks +Imports Microsoft.CodeAnalysis +Imports Roslyn.Test.Utilities + +Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel.CSharp + Public Class ExternalCodeParameterTests + Inherits AbstractCodeParameterTests + +#Region "FullName tests" + + + Public Async Function TestFullName1() As Task + Dim code = + +class C +{ + void Foo(string $$s) + { + } +} + + + Await TestFullName(code, "s") + End Function + + + Public Async Function TestFullName2() As Task + Dim code = + +class C +{ + void Foo(ref string $$s) + { + } +} + + + Await TestFullName(code, "s") + End Function + + + Public Async Function TestFullName3() As Task + Dim code = + +class C +{ + void Foo(out string $$s) + { + } +} + + + Await TestFullName(code, "s") + End Function + +#End Region + +#Region "Name tests" + + + Public Async Function TestName1() As Task + Dim code = + +class C +{ + void Foo(string $$s) + { + } +} + + + Await TestName(code, "s") + End Function + + + Public Async Function TestName2() As Task + Dim code = + +class C +{ + void Foo(ref string $$s) + { + } +} + + + Await TestName(code, "s") + End Function + + + Public Async Function TestName3() As Task + Dim code = + +class C +{ + void Foo(out string $$s) + { + } +} + + + Await TestName(code, "s") + End Function + +#End Region + + Protected Overrides ReadOnly Property LanguageName As String = LanguageNames.CSharp + Protected Overrides ReadOnly Property TargetExternalCodeElements As Boolean = True + + End Class +End Namespace \ No newline at end of file diff --git a/src/VisualStudio/Core/Test/CodeModel/CodeModelTestHelpers.vb b/src/VisualStudio/Core/Test/CodeModel/CodeModelTestHelpers.vb index 11f5a0df164fe3582f3f723ff1511162dea4d25c..715185024fec54a436b0726f9e68b2c4652ea271 100644 --- a/src/VisualStudio/Core/Test/CodeModel/CodeModelTestHelpers.vb +++ b/src/VisualStudio/Core/Test/CodeModel/CodeModelTestHelpers.vb @@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.VisualStudio.ComponentModelHost Imports Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel +Imports Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.ExternalElements Imports Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.InternalElements Imports Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.Interop Imports Microsoft.VisualStudio.LanguageServices.Implementation.Interop @@ -173,6 +174,14 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel Assert.True(codeElement IsNot Nothing, "Expected code element") Assert.True(codeElement.InfoLocation = EnvDTE.vsCMInfoLocation.vsCMInfoLocationProject, "Expected internal code element") + If TypeOf codeElement Is EnvDTE.CodeParameter Then + Dim codeParameter = DirectCast(codeElement, EnvDTE.CodeParameter) + Dim externalParentCodeElement = codeParameter.Parent.AsExternal() + Dim externalParentCodeElementImpl = ComAggregate.GetManagedObject(Of AbstractExternalCodeMember)(externalParentCodeElement) + + Return DirectCast(externalParentCodeElementImpl.Parameters.Item(codeParameter.Name), T) + End If + Dim codeElementImpl = ComAggregate.GetManagedObject(Of AbstractCodeElement)(codeElement) Dim state = codeElementImpl.State Dim projectId = codeElementImpl.FileCodeModel.GetProjectId() diff --git a/src/VisualStudio/Core/Test/CodeModel/VisualBasic/ExternalCodeFunctionTests.vb b/src/VisualStudio/Core/Test/CodeModel/VisualBasic/ExternalCodeFunctionTests.vb new file mode 100644 index 0000000000000000000000000000000000000000..b70fffa32667a8f88ab21d641598fed7df4f7c12 --- /dev/null +++ b/src/VisualStudio/Core/Test/CodeModel/VisualBasic/ExternalCodeFunctionTests.vb @@ -0,0 +1,47 @@ +Imports System.Threading.Tasks +Imports Microsoft.CodeAnalysis +Imports Roslyn.Test.Utilities + +Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel.CSharp.VisualBasic + Public Class ExternalCodeFunctionTests + Inherits AbstractCodeFunctionTests + +#Region "FullName tests" + + + Public Async Function TestFullName1() As Task + Dim code = + +Class C + Sub $$Foo(string s) + End Sub +End Class + + + Await TestFullName(code, "C.Foo") + End Function + +#End Region + +#Region "Name tests" + + + Public Async Function TestName1() As Task + Dim code = + +Class C + Sub $$Foo(string s) + End Sub +End Class + + + Await TestName(code, "Foo") + End Function + +#End Region + + Protected Overrides ReadOnly Property LanguageName As String = LanguageNames.VisualBasic + Protected Overrides ReadOnly Property TargetExternalCodeElements As Boolean = True + + End Class +End Namespace \ No newline at end of file diff --git a/src/VisualStudio/Core/Test/CodeModel/VisualBasic/ExternalCodeParameterTests.vb b/src/VisualStudio/Core/Test/CodeModel/VisualBasic/ExternalCodeParameterTests.vb new file mode 100644 index 0000000000000000000000000000000000000000..7956bd8bb8d8dc609ba8bcdd08c7e61a02c04418 --- /dev/null +++ b/src/VisualStudio/Core/Test/CodeModel/VisualBasic/ExternalCodeParameterTests.vb @@ -0,0 +1,125 @@ +' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +Imports System.Threading.Tasks +Imports Microsoft.CodeAnalysis +Imports Roslyn.Test.Utilities + +Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel.VisualBasic + Public Class ExternalCodeParameterTests + Inherits AbstractCodeParameterTests + +#Region "FullName tests" + + + Public Async Function TestFullName1() As Task + Dim code = + +Class C + Sub Foo($$s As String) + End Sub +End Class + + + Await TestFullName(code, "s") + End Function +#End Region + +#Region "Name tests" + + + Public Async Function TestName_NoModifiers() As Task + Dim code = + +Public Class C1 + + Public Sub S1($$p1 As Integer) + End Sub + +End Class + + + Await TestName(code, "p1") + End Function + + + Public Async Function TestName_ByValModifier() As Task + Dim code = + +Public Class C1 + + Public Sub S2(ByVal $$p2 As Integer) + End Sub + +End Class + + + Await TestName(code, "p2") + End Function + + + Public Async Function TestName_ByRefModifier() As Task + Dim code = + +Public Class C1 + + Public Sub S3(ByRef $$p3 As Integer) + End Sub + +End Class + + + Await TestName(code, "p3") + End Function + + + Public Async Function TestName_OptionalByValModifiers() As Task + Dim code = + +Public Class C1 + + Public Sub S4(Optional ByVal $$p4 As Integer = 0) + End Sub + +End Class + + + Await TestName(code, "p4") + End Function + + + Public Async Function TestName_ByValParamArrayModifiers() As Task + Dim code = + +Public Class C1 + + Public Sub S5(ByVal ParamArray $$p5() As Integer) + End Sub + +End Class + + + Await TestName(code, "p5") + End Function + + + Public Async Function TestName_TypeCharacter() As Task + Dim code = + +Public Class C1 + + Public Sub S6($$p6%) + End Sub + +End Class + + + Await TestName(code, "p6") + End Function + +#End Region + + Protected Overrides ReadOnly Property LanguageName As String = LanguageNames.VisualBasic + Protected Overrides ReadOnly Property TargetExternalCodeElements As Boolean = True + + End Class +End Namespace \ No newline at end of file diff --git a/src/VisualStudio/Core/Test/ServicesVisualStudioTest.vbproj b/src/VisualStudio/Core/Test/ServicesVisualStudioTest.vbproj index 7c46de5ea0b9d3b599cbd3e28d6c8a1fe345dc10..615367d1dce13c444e1f41cda662c1884152083d 100644 --- a/src/VisualStudio/Core/Test/ServicesVisualStudioTest.vbproj +++ b/src/VisualStudio/Core/Test/ServicesVisualStudioTest.vbproj @@ -289,6 +289,8 @@ + + @@ -323,6 +325,8 @@ + + diff --git a/src/VisualStudio/VisualBasic/Impl/CodeModel/VisualBasicCodeModelService.vb b/src/VisualStudio/VisualBasic/Impl/CodeModel/VisualBasicCodeModelService.vb index 1525f856790ce2bd00738a1b76a354bea5e77249..b911297ab504196294b5a1f19bd9c9fe51bd7171 100644 --- a/src/VisualStudio/VisualBasic/Impl/CodeModel/VisualBasicCodeModelService.vb +++ b/src/VisualStudio/VisualBasic/Impl/CodeModel/VisualBasicCodeModelService.vb @@ -56,14 +56,16 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel Private Shared ReadOnly s_externalNameFormat As SymbolDisplayFormat = New SymbolDisplayFormat( genericsOptions:=SymbolDisplayGenericsOptions.IncludeTypeParameters, - miscellaneousOptions:=SymbolDisplayMiscellaneousOptions.ExpandNullable) + miscellaneousOptions:=SymbolDisplayMiscellaneousOptions.ExpandNullable, + parameterOptions:=SymbolDisplayParameterOptions.IncludeName) Private Shared ReadOnly s_externalfullNameFormat As SymbolDisplayFormat = New SymbolDisplayFormat( typeQualificationStyle:=SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, genericsOptions:=SymbolDisplayGenericsOptions.IncludeTypeParameters, memberOptions:=SymbolDisplayMemberOptions.IncludeContainingType, - miscellaneousOptions:=SymbolDisplayMiscellaneousOptions.ExpandNullable) + miscellaneousOptions:=SymbolDisplayMiscellaneousOptions.ExpandNullable, + parameterOptions:=SymbolDisplayParameterOptions.IncludeName) Private Shared ReadOnly s_setTypeFormat As SymbolDisplayFormat = New SymbolDisplayFormat(