diff --git a/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs b/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs index 00789c42db1c8376a767556b577ec441a7d9b275..cceb22c9b2b0aad4b8a1027a999ff0b65be20cbf 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 17293d7fd1fb185f47d3b5f844c28ca6b86c1b7b..84e3d2cc227b975a25faafb338b6d98812c46ebe 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 b5b152670c3e6f2526e7013414485652be8b8b50..ba7451941908809d7b5ce5456ac0bb427f701896 100644 --- a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeParameterTests.vb +++ b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeParameterTests.vb @@ -101,6 +101,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" @@ -118,6 +167,36 @@ class C TestFullName(code, "s") End Sub + + 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 "Kind tests" 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 57b93eaea261cf5785923b559610b608fa11ee51..7bafee467d41ea42b0167911b4da48ec4877293f 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 51eca738f34eba03154f73f8067a32f87f147ac8..b3893c97beb2e386bf3d4915936cebf2f0f7651c 100644 --- a/src/VisualStudio/Core/Test/ServicesVisualStudioTest.vbproj +++ b/src/VisualStudio/Core/Test/ServicesVisualStudioTest.vbproj @@ -285,6 +285,8 @@ + + @@ -319,6 +321,8 @@ + + diff --git a/src/VisualStudio/VisualBasic/Impl/CodeModel/VisualBasicCodeModelService.vb b/src/VisualStudio/VisualBasic/Impl/CodeModel/VisualBasicCodeModelService.vb index 38ca9f5952066e0f01252a668724d4e8cbb56608..165116aaf796825614aa64777e2b10e043b3515d 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(