diff --git a/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyDetail.cs b/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyDetail.cs index 52af53f48a6caa8a4f0bccf41b0fd64bff1fcd9f..0bc5b01f70b4812fe0b463322aa311e65e23fcb2 100644 --- a/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyDetail.cs +++ b/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyDetail.cs @@ -102,7 +102,7 @@ public void NavigateTo() if (document != null) { var navigator = _workspace.Services.GetService(); - var options = _workspace.Options.WithChangedOption(NavigationOptions.UsePreviewTab, true); + var options = _workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true); navigator.TryNavigateToSpan(_workspace, document.Id, _span, options); } } diff --git a/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyProvider.cs b/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyProvider.cs index 727b69b2b25fbea0585acd3320109e6f43426758..221db14cc93138cf5396867b1480a663da9aac4b 100644 --- a/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyProvider.cs +++ b/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyProvider.cs @@ -133,7 +133,7 @@ public void NavigateTo(SymbolKey id, Project project, CancellationToken cancella var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken); var resolution = id.Resolve(compilation, cancellationToken: cancellationToken); var workspace = project.Solution.Workspace; - var options = workspace.Options.WithChangedOption(NavigationOptions.UsePreviewTab, true); + var options = workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true); var symbolNavigationService = workspace.Services.GetService(); symbolNavigationService.TryNavigateToSymbol(resolution.Symbol, project, options, cancellationToken); diff --git a/src/EditorFeatures/Core/Implementation/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/Implementation/GoToDefinition/GoToDefinitionHelpers.cs index 55a6884b524ec092982375f157ac6381178fb524..d18156e1aad4ef76dae41b958bb34fbe971736fb 100644 --- a/src/EditorFeatures/Core/Implementation/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/Implementation/GoToDefinition/GoToDefinitionHelpers.cs @@ -73,7 +73,7 @@ internal static class GoToDefinitionHelpers var symbolNavigationService = solution.Workspace.Services.GetService(); return symbolNavigationService.TryNavigateToSymbol( symbol, project, - options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true), + options: options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true), cancellationToken: cancellationToken); } @@ -90,7 +90,7 @@ internal static class GoToDefinitionHelpers workspace, documentId: solution.GetDocument(firstItem.SourceTree).Id, textSpan: firstItem.SourceSpan, - options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true)); + options: options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true)); } else { diff --git a/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs b/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs index b96569e90e2e7ed5a4cef1d4d4fc185aaf208ed8..b58b60d3affdbc77d4a58f3328d3c7d31146523c 100644 --- a/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs +++ b/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs @@ -61,8 +61,5 @@ internal static class FeatureOnOffOptions /// [ExportOption] public static readonly PerLanguageOption RefactoringVerification = new PerLanguageOption(OptionName, "Refactoring Verification", defaultValue: false); - - [ExportOption] - public static readonly PerLanguageOption GoToDefinitionUsesObjectBrowser = new PerLanguageOption(OptionName, "Go To Definition Uses Object Browser", defaultValue: false); } } diff --git a/src/Features/Core/Portable/Navigation/NavigationOptions.cs b/src/Features/Core/Portable/Navigation/NavigationOptions.cs index 0177e0b234da4fdd6994c56a3202b715f8f812d3..5b4962ab8b97faeddfee058d59ad3b8ebf036f5e 100644 --- a/src/Features/Core/Portable/Navigation/NavigationOptions.cs +++ b/src/Features/Core/Portable/Navigation/NavigationOptions.cs @@ -8,6 +8,10 @@ internal static class NavigationOptions { public const string FeatureName = "Navigation"; - public static readonly Option UsePreviewTab = new Option(FeatureName, "UsePreviewTab", defaultValue: false); + /// + /// This option can be passed to the APIs to request that a provisional (or preview) tab + /// be used for any document that needs to be opened, if one is available. + /// + public static readonly Option PreferProvisionalTab = new Option(FeatureName, "PreferProvisionalTab", defaultValue: false); } } diff --git a/src/Features/Core/Portable/Navigation/NavigationOptionsProvider.cs b/src/Features/Core/Portable/Navigation/NavigationOptionsProvider.cs index 4b11e1711a903954af72f53ecf526f3f0cf42bd1..f9dd48aad4266d3c657dc8240682e255c9e32ce0 100644 --- a/src/Features/Core/Portable/Navigation/NavigationOptionsProvider.cs +++ b/src/Features/Core/Portable/Navigation/NavigationOptionsProvider.cs @@ -11,14 +11,8 @@ namespace Microsoft.CodeAnalysis.Navigation [ExportOptionProvider, Shared] internal class NavigationOptionsProvider : IOptionProvider { - private readonly IEnumerable _options = new List - { - NavigationOptions.UsePreviewTab - }.ToImmutableArray(); + private readonly IEnumerable _options = ImmutableArray.Create(NavigationOptions.PreferProvisionalTab); - public IEnumerable GetOptions() - { - return _options; - } + public IEnumerable GetOptions() => _options; } } diff --git a/src/VisualStudio/CSharp/Impl/CSharpVisualStudio.csproj b/src/VisualStudio/CSharp/Impl/CSharpVisualStudio.csproj index 82f22e10523cf00b2066de24573dfdf9279b770d..eb3c04c5aaa68bae051bb7799341806ce654f526 100644 --- a/src/VisualStudio/CSharp/Impl/CSharpVisualStudio.csproj +++ b/src/VisualStudio/CSharp/Impl/CSharpVisualStudio.csproj @@ -198,7 +198,6 @@ - diff --git a/src/VisualStudio/CSharp/Impl/ObjectBrowser/CSharpLibraryService.cs b/src/VisualStudio/CSharp/Impl/ObjectBrowser/CSharpLibraryService.cs index cbb7f486341888945beaafd508471ebb78ff5e23..5521f474514be436f45cb1358c45dcdc5d118f01 100644 --- a/src/VisualStudio/CSharp/Impl/ObjectBrowser/CSharpLibraryService.cs +++ b/src/VisualStudio/CSharp/Impl/ObjectBrowser/CSharpLibraryService.cs @@ -1,11 +1,14 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Composition; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.VisualStudio.LanguageServices.Implementation.Library; using Microsoft.VisualStudio.Shell.Interop; namespace Microsoft.VisualStudio.LanguageServices.CSharp.ObjectBrowser { + [ExportLanguageService(typeof(ILibraryService), LanguageNames.CSharp), Shared] internal class CSharpLibraryService : AbstractLibraryService { private static readonly SymbolDisplayFormat s_typeDisplayFormat = new SymbolDisplayFormat( diff --git a/src/VisualStudio/CSharp/Impl/ObjectBrowser/CSharpLibraryServiceFactory.cs b/src/VisualStudio/CSharp/Impl/ObjectBrowser/CSharpLibraryServiceFactory.cs deleted file mode 100644 index 8893ae3593f3722288957459c3eb2e61ee72b117..0000000000000000000000000000000000000000 --- a/src/VisualStudio/CSharp/Impl/ObjectBrowser/CSharpLibraryServiceFactory.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Composition; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.VisualStudio.LanguageServices.Implementation.Library; - -namespace Microsoft.VisualStudio.LanguageServices.CSharp.ObjectBrowser -{ - [ExportLanguageServiceFactory(typeof(ILibraryService), LanguageNames.CSharp), Shared] - internal class CSharpLibraryServiceFactory : ILanguageServiceFactory - { - public ILanguageService CreateLanguageService(HostLanguageServices languageServices) - { - return new CSharpLibraryService(); - } - } -} diff --git a/src/VisualStudio/Core/Def/Implementation/Library/AbstractLibraryService.cs b/src/VisualStudio/Core/Def/Implementation/Library/AbstractLibraryService.cs index 6c46e823591e512918aba9deacaa719f2becfdfa..f748c6654daf4d7a58173bae72beb19633c0ba90 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/AbstractLibraryService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/AbstractLibraryService.cs @@ -15,7 +15,7 @@ internal abstract class AbstractLibraryService : ILibraryService public SymbolDisplayFormat TypeDisplayFormat { get; } public SymbolDisplayFormat MemberDisplayFormat { get; } - public NavInfoFactory NavInfo { get; } + public NavInfoFactory NavInfoFactory { get; } protected AbstractLibraryService( Guid libraryId, @@ -28,7 +28,7 @@ internal abstract class AbstractLibraryService : ILibraryService this.TypeDisplayFormat = typeDisplayFormat; this.MemberDisplayFormat = memberDisplayFormat; - this.NavInfo = new NavInfoFactory(this); + this.NavInfoFactory = new NavInfoFactory(this); } } } diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ILibraryService.cs b/src/VisualStudio/Core/Def/Implementation/Library/ILibraryService.cs index ddc474a2aeb17ec70202df8ae8ec0c0d9ded4c93..d0d0b019a16a583f1bcd14a39eb8101dc8434a0b 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ILibraryService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ILibraryService.cs @@ -1,6 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Host; using Microsoft.VisualStudio.LanguageServices.Implementation.Library.VsNavInfo; @@ -8,6 +7,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Library { internal interface ILibraryService : ILanguageService { - NavInfoFactory NavInfo { get; } + NavInfoFactory NavInfoFactory { get; } } } diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractDescriptionBuilder.cs b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractDescriptionBuilder.cs index 7bf3acfdc4d9153a5ab47ededbbaf1822563ede3..cd3662e2e078b966e7b333ed8bb620e3ab8c1ad0 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractDescriptionBuilder.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractDescriptionBuilder.cs @@ -44,7 +44,7 @@ private Compilation GetCompilation() protected void AddAssemblyLink(IAssemblySymbol assemblySymbol) { var name = assemblySymbol.Identity.Name; - var navInfo = _libraryManager.LibraryService.NavInfo.CreateForAssembly(assemblySymbol); + var navInfo = _libraryManager.LibraryService.NavInfoFactory.CreateForAssembly(assemblySymbol); _description.AddDescriptionText3(name, VSOBDESCRIPTIONSECTION.OBDS_TYPE, navInfo); } @@ -82,7 +82,7 @@ protected void AddNamespaceLink(INamespaceSymbol namespaceSymbol) } var text = namespaceSymbol.ToDisplayString(); - var navInfo = _libraryManager.LibraryService.NavInfo.CreateForNamespace(namespaceSymbol, _project, GetCompilation(), useExpandedHierarchy: false); + var navInfo = _libraryManager.LibraryService.NavInfoFactory.CreateForNamespace(namespaceSymbol, _project, GetCompilation(), useExpandedHierarchy: false); _description.AddDescriptionText3(text, VSOBDESCRIPTIONSECTION.OBDS_TYPE, navInfo); } @@ -131,7 +131,7 @@ protected void AddTypeLink(ITypeSymbol typeSymbol, LinkFlags flags) miscellaneousOptions: miscellaneousOptions); var text = typeSymbol.ToDisplayString(typeDisplayFormat); - var navInfo = _libraryManager.LibraryService.NavInfo.CreateForType(typeSymbol, _project, GetCompilation(), useExpandedHierarchy: false); + var navInfo = _libraryManager.LibraryService.NavInfoFactory.CreateForType(typeSymbol, _project, GetCompilation(), useExpandedHierarchy: false); _description.AddDescriptionText3(text, VSOBDESCRIPTIONSECTION.OBDS_TYPE, navInfo); } diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs index c82b3a430136050f183f5d925784fe8479541869..cd6febc18509b42c0d36e87cef368b89dd1a7bef 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs @@ -399,7 +399,7 @@ protected override int CreateNavInfo(SYMBOL_DESCRIPTION_NODE[] rgSymbolNodes, ui SharedPools.Default().ClearAndFree(className); // TODO: Make sure we pass the right value for Visual Basic. - ppNavInfo = this.LibraryService.NavInfo.Create(libraryName, referenceOwnerName, namespaceName.ToString(), className.ToString(), memberName); + ppNavInfo = this.LibraryService.NavInfoFactory.Create(libraryName, referenceOwnerName, namespaceName.ToString(), className.ToString(), memberName); return VSConstants.S_OK; } @@ -426,18 +426,18 @@ internal IVsNavInfo GetNavInfo(SymbolListItem symbolListItem, bool useExpandedHi if (symbolListItem is MemberListItem) { - return this.LibraryService.NavInfo.CreateForMember(symbol, project, compilation, useExpandedHierarchy); + return this.LibraryService.NavInfoFactory.CreateForMember(symbol, project, compilation, useExpandedHierarchy); } else if (symbolListItem is TypeListItem) { - return this.LibraryService.NavInfo.CreateForType((INamedTypeSymbol)symbol, project, compilation, useExpandedHierarchy); + return this.LibraryService.NavInfoFactory.CreateForType((INamedTypeSymbol)symbol, project, compilation, useExpandedHierarchy); } else if (symbolListItem is NamespaceListItem) { - return this.LibraryService.NavInfo.CreateForNamespace((INamespaceSymbol)symbol, project, compilation, useExpandedHierarchy); + return this.LibraryService.NavInfoFactory.CreateForNamespace((INamespaceSymbol)symbol, project, compilation, useExpandedHierarchy); } - return this.LibraryService.NavInfo.CreateForProject(project); + return this.LibraryService.NavInfoFactory.CreateForProject(project); } protected override bool TryQueryStatus(Guid commandGroup, uint commandId, ref OLECMDF commandFlags) diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/ObjectList.cs b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/ObjectList.cs index 23b9449ed2c1f723e97b5133928128bc0c7b94c8..00fce55b710126f6361797eeada560a80fc3f6f6 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/ObjectList.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/ObjectList.cs @@ -564,14 +564,14 @@ protected override IVsNavInfo GetNavInfo(uint index) var project = this.LibraryManager.GetProject(projectListItem.ProjectId); if (project != null) { - return this.LibraryManager.LibraryService.NavInfo.CreateForProject(project); + return this.LibraryManager.LibraryService.NavInfoFactory.CreateForProject(project); } } var referenceListItem = listItem as ReferenceListItem; if (referenceListItem != null) { - return this.LibraryManager.LibraryService.NavInfo.CreateForReference(referenceListItem.MetadataReference); + return this.LibraryManager.LibraryService.NavInfoFactory.CreateForReference(referenceListItem.MetadataReference); } var symbolListItem = listItem as SymbolListItem; diff --git a/src/VisualStudio/Core/Def/Implementation/Library/VsNavInfo/NavInfoFactory.cs b/src/VisualStudio/Core/Def/Implementation/Library/VsNavInfo/NavInfoFactory.cs index 1642924d62f1868a50e40dd263a5ddd6ed6f303d..c9daa0705388dffade6619f85cbd0874a6d4d2f4 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/VsNavInfo/NavInfoFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/VsNavInfo/NavInfoFactory.cs @@ -128,6 +128,8 @@ public IVsNavInfo CreateForType(ITypeSymbol typeSymbol, Project project, Compila public IVsNavInfo CreateForMember(ISymbol memberSymbol, Project project, Compilation compilation, bool useExpandedHierarchy = false) { + memberSymbol = memberSymbol.OriginalDefinition; + return Create( memberSymbol.ContainingAssembly, project, diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/AbstractTableEntriesSnapshot.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/AbstractTableEntriesSnapshot.cs index 51e3a688169aa9559ce5e4a156e04085b1f348fc..c9c0ada0b74c62841e7404eb3327bd01577fc3cc 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/AbstractTableEntriesSnapshot.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/AbstractTableEntriesSnapshot.cs @@ -188,7 +188,7 @@ protected bool TryNavigateTo(Workspace workspace, DocumentId documentId, int lin return false; } - var options = workspace.Options.WithChangedOption(NavigationOptions.UsePreviewTab, previewTab); + var options = workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, previewTab); if (navigationService.TryNavigateToLineAndOffset(workspace, documentId, line, column, options)) { return true; diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs index f157c78685bed41e83415f8e194a3f6121ad80a1..6b28d6623e07ce476383715b2f185653d31db0b6 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs @@ -185,7 +185,7 @@ private static Document OpenDocument(Workspace workspace, DocumentId documentId, // in a permanent tab, this allows the document to transition to the new state. if (workspace.CanOpenDocuments) { - if (options.GetOption(NavigationOptions.UsePreviewTab)) + if (options.GetOption(NavigationOptions.PreferProvisionalTab)) { using (NewDocumentStateScope ndss = new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.Navigation)) { diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index 8f2af6c1d6b5931a71c4b2f6168afeaaa982d609..c4b4fdf1704a88c7b0f77bfe1d5515e972018f1c 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -94,19 +94,19 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet optio } var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken); - var navInfo = libraryService.NavInfo.CreateForSymbol(symbol, project, compilation); + var navInfo = libraryService.NavInfoFactory.CreateForSymbol(symbol, project, compilation); if (navInfo == null) { - navInfo = libraryService.NavInfo.CreateForProject(project); + navInfo = libraryService.NavInfoFactory.CreateForProject(project); } - if (navInfo == null) + if (navInfo != null) { - return false; + var navigationTool = GetService(); + return navigationTool.NavigateToNavInfo(navInfo) == VSConstants.S_OK; } - var navigationTool = GetService(); - return navigationTool.NavigateToNavInfo(navInfo) == VSConstants.S_OK; + // Note: we'll fallback to Metadata-As-Source if we fail to get IVsNavInfo, but that should never happen. } // Generate new source or retrieve existing source for the symbol in question @@ -147,7 +147,7 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet optio workspace: editorWorkspace, documentId: openedDocument.Id, textSpan: result.IdentifierLocation.SourceSpan, - options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true)); + options: options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true)); } return true; diff --git a/src/VisualStudio/Core/Test/VsNavInfo/VsNavInfoTests.vb b/src/VisualStudio/Core/Test/VsNavInfo/VsNavInfoTests.vb index fe356ea0a885f2e05b66fc45e0f745e346bfc00c..9a47406558b156cf453e43b689cf63426f03bace 100644 --- a/src/VisualStudio/Core/Test/VsNavInfo/VsNavInfoTests.vb +++ b/src/VisualStudio/Core/Test/VsNavInfo/VsNavInfoTests.vb @@ -274,6 +274,128 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo }) End Sub + + Public Sub CSharp_TestMetadata_GenericType() + Dim workspace = + + + + using System.Collections.Generic; + class C + { + $$List<int> s; + } + + + + + Test(workspace, + canonicalNodes:={ + Package("Z:\FxReferenceAssembliesUri"), + [Namespace]("System"), + [Namespace]("Collections"), + [Namespace]("Generic"), + [Class]("List") + }, + presentationNodes:={ + Package("Z:\FxReferenceAssembliesUri"), + [Namespace]("System.Collections.Generic"), + [Class]("List") + }) + End Sub + + + Public Sub CSharp_TestMetadata_GenericMethod() + Dim workspace = + + + + using System; + class C + { + void M() + { + var a = new int[] { 1, 2, 3, 4, 5 }; + var r = Array.AsReadOnly$$(a); + } + } + + + + + Test(workspace, + canonicalNodes:={ + Package("Z:\FxReferenceAssembliesUri"), + [Namespace]("System"), + [Class]("Array"), + Member("AsReadOnly(T[])") + }, + presentationNodes:={ + Package("Z:\FxReferenceAssembliesUri"), + [Namespace]("System"), + [Class]("Array"), + Member("AsReadOnly(T[])") + }) + End Sub + + + Public Sub CSharp_TestNull_Parameter() + Dim workspace = + + + + class C + { + void M(int i$$) { } + } + + + + + TestIsNull(workspace) + End Sub + + + Public Sub CSharp_TestNull_Local() + Dim workspace = + + + + class C + { + void M() + { + int i$$; + } + } + + + + + TestIsNull(workspace) + End Sub + + + Public Sub CSharp_TestNull_Label() + Dim workspace = + + + + class C + { + void M() + { + label$$: + int i; + } + } + + + + + TestIsNull(workspace) + End Sub + #End Region #Region "Visual Basic Tests" @@ -564,6 +686,124 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo }) End Sub + + Public Sub VisualBasic_TestMetadata_GenericType() + Dim workspace = + + + + Imports System.Collections.Generic + Class C + Dim s As List$$(Of Integer) + End Class + + + + + Test(workspace, + canonicalNodes:={ + Package("Z:\FxReferenceAssembliesUri"), + [Namespace]("System"), + [Namespace]("Collections"), + [Namespace]("Generic"), + [Class]("List(Of T)") + }, + presentationNodes:={ + Package("Z:\FxReferenceAssembliesUri"), + [Namespace]("System.Collections.Generic"), + [Class]("List(Of T)") + }) + End Sub + + + Public Sub VisualBasic_TestMetadata_GenericMethod() + Dim workspace = + + + + Imports System + Class C + Sub M() + Dim a = New Integer() { 1, 2, 3, 4, 5 } + Dim r = Array.AsReadOnly$$(a) + End Sub + End Class + + + + + Test(workspace, + canonicalNodes:={ + Package("Z:\FxReferenceAssembliesUri"), + [Namespace]("System"), + [Class]("Array"), + Member("AsReadOnly(Of T)(T()) As System.Collections.ObjectModel.ReadOnlyCollection(Of T)") + }, + presentationNodes:={ + Package("Z:\FxReferenceAssembliesUri"), + [Namespace]("System"), + [Class]("Array"), + Member("AsReadOnly(Of T)(T()) As System.Collections.ObjectModel.ReadOnlyCollection(Of T)") + }) + End Sub + + + Public Sub VisualBasic_TestNull_Parameter() + Dim workspace = + + + + Class C + Sub M(i$$ As Integer) + End Sub + End Class + + + + + TestIsNull(workspace) + End Sub + + + Public Sub VisualBasic_TestNull_Local() + Dim workspace = + + + + Class C + Sub M() + Dim i$$ As Integer + End Sub + End Class + + + + + TestIsNull(workspace) + End Sub + + + Public Sub VisualBasic_TestNull_Label() + Dim workspace = + + + + Class C + void M() + { + Sub M() + label$$: + Dim i As Integer + End Sub + } + End Class + + + + + TestIsNull(workspace) + End Sub + #End Region Private Shared Sub IsOK(comAction As Func(Of Integer)) @@ -639,7 +879,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo Dim project = document.Project Dim compilation = project.GetCompilationAsync(CancellationToken.None).Result - Dim navInfo = libraryService.NavInfo.CreateForSymbol(symbol, document.Project, compilation, useExpandedHierarchy) + Dim navInfo = libraryService.NavInfoFactory.CreateForSymbol(symbol, document.Project, compilation, useExpandedHierarchy) Assert.True(navInfo IsNot Nothing, $"Could not retrieve nav info for {symbol.ToDisplayString()}") If canonicalNodes IsNot Nothing Then @@ -657,5 +897,30 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo End If End Using End Sub + + Private Shared Sub TestIsNull( + workspaceDefinition As XElement, + Optional useExpandedHierarchy As Boolean = False + ) + + Using workspace = TestWorkspaceFactory.CreateWorkspace(workspaceDefinition, exportProvider:=VisualStudioTestExportProvider.ExportProvider) + Dim hostDocument = workspace.DocumentWithCursor + Assert.True(hostDocument IsNot Nothing, "Test defined without cursor position") + + Dim document = workspace.CurrentSolution.GetDocument(hostDocument.Id) + Dim semanticModel = document.GetSemanticModelAsync(CancellationToken.None).Result + Dim position As Integer = hostDocument.CursorPosition.Value + Dim symbol = SymbolFinder.FindSymbolAtPosition(semanticModel, position, workspace, CancellationToken.None) + Assert.True(symbol IsNot Nothing, $"Could not find symbol as position, {position}") + + Dim libraryService = document.Project.LanguageServices.GetService(Of ILibraryService) + + Dim project = document.Project + Dim compilation = project.GetCompilationAsync(CancellationToken.None).Result + Dim navInfo = libraryService.NavInfoFactory.CreateForSymbol(symbol, document.Project, compilation, useExpandedHierarchy) + Assert.Null(navInfo) + End Using + End Sub + End Class End Namespace \ No newline at end of file diff --git a/src/VisualStudio/VisualBasic/Impl/BasicVisualStudio.vbproj b/src/VisualStudio/VisualBasic/Impl/BasicVisualStudio.vbproj index fb0eafc1daf2c59e05f7474490b8b755a565d377..e2aefa983e6eb73ccad6f9cbead02b8734074aaa 100644 --- a/src/VisualStudio/VisualBasic/Impl/BasicVisualStudio.vbproj +++ b/src/VisualStudio/VisualBasic/Impl/BasicVisualStudio.vbproj @@ -128,7 +128,6 @@ - diff --git a/src/VisualStudio/VisualBasic/Impl/ObjectBrowser/VisualBasicLibraryService.vb b/src/VisualStudio/VisualBasic/Impl/ObjectBrowser/VisualBasicLibraryService.vb index f36e38c0ff5e13aba646add8d6a0914bdcfdff47..5ffff3094a1518deaa3ef934480e64f6fa62ae62 100644 --- a/src/VisualStudio/VisualBasic/Impl/ObjectBrowser/VisualBasicLibraryService.vb +++ b/src/VisualStudio/VisualBasic/Impl/ObjectBrowser/VisualBasicLibraryService.vb @@ -1,10 +1,13 @@ ' 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.Composition Imports Microsoft.CodeAnalysis +Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.VisualStudio.LanguageServices.Implementation.Library Imports Microsoft.VisualStudio.Shell.Interop Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ObjectBrowser + Friend Class VisualBasicLibraryService Inherits AbstractLibraryService diff --git a/src/VisualStudio/VisualBasic/Impl/ObjectBrowser/VisualBasicLibraryServiceFactory.vb b/src/VisualStudio/VisualBasic/Impl/ObjectBrowser/VisualBasicLibraryServiceFactory.vb deleted file mode 100644 index 8246f8bab33e4d0d4334cd02df031ac5305ce133..0000000000000000000000000000000000000000 --- a/src/VisualStudio/VisualBasic/Impl/ObjectBrowser/VisualBasicLibraryServiceFactory.vb +++ /dev/null @@ -1,18 +0,0 @@ -' 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.Composition -Imports Microsoft.CodeAnalysis -Imports Microsoft.CodeAnalysis.Host -Imports Microsoft.CodeAnalysis.Host.Mef -Imports Microsoft.VisualStudio.LanguageServices.Implementation.Library - -Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ObjectBrowser - - Friend Class VisualBasicLibraryServiceFactory - Implements ILanguageServiceFactory - - Public Function CreateLanguageService(languageServices As HostLanguageServices) As ILanguageService Implements ILanguageServiceFactory.CreateLanguageService - Return New VisualBasicLibraryService() - End Function - End Class -End Namespace \ No newline at end of file