提交 8150bc4c 编写于 作者: D Dustin Campbell

Implement Code Review feedback for Object Browser navigation

* Remove unintentionally added extra option.
* Rename NavInfo property to NavInfoFactory.
* Add fallback to metadata-as-source if NavInfo can't be retrieved for some reason.
* Use [ExportLanguageService] attributes rather than language service factories.
* Add NavInfo tests for generic methods and types
* Add negative NavInfo tests for parameters, locals and labels
* Rename UsePreviewTab option to PreferProvisionalTab to remove some confusion around what it does, and document it.
上级 0d4a7181
...@@ -102,7 +102,7 @@ public void NavigateTo() ...@@ -102,7 +102,7 @@ public void NavigateTo()
if (document != null) if (document != null)
{ {
var navigator = _workspace.Services.GetService<IDocumentNavigationService>(); var navigator = _workspace.Services.GetService<IDocumentNavigationService>();
var options = _workspace.Options.WithChangedOption(NavigationOptions.UsePreviewTab, true); var options = _workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true);
navigator.TryNavigateToSpan(_workspace, document.Id, _span, options); navigator.TryNavigateToSpan(_workspace, document.Id, _span, options);
} }
} }
......
...@@ -133,7 +133,7 @@ public void NavigateTo(SymbolKey id, Project project, CancellationToken cancella ...@@ -133,7 +133,7 @@ public void NavigateTo(SymbolKey id, Project project, CancellationToken cancella
var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken); var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var resolution = id.Resolve(compilation, cancellationToken: cancellationToken); var resolution = id.Resolve(compilation, cancellationToken: cancellationToken);
var workspace = project.Solution.Workspace; 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<ISymbolNavigationService>(); var symbolNavigationService = workspace.Services.GetService<ISymbolNavigationService>();
symbolNavigationService.TryNavigateToSymbol(resolution.Symbol, project, options, cancellationToken); symbolNavigationService.TryNavigateToSymbol(resolution.Symbol, project, options, cancellationToken);
......
...@@ -73,7 +73,7 @@ internal static class GoToDefinitionHelpers ...@@ -73,7 +73,7 @@ internal static class GoToDefinitionHelpers
var symbolNavigationService = solution.Workspace.Services.GetService<ISymbolNavigationService>(); var symbolNavigationService = solution.Workspace.Services.GetService<ISymbolNavigationService>();
return symbolNavigationService.TryNavigateToSymbol( return symbolNavigationService.TryNavigateToSymbol(
symbol, project, symbol, project,
options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true), options: options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true),
cancellationToken: cancellationToken); cancellationToken: cancellationToken);
} }
...@@ -90,7 +90,7 @@ internal static class GoToDefinitionHelpers ...@@ -90,7 +90,7 @@ internal static class GoToDefinitionHelpers
workspace, workspace,
documentId: solution.GetDocument(firstItem.SourceTree).Id, documentId: solution.GetDocument(firstItem.SourceTree).Id,
textSpan: firstItem.SourceSpan, textSpan: firstItem.SourceSpan,
options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true)); options: options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true));
} }
else else
{ {
......
...@@ -61,8 +61,5 @@ internal static class FeatureOnOffOptions ...@@ -61,8 +61,5 @@ internal static class FeatureOnOffOptions
/// </summary> /// </summary>
[ExportOption] [ExportOption]
public static readonly PerLanguageOption<bool> RefactoringVerification = new PerLanguageOption<bool>(OptionName, "Refactoring Verification", defaultValue: false); public static readonly PerLanguageOption<bool> RefactoringVerification = new PerLanguageOption<bool>(OptionName, "Refactoring Verification", defaultValue: false);
[ExportOption]
public static readonly PerLanguageOption<bool> GoToDefinitionUsesObjectBrowser = new PerLanguageOption<bool>(OptionName, "Go To Definition Uses Object Browser", defaultValue: false);
} }
} }
...@@ -8,6 +8,10 @@ internal static class NavigationOptions ...@@ -8,6 +8,10 @@ internal static class NavigationOptions
{ {
public const string FeatureName = "Navigation"; public const string FeatureName = "Navigation";
public static readonly Option<bool> UsePreviewTab = new Option<bool>(FeatureName, "UsePreviewTab", defaultValue: false); /// <summary>
/// This option can be passed to the <see cref="IDocumentNavigationService"/> APIs to request that a provisional (or preview) tab
/// be used for any document that needs to be opened, if one is available.
/// </summary>
public static readonly Option<bool> PreferProvisionalTab = new Option<bool>(FeatureName, "PreferProvisionalTab", defaultValue: false);
} }
} }
...@@ -11,14 +11,8 @@ namespace Microsoft.CodeAnalysis.Navigation ...@@ -11,14 +11,8 @@ namespace Microsoft.CodeAnalysis.Navigation
[ExportOptionProvider, Shared] [ExportOptionProvider, Shared]
internal class NavigationOptionsProvider : IOptionProvider internal class NavigationOptionsProvider : IOptionProvider
{ {
private readonly IEnumerable<IOption> _options = new List<IOption> private readonly IEnumerable<IOption> _options = ImmutableArray.Create(NavigationOptions.PreferProvisionalTab);
{
NavigationOptions.UsePreviewTab
}.ToImmutableArray();
public IEnumerable<IOption> GetOptions() public IEnumerable<IOption> GetOptions() => _options;
{
return _options;
}
} }
} }
...@@ -198,7 +198,6 @@ ...@@ -198,7 +198,6 @@
<Compile Include="Debugging\LocationInfoGetter.cs" /> <Compile Include="Debugging\LocationInfoGetter.cs" />
<Compile Include="LanguageService\HACK_CSharpCreateServicesOnUIThread.cs" /> <Compile Include="LanguageService\HACK_CSharpCreateServicesOnUIThread.cs" />
<Compile Include="ObjectBrowser\CSharpLibraryService.cs" /> <Compile Include="ObjectBrowser\CSharpLibraryService.cs" />
<Compile Include="ObjectBrowser\CSharpLibraryServiceFactory.cs" />
<Compile Include="ObjectBrowser\ListItemFactory.cs" /> <Compile Include="ObjectBrowser\ListItemFactory.cs" />
<Compile Include="Options\AdvancedOptionPageStrings.cs" /> <Compile Include="Options\AdvancedOptionPageStrings.cs" />
<Compile Include="Options\IntelliSenseOptionPageStrings.cs" /> <Compile Include="Options\IntelliSenseOptionPageStrings.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.LanguageServices.Implementation.Library; using Microsoft.VisualStudio.LanguageServices.Implementation.Library;
using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.LanguageServices.CSharp.ObjectBrowser namespace Microsoft.VisualStudio.LanguageServices.CSharp.ObjectBrowser
{ {
[ExportLanguageService(typeof(ILibraryService), LanguageNames.CSharp), Shared]
internal class CSharpLibraryService : AbstractLibraryService internal class CSharpLibraryService : AbstractLibraryService
{ {
private static readonly SymbolDisplayFormat s_typeDisplayFormat = new SymbolDisplayFormat( private static readonly SymbolDisplayFormat s_typeDisplayFormat = new SymbolDisplayFormat(
......
// 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();
}
}
}
...@@ -15,7 +15,7 @@ internal abstract class AbstractLibraryService : ILibraryService ...@@ -15,7 +15,7 @@ internal abstract class AbstractLibraryService : ILibraryService
public SymbolDisplayFormat TypeDisplayFormat { get; } public SymbolDisplayFormat TypeDisplayFormat { get; }
public SymbolDisplayFormat MemberDisplayFormat { get; } public SymbolDisplayFormat MemberDisplayFormat { get; }
public NavInfoFactory NavInfo { get; } public NavInfoFactory NavInfoFactory { get; }
protected AbstractLibraryService( protected AbstractLibraryService(
Guid libraryId, Guid libraryId,
...@@ -28,7 +28,7 @@ internal abstract class AbstractLibraryService : ILibraryService ...@@ -28,7 +28,7 @@ internal abstract class AbstractLibraryService : ILibraryService
this.TypeDisplayFormat = typeDisplayFormat; this.TypeDisplayFormat = typeDisplayFormat;
this.MemberDisplayFormat = memberDisplayFormat; this.MemberDisplayFormat = memberDisplayFormat;
this.NavInfo = new NavInfoFactory(this); this.NavInfoFactory = new NavInfoFactory(this);
} }
} }
} }
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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.CodeAnalysis.Host;
using Microsoft.VisualStudio.LanguageServices.Implementation.Library.VsNavInfo; using Microsoft.VisualStudio.LanguageServices.Implementation.Library.VsNavInfo;
...@@ -8,6 +7,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Library ...@@ -8,6 +7,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Library
{ {
internal interface ILibraryService : ILanguageService internal interface ILibraryService : ILanguageService
{ {
NavInfoFactory NavInfo { get; } NavInfoFactory NavInfoFactory { get; }
} }
} }
...@@ -44,7 +44,7 @@ private Compilation GetCompilation() ...@@ -44,7 +44,7 @@ private Compilation GetCompilation()
protected void AddAssemblyLink(IAssemblySymbol assemblySymbol) protected void AddAssemblyLink(IAssemblySymbol assemblySymbol)
{ {
var name = assemblySymbol.Identity.Name; 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); _description.AddDescriptionText3(name, VSOBDESCRIPTIONSECTION.OBDS_TYPE, navInfo);
} }
...@@ -82,7 +82,7 @@ protected void AddNamespaceLink(INamespaceSymbol namespaceSymbol) ...@@ -82,7 +82,7 @@ protected void AddNamespaceLink(INamespaceSymbol namespaceSymbol)
} }
var text = namespaceSymbol.ToDisplayString(); 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); _description.AddDescriptionText3(text, VSOBDESCRIPTIONSECTION.OBDS_TYPE, navInfo);
} }
...@@ -131,7 +131,7 @@ protected void AddTypeLink(ITypeSymbol typeSymbol, LinkFlags flags) ...@@ -131,7 +131,7 @@ protected void AddTypeLink(ITypeSymbol typeSymbol, LinkFlags flags)
miscellaneousOptions: miscellaneousOptions); miscellaneousOptions: miscellaneousOptions);
var text = typeSymbol.ToDisplayString(typeDisplayFormat); 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); _description.AddDescriptionText3(text, VSOBDESCRIPTIONSECTION.OBDS_TYPE, navInfo);
} }
......
...@@ -399,7 +399,7 @@ protected override int CreateNavInfo(SYMBOL_DESCRIPTION_NODE[] rgSymbolNodes, ui ...@@ -399,7 +399,7 @@ protected override int CreateNavInfo(SYMBOL_DESCRIPTION_NODE[] rgSymbolNodes, ui
SharedPools.Default<StringBuilder>().ClearAndFree(className); SharedPools.Default<StringBuilder>().ClearAndFree(className);
// TODO: Make sure we pass the right value for Visual Basic. // 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; return VSConstants.S_OK;
} }
...@@ -426,18 +426,18 @@ internal IVsNavInfo GetNavInfo(SymbolListItem symbolListItem, bool useExpandedHi ...@@ -426,18 +426,18 @@ internal IVsNavInfo GetNavInfo(SymbolListItem symbolListItem, bool useExpandedHi
if (symbolListItem is MemberListItem) 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) 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) 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) protected override bool TryQueryStatus(Guid commandGroup, uint commandId, ref OLECMDF commandFlags)
......
...@@ -564,14 +564,14 @@ protected override IVsNavInfo GetNavInfo(uint index) ...@@ -564,14 +564,14 @@ protected override IVsNavInfo GetNavInfo(uint index)
var project = this.LibraryManager.GetProject(projectListItem.ProjectId); var project = this.LibraryManager.GetProject(projectListItem.ProjectId);
if (project != null) if (project != null)
{ {
return this.LibraryManager.LibraryService.NavInfo.CreateForProject(project); return this.LibraryManager.LibraryService.NavInfoFactory.CreateForProject(project);
} }
} }
var referenceListItem = listItem as ReferenceListItem; var referenceListItem = listItem as ReferenceListItem;
if (referenceListItem != null) if (referenceListItem != null)
{ {
return this.LibraryManager.LibraryService.NavInfo.CreateForReference(referenceListItem.MetadataReference); return this.LibraryManager.LibraryService.NavInfoFactory.CreateForReference(referenceListItem.MetadataReference);
} }
var symbolListItem = listItem as SymbolListItem; var symbolListItem = listItem as SymbolListItem;
......
...@@ -128,6 +128,8 @@ public IVsNavInfo CreateForType(ITypeSymbol typeSymbol, Project project, Compila ...@@ -128,6 +128,8 @@ public IVsNavInfo CreateForType(ITypeSymbol typeSymbol, Project project, Compila
public IVsNavInfo CreateForMember(ISymbol memberSymbol, Project project, Compilation compilation, bool useExpandedHierarchy = false) public IVsNavInfo CreateForMember(ISymbol memberSymbol, Project project, Compilation compilation, bool useExpandedHierarchy = false)
{ {
memberSymbol = memberSymbol.OriginalDefinition;
return Create( return Create(
memberSymbol.ContainingAssembly, memberSymbol.ContainingAssembly,
project, project,
......
...@@ -188,7 +188,7 @@ protected bool TryNavigateTo(Workspace workspace, DocumentId documentId, int lin ...@@ -188,7 +188,7 @@ protected bool TryNavigateTo(Workspace workspace, DocumentId documentId, int lin
return false; 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)) if (navigationService.TryNavigateToLineAndOffset(workspace, documentId, line, column, options))
{ {
return true; return true;
......
...@@ -185,7 +185,7 @@ private static Document OpenDocument(Workspace workspace, DocumentId documentId, ...@@ -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. // in a permanent tab, this allows the document to transition to the new state.
if (workspace.CanOpenDocuments) if (workspace.CanOpenDocuments)
{ {
if (options.GetOption(NavigationOptions.UsePreviewTab)) if (options.GetOption(NavigationOptions.PreferProvisionalTab))
{ {
using (NewDocumentStateScope ndss = new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.Navigation)) using (NewDocumentStateScope ndss = new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.Navigation))
{ {
......
...@@ -94,19 +94,19 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet optio ...@@ -94,19 +94,19 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet optio
} }
var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken); 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) if (navInfo == null)
{ {
navInfo = libraryService.NavInfo.CreateForProject(project); navInfo = libraryService.NavInfoFactory.CreateForProject(project);
} }
if (navInfo == null) if (navInfo != null)
{ {
return false; var navigationTool = GetService<SVsObjBrowser, IVsNavigationTool>();
return navigationTool.NavigateToNavInfo(navInfo) == VSConstants.S_OK;
} }
var navigationTool = GetService<SVsObjBrowser, IVsNavigationTool>(); // Note: we'll fallback to Metadata-As-Source if we fail to get IVsNavInfo, but that should never happen.
return navigationTool.NavigateToNavInfo(navInfo) == VSConstants.S_OK;
} }
// Generate new source or retrieve existing source for the symbol in question // 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 ...@@ -147,7 +147,7 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet optio
workspace: editorWorkspace, workspace: editorWorkspace,
documentId: openedDocument.Id, documentId: openedDocument.Id,
textSpan: result.IdentifierLocation.SourceSpan, textSpan: result.IdentifierLocation.SourceSpan,
options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true)); options: options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true));
} }
return true; return true;
......
...@@ -274,6 +274,128 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo ...@@ -274,6 +274,128 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo
}) })
End Sub End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub CSharp_TestMetadata_GenericType()
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true" AssemblyName="CSharpTestAssembly">
<Document>
using System.Collections.Generic;
class C
{
$$List&lt;int&gt; s;
}
</Document>
</Project>
</Workspace>
Test(workspace,
canonicalNodes:={
Package("Z:\FxReferenceAssembliesUri"),
[Namespace]("System"),
[Namespace]("Collections"),
[Namespace]("Generic"),
[Class]("List<T>")
},
presentationNodes:={
Package("Z:\FxReferenceAssembliesUri"),
[Namespace]("System.Collections.Generic"),
[Class]("List<T>")
})
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub CSharp_TestMetadata_GenericMethod()
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true" AssemblyName="CSharpTestAssembly">
<Document>
using System;
class C
{
void M()
{
var a = new int[] { 1, 2, 3, 4, 5 };
var r = Array.AsReadOnly$$(a);
}
}
</Document>
</Project>
</Workspace>
Test(workspace,
canonicalNodes:={
Package("Z:\FxReferenceAssembliesUri"),
[Namespace]("System"),
[Class]("Array"),
Member("AsReadOnly<T>(T[])")
},
presentationNodes:={
Package("Z:\FxReferenceAssembliesUri"),
[Namespace]("System"),
[Class]("Array"),
Member("AsReadOnly<T>(T[])")
})
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub CSharp_TestNull_Parameter()
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true" AssemblyName="CSharpTestAssembly">
<Document>
class C
{
void M(int i$$) { }
}
</Document>
</Project>
</Workspace>
TestIsNull(workspace)
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub CSharp_TestNull_Local()
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true" AssemblyName="CSharpTestAssembly">
<Document>
class C
{
void M()
{
int i$$;
}
}
</Document>
</Project>
</Workspace>
TestIsNull(workspace)
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub CSharp_TestNull_Label()
Dim workspace =
<Workspace>
<Project Language="C#" CommonReferences="true" AssemblyName="CSharpTestAssembly">
<Document>
class C
{
void M()
{
label$$:
int i;
}
}
</Document>
</Project>
</Workspace>
TestIsNull(workspace)
End Sub
#End Region #End Region
#Region "Visual Basic Tests" #Region "Visual Basic Tests"
...@@ -564,6 +686,124 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo ...@@ -564,6 +686,124 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo
}) })
End Sub End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub VisualBasic_TestMetadata_GenericType()
Dim workspace =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true" AssemblyName="VBTestAssembly">
<Document>
Imports System.Collections.Generic
Class C
Dim s As List$$(Of Integer)
End Class
</Document>
</Project>
</Workspace>
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
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub VisualBasic_TestMetadata_GenericMethod()
Dim workspace =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true" AssemblyName="VisualBasicTestAssembly">
<Document>
Imports System
Class C
Sub M()
Dim a = New Integer() { 1, 2, 3, 4, 5 }
Dim r = Array.AsReadOnly$$(a)
End Sub
End Class
</Document>
</Project>
</Workspace>
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
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub VisualBasic_TestNull_Parameter()
Dim workspace =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true" AssemblyName="VBTestAssembly">
<Document>
Class C
Sub M(i$$ As Integer)
End Sub
End Class
</Document>
</Project>
</Workspace>
TestIsNull(workspace)
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub VisualBasic_TestNull_Local()
Dim workspace =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true" AssemblyName="VBTestAssembly">
<Document>
Class C
Sub M()
Dim i$$ As Integer
End Sub
End Class
</Document>
</Project>
</Workspace>
TestIsNull(workspace)
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.VsNavInfo)>
Public Sub VisualBasic_TestNull_Label()
Dim workspace =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true" AssemblyName="VBTestAssembly">
<Document>
Class C
void M()
{
Sub M()
label$$:
Dim i As Integer
End Sub
}
End Class
</Document>
</Project>
</Workspace>
TestIsNull(workspace)
End Sub
#End Region #End Region
Private Shared Sub IsOK(comAction As Func(Of Integer)) Private Shared Sub IsOK(comAction As Func(Of Integer))
...@@ -639,7 +879,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo ...@@ -639,7 +879,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo
Dim project = document.Project Dim project = document.Project
Dim compilation = project.GetCompilationAsync(CancellationToken.None).Result 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()}") Assert.True(navInfo IsNot Nothing, $"Could not retrieve nav info for {symbol.ToDisplayString()}")
If canonicalNodes IsNot Nothing Then If canonicalNodes IsNot Nothing Then
...@@ -657,5 +897,30 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo ...@@ -657,5 +897,30 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.VsNavInfo
End If End If
End Using End Using
End Sub 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 Class
End Namespace End Namespace
\ No newline at end of file
...@@ -128,7 +128,6 @@ ...@@ -128,7 +128,6 @@
<Compile Include="ObjectBrowser\ListItemFactory.vb" /> <Compile Include="ObjectBrowser\ListItemFactory.vb" />
<Compile Include="ObjectBrowser\ObjectBrowserLibraryManager.vb" /> <Compile Include="ObjectBrowser\ObjectBrowserLibraryManager.vb" />
<Compile Include="ObjectBrowser\VisualBasicLibraryService.vb" /> <Compile Include="ObjectBrowser\VisualBasicLibraryService.vb" />
<Compile Include="ObjectBrowser\VisualBasicLibraryServiceFactory.vb" />
<Compile Include="Options\AdvancedOptionPageStrings.vb" /> <Compile Include="Options\AdvancedOptionPageStrings.vb" />
<Compile Include="Options\AutomationObject.vb" /> <Compile Include="Options\AutomationObject.vb" />
<Compile Include="Options\VisualBasicLanguageSettingsSerializer.vb" /> <Compile Include="Options\VisualBasicLanguageSettingsSerializer.vb" />
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. ' 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
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.VisualStudio.LanguageServices.Implementation.Library Imports Microsoft.VisualStudio.LanguageServices.Implementation.Library
Imports Microsoft.VisualStudio.Shell.Interop Imports Microsoft.VisualStudio.Shell.Interop
Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ObjectBrowser Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ObjectBrowser
<ExportLanguageService(GetType(ILibraryService), LanguageNames.VisualBasic), [Shared]>
Friend Class VisualBasicLibraryService Friend Class VisualBasicLibraryService
Inherits AbstractLibraryService Inherits AbstractLibraryService
......
' 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
<ExportLanguageServiceFactory(GetType(ILibraryService), LanguageNames.VisualBasic), [Shared]>
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册