提交 e583c0c1 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14693 from CyrusNajmabadi/navigateToItemDisplay3

Introduce abstraction layer to allow VS15 to create new types of NavigateTo item displays.
......@@ -859,7 +859,7 @@ public partial class C
_provider = new NavigateToItemProvider(
workspace, _glyphServiceMock.Object, aggregateListener,
workspace.ExportProvider.GetExportedValues<Lazy<INavigateToOptionsService, VisualStudioVersionMetadata>>());
workspace.ExportProvider.GetExportedValues<Lazy<INavigateToHostVersionService, VisualStudioVersionMetadata>>());
_aggregator = new NavigateToTestAggregator(_provider);
var items = await _aggregator.GetItemsAsync("VisibleMethod");
......
......@@ -107,6 +107,7 @@
<InternalsVisibleToMoq Include="DynamicProxyGenAssembly2" />
</ItemGroup>
<ItemGroup>
<Compile Include="Implementation\NavigateTo\AbstractNavigateToItemDisplay.cs" />
<Compile Include="CommandArgs.cs" />
<Compile Include="CommandHandlers\AbstractCompletionCommandHandler.cs" />
<Compile Include="CommandHandlers\AbstractIntelliSenseCommandHandler.cs" />
......@@ -270,7 +271,8 @@
<Compile Include="Implementation\Intellisense\Completion\Presentation\VisualStudio14CompletionSetFactory.cs" />
<Compile Include="Implementation\Interactive\IAbstractResetInteractiveCommand.cs" />
<Compile Include="Implementation\LineSeparators\LineSeparatorAdornmentManagerProvider.cs" />
<Compile Include="Implementation\NavigateTo\INavigateToOptionsService.cs" />
<Compile Include="Implementation\NavigateTo\Dev14NavigateToHostVersionService.cs" />
<Compile Include="Implementation\NavigateTo\INavigateToHostVersionService.cs" />
<Compile Include="Implementation\Structure\InvalidOutliningRegionException.cs" />
<Compile Include="Implementation\Structure\AbstractStructureTaggerProvider.cs" />
<Compile Include="Implementation\Preview\DifferenceViewerPreview.cs" />
......@@ -536,8 +538,8 @@
<Compile Include="Implementation\NavigateTo\INavigateToPreviewService.cs" />
<Compile Include="Implementation\NavigateTo\NavigateToIconFactory.cs" />
<Compile Include="Implementation\NavigateTo\NavigateToItemProvider.cs" />
<Compile Include="Implementation\NavigateTo\NavigateToItemProvider.ItemDisplayFactory.cs" />
<Compile Include="Implementation\NavigateTo\NavigateToItemProvider.NavigateToItemDisplay.cs" />
<Compile Include="Implementation\NavigateTo\Dev14NavigateToHostVersionService.ItemDisplayFactory.cs" />
<Compile Include="Implementation\NavigateTo\Dev14NavigateToHostVersionService.NavigateToItemDisplay.cs" />
<Compile Include="Implementation\NavigateTo\NavigateToItemProvider.Searcher.cs" />
<Compile Include="Implementation\NavigateTo\NavigateToItemProviderFactory.cs" />
<Compile Include="Implementation\NavigationBar\NavigationBarController.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.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Threading;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.VisualStudio.Language.NavigateTo.Interfaces;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo
{
internal abstract class AbstractNavigateToItemDisplay : INavigateToItemDisplay2
{
protected readonly INavigateToSearchResult SearchResult;
private ReadOnlyCollection<DescriptionItem> _descriptionItems;
protected AbstractNavigateToItemDisplay(INavigateToSearchResult searchResult)
{
SearchResult = searchResult;
}
public string AdditionalInformation => SearchResult.AdditionalInformation;
public string Description => null;
public ReadOnlyCollection<DescriptionItem> DescriptionItems
{
get
{
if (_descriptionItems == null)
{
_descriptionItems = CreateDescriptionItems();
}
return _descriptionItems;
}
}
private ReadOnlyCollection<DescriptionItem> CreateDescriptionItems()
{
var document = SearchResult.NavigableItem.Document;
if (document == null)
{
return new List<DescriptionItem>().AsReadOnly();
}
var sourceText = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var items = new List<DescriptionItem>
{
new DescriptionItem(
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun("Project:", bold: true) }),
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun(document.Project.Name) })),
new DescriptionItem(
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun("File:", bold: true) }),
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun(document.FilePath ?? document.Name) })),
new DescriptionItem(
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun("Line:", bold: true) }),
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun((sourceText.Lines.IndexOf(SearchResult.NavigableItem.SourceSpan.Start) + 1).ToString()) }))
};
var summary = SearchResult.Summary;
if (!string.IsNullOrWhiteSpace(summary))
{
items.Add(
new DescriptionItem(
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun("Summary:", bold: true) }),
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun(summary) })));
}
return items.AsReadOnly();
}
public abstract Icon Glyph { get; }
public string Name => SearchResult.NavigableItem.DisplayTaggedParts.JoinText();
public void NavigateTo()
{
var document = SearchResult.NavigableItem.Document;
if (document == null)
{
return;
}
var workspace = document.Project.Solution.Workspace;
var navigationService = workspace.Services.GetService<IDocumentNavigationService>();
// Document tabs opened by NavigateTo are carefully created as preview or regular
// tabs by them; trying to specifically open them in a particular kind of tab here
// has no effect.
navigationService.TryNavigateToSpan(workspace, document.Id, SearchResult.NavigableItem.SourceSpan);
}
public int GetProvisionalViewingStatus()
{
var document = SearchResult.NavigableItem.Document;
if (document == null)
{
return 0;
}
var workspace = document.Project.Solution.Workspace;
var previewService = workspace.Services.GetService<INavigateToPreviewService>();
return previewService.GetProvisionalViewingStatus(document);
}
public void PreviewItem()
{
var document = SearchResult.NavigableItem.Document;
if (document == null)
{
return;
}
var workspace = document.Project.Solution.Workspace;
var previewService = workspace.Services.GetService<INavigateToPreviewService>();
previewService.PreviewItem(this);
}
}
}
\ No newline at end of file
......@@ -7,13 +7,13 @@
namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo
{
internal partial class NavigateToItemProvider
internal partial class Dev14NavigateToHostVersionService
{
private class ItemDisplayFactory : INavigateToItemDisplayFactory, IDisposable
private class Dev14ItemDisplayFactory : INavigateToItemDisplayFactory, IDisposable
{
private readonly NavigateToIconFactory _iconFactory;
public ItemDisplayFactory(NavigateToIconFactory iconFactory)
public Dev14ItemDisplayFactory(NavigateToIconFactory iconFactory)
{
Contract.ThrowIfNull(iconFactory);
......@@ -23,7 +23,7 @@ public ItemDisplayFactory(NavigateToIconFactory iconFactory)
public INavigateToItemDisplay CreateItemDisplay(NavigateToItem item)
{
var searchResult = (INavigateToSearchResult)item.Tag;
return new NavigateToItemDisplay(searchResult, _iconFactory);
return new Dev14NavigateToItemDisplay(searchResult, _iconFactory);
}
public void Dispose()
......
// 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.Drawing;
using Microsoft.CodeAnalysis.NavigateTo;
namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo
{
internal partial class Dev14NavigateToHostVersionService
{
private class Dev14NavigateToItemDisplay : AbstractNavigateToItemDisplay
{
private readonly NavigateToIconFactory _iconFactory;
private Icon _glyph;
public Dev14NavigateToItemDisplay(INavigateToSearchResult searchResult, NavigateToIconFactory iconFactory)
: base(searchResult)
{
_iconFactory = iconFactory;
}
public override Icon Glyph
{
get
{
if (_glyph == null)
{
_glyph = _iconFactory.GetIcon(SearchResult.NavigableItem.Glyph);
}
return _glyph;
}
}
}
}
}
\ No newline at end of file
// 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.ComponentModel.Composition;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Language.NavigateTo.Interfaces;
namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo
{
[ExportVersionSpecific(typeof(INavigateToHostVersionService), VisualStudioVersion.Dev14)]
internal sealed partial class Dev14NavigateToHostVersionService : INavigateToHostVersionService
{
private readonly IGlyphService _glyphService;
[ImportingConstructor]
public Dev14NavigateToHostVersionService(
IGlyphService glyphService)
{
_glyphService = glyphService;
}
public bool GetSearchCurrentDocument(INavigateToOptions options)
=> false;
public INavigateToItemDisplayFactory CreateDisplayFactory()
=> new Dev14ItemDisplayFactory(new NavigateToIconFactory(_glyphService));
}
}
\ No newline at end of file
......@@ -4,17 +4,13 @@
namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo
{
internal interface INavigateToOptionsService
/// <summary>
/// Contains navigate-to specific operations that depend on the version of the
/// host they're running under.
/// </summary>
internal interface INavigateToHostVersionService
{
bool GetSearchCurrentDocument(INavigateToOptions options);
}
[ExportVersionSpecific(typeof(INavigateToOptionsService), VisualStudioVersion.Dev14)]
internal class Dev14NavigateToOptionsService : INavigateToOptionsService
{
public bool GetSearchCurrentDocument(INavigateToOptions options)
{
return false;
}
INavigateToItemDisplayFactory CreateDisplayFactory();
}
}
\ No newline at end of file
// 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Threading;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.VisualStudio.Language.NavigateTo.Interfaces;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo
{
internal partial class NavigateToItemProvider
{
private class NavigateToItemDisplay : INavigateToItemDisplay2
{
private readonly INavigateToSearchResult _searchResult;
private readonly NavigateToIconFactory _iconFactory;
private Icon _glyph;
private ReadOnlyCollection<DescriptionItem> _descriptionItems;
public NavigateToItemDisplay(INavigateToSearchResult searchResult, NavigateToIconFactory iconFactory)
{
_searchResult = searchResult;
_iconFactory = iconFactory;
}
public string AdditionalInformation
{
get
{
return _searchResult.AdditionalInformation;
}
}
public string Description
{
get
{
return null;
}
}
public ReadOnlyCollection<DescriptionItem> DescriptionItems
{
get
{
if (_descriptionItems == null)
{
_descriptionItems = CreateDescriptionItems();
}
return _descriptionItems;
}
}
private ReadOnlyCollection<DescriptionItem> CreateDescriptionItems()
{
var document = _searchResult.NavigableItem.Document;
if (document == null)
{
return new List<DescriptionItem>().AsReadOnly();
}
var sourceText = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var items = new List<DescriptionItem>
{
new DescriptionItem(
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun("Project:", bold: true) }),
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun(document.Project.Name) })),
new DescriptionItem(
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun("File:", bold: true) }),
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun(document.FilePath ?? document.Name) })),
new DescriptionItem(
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun("Line:", bold: true) }),
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun((sourceText.Lines.IndexOf(_searchResult.NavigableItem.SourceSpan.Start) + 1).ToString()) }))
};
var summary = _searchResult.Summary;
if (!string.IsNullOrWhiteSpace(summary))
{
items.Add(
new DescriptionItem(
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun("Summary:", bold: true) }),
new ReadOnlyCollection<DescriptionRun>(
new[] { new DescriptionRun(summary) })));
}
return items.AsReadOnly();
}
public Icon Glyph
{
get
{
if (_glyph == null)
{
_glyph = _iconFactory.GetIcon(_searchResult.NavigableItem.Glyph);
}
return _glyph;
}
}
public string Name => _searchResult.NavigableItem.DisplayTaggedParts.JoinText();
public void NavigateTo()
{
var document = _searchResult.NavigableItem.Document;
if (document == null)
{
return;
}
var workspace = document.Project.Solution.Workspace;
var navigationService = workspace.Services.GetService<IDocumentNavigationService>();
// Document tabs opened by NavigateTo are carefully created as preview or regular
// tabs by them; trying to specifically open them in a particular kind of tab here
// has no effect.
navigationService.TryNavigateToSpan(workspace, document.Id, _searchResult.NavigableItem.SourceSpan);
}
public int GetProvisionalViewingStatus()
{
var document = _searchResult.NavigableItem.Document;
if (document == null)
{
return 0;
}
var workspace = document.Project.Solution.Workspace;
var previewService = workspace.Services.GetService<INavigateToPreviewService>();
return previewService.GetProvisionalViewingStatus(document);
}
public void PreviewItem()
{
var document = _searchResult.NavigableItem.Document;
if (document == null)
{
return;
}
var workspace = document.Project.Solution.Workspace;
var previewService = workspace.Services.GetService<INavigateToPreviewService>();
previewService.PreviewItem(this);
}
}
}
}
......@@ -17,7 +17,7 @@ internal partial class NavigateToItemProvider
private class Searcher
{
private readonly Solution _solution;
private readonly ItemDisplayFactory _displayFactory;
private readonly INavigateToItemDisplayFactory _displayFactory;
private readonly INavigateToCallback _callback;
private readonly string _searchPattern;
private readonly bool _searchCurrentDocument;
......@@ -29,7 +29,7 @@ private class Searcher
public Searcher(
Solution solution,
IAsynchronousOperationListener asyncListener,
ItemDisplayFactory displayFactory,
INavigateToItemDisplayFactory displayFactory,
INavigateToCallback callback,
string searchPattern,
bool searchCurrentDocument,
......
......@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.Editor.Extensibility.Composition;
using Microsoft.CodeAnalysis.Shared.TestHooks;
......@@ -16,8 +17,8 @@ internal partial class NavigateToItemProvider : INavigateToItemProvider
{
private readonly Workspace _workspace;
private readonly IAsynchronousOperationListener _asyncListener;
private readonly ImmutableArray<Lazy<INavigateToOptionsService, VisualStudioVersionMetadata>> _optionsServices;
private readonly ItemDisplayFactory _displayFactory;
private readonly INavigateToItemDisplayFactory _displayFactory;
private readonly ImmutableArray<Lazy<INavigateToHostVersionService, VisualStudioVersionMetadata>> _hostServices;
private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
......@@ -25,7 +26,7 @@ internal partial class NavigateToItemProvider : INavigateToItemProvider
Workspace workspace,
IGlyphService glyphService,
IAsynchronousOperationListener asyncListener,
IEnumerable<Lazy<INavigateToOptionsService, VisualStudioVersionMetadata>> optionsServices)
IEnumerable<Lazy<INavigateToHostVersionService, VisualStudioVersionMetadata>> hostServices)
{
Contract.ThrowIfNull(workspace);
Contract.ThrowIfNull(glyphService);
......@@ -33,8 +34,12 @@ internal partial class NavigateToItemProvider : INavigateToItemProvider
_workspace = workspace;
_asyncListener = asyncListener;
_optionsServices = optionsServices.ToImmutableArray();
_displayFactory = new ItemDisplayFactory(new NavigateToIconFactory(glyphService));
_hostServices = hostServices.ToImmutableArray();
var hostService = _hostServices.Length > 0
? VersionSelector.SelectHighest(hostServices)
: new Dev14NavigateToHostVersionService(glyphService);
_displayFactory = hostService.CreateDisplayFactory();
}
public void StopSearch()
......@@ -46,7 +51,7 @@ public void StopSearch()
public void Dispose()
{
this.StopSearch();
_displayFactory.Dispose();
(_displayFactory as IDisposable)?.Dispose();
}
public void StartSearch(INavigateToCallback callback, string searchValue)
......@@ -90,11 +95,11 @@ private bool GetSearchCurrentDocumentOption(INavigateToCallback callback)
private bool GetSearchCurrentDocumentOptionWorker(INavigateToCallback callback)
{
var optionsService = _optionsServices.Length > 0
? VersionSelector.SelectHighest(_optionsServices)
var hostService = _hostServices.Length > 0
? VersionSelector.SelectHighest(_hostServices)
: null;
var searchCurrentDocument = optionsService?.GetSearchCurrentDocument(callback.Options) ?? false;
var searchCurrentDocument = hostService?.GetSearchCurrentDocument(callback.Options) ?? false;
return searchCurrentDocument;
}
}
}
}
\ No newline at end of file
......@@ -15,12 +15,12 @@ internal class NavigateToItemProviderFactory : INavigateToItemProviderFactory
{
private readonly IGlyphService _glyphService;
private readonly IAsynchronousOperationListener _asyncListener;
private readonly IEnumerable<Lazy<INavigateToOptionsService, VisualStudioVersionMetadata>> _optionsServices;
private readonly IEnumerable<Lazy<INavigateToHostVersionService, VisualStudioVersionMetadata>> _hostServices;
[ImportingConstructor]
public NavigateToItemProviderFactory(
IGlyphService glyphService,
[ImportMany] IEnumerable<Lazy<INavigateToOptionsService, VisualStudioVersionMetadata>> optionsServices,
[ImportMany] IEnumerable<Lazy<INavigateToHostVersionService, VisualStudioVersionMetadata>> hostServices,
[ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners)
{
if (glyphService == null)
......@@ -34,7 +34,7 @@ internal class NavigateToItemProviderFactory : INavigateToItemProviderFactory
}
_glyphService = glyphService;
_optionsServices = optionsServices;
_hostServices = hostServices;
_asyncListener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.NavigateTo);
}
......@@ -49,7 +49,7 @@ public bool TryCreateNavigateToItemProvider(IServiceProvider serviceProvider, ou
return false;
}
provider = new NavigateToItemProvider(workspace, _glyphService, _asyncListener, _optionsServices);
provider = new NavigateToItemProvider(workspace, _glyphService, _asyncListener, _hostServices);
return true;
}
}
......
......@@ -54,6 +54,7 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
......@@ -61,11 +62,12 @@
<PublicAPI Include="PublicAPI.Unshipped.txt" />
</ItemGroup>
<ItemGroup>
<Compile Include="NavigateTo\Dev15NavigateToHostVersionService.cs" />
<Compile Include="NavigateTo\Dev15NavigateToHostVersionService.Dev15ItemDisplayFactory.cs" />
<Compile Include="IntelliSense\Completion\Presentation\IntellisenseFilter2.cs" />
<Compile Include="IntelliSense\Completion\Presentation\Roslyn15CompletionSet.cs" />
<Compile Include="IntelliSense\Completion\Presentation\VisualStudio15CompletionSetFactory.cs" />
<Compile Include="IntelliSense\Completion\Presentation\VisualStudio15CompletionSet.cs" />
<Compile Include="NavigateTo\Dev15NavigateToOptionsService.cs" />
<Compile Include="Structure\BlockContextProvider.cs" />
<Compile Include="Structure\VisualStudio15StructureTaggerProvider.cs" />
</ItemGroup>
......
// 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;
using System.Collections.Generic;
using System.Drawing;
using Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.Language.NavigateTo.Interfaces;
using Microsoft.VisualStudio.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.NavigateTo
{
internal partial class Dev15NavigateToHostVersionService
{
private class Dev15ItemDisplayFactory : INavigateToItemDisplayFactory
{
public INavigateToItemDisplay CreateItemDisplay(NavigateToItem item)
{
var searchResult = (INavigateToSearchResult)item.Tag;
return new Dev15NavigateToItemDisplay(searchResult);
}
}
private class Dev15NavigateToItemDisplay : AbstractNavigateToItemDisplay, INavigateToItemDisplay3
{
public Dev15NavigateToItemDisplay(INavigateToSearchResult searchResult)
: base(searchResult)
{
}
public override Icon Glyph => null;
public ImageMoniker GlyphMoniker => SearchResult.NavigableItem.Glyph.GetImageMoniker();
public IReadOnlyList<Span> GetAdditionalInformationMatchRuns(string searchValue)
=> SpecializedCollections.EmptyReadOnlyList<Span>();
public IReadOnlyList<Span> GetNameMatchRuns(string searchValue)
=> SearchResult.NameMatchSpans.NullToEmpty().SelectAsArray(ts => ts.ToSpan());
}
}
}
\ No newline at end of file
......@@ -5,13 +5,16 @@
namespace Microsoft.CodeAnalysis.Editor.NavigateTo
{
[ExportVersionSpecific(typeof(INavigateToOptionsService), VisualStudioVersion.Dev15)]
internal class Dev15NavigateToOptionsService : INavigateToOptionsService
[ExportVersionSpecific(typeof(INavigateToHostVersionService), VisualStudioVersion.Dev15)]
internal partial class Dev15NavigateToHostVersionService : INavigateToHostVersionService
{
public bool GetSearchCurrentDocument(INavigateToOptions options)
{
var options2 = options as INavigateToOptions2;
return options2?.SearchCurrentDocument ?? false;
}
public INavigateToItemDisplayFactory CreateDisplayFactory()
=> new Dev15ItemDisplayFactory();
}
}
\ No newline at end of file
{
"dependencies": {
"Dev15BinariesForRoslyn": "4.0.0.0",
"Dev15BinariesForRoslyn": "5.0.0.0",
"System.Collections.Immutable": "1.2.0",
"Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime": {
"version": "14.3.25407",
......
......@@ -25,7 +25,7 @@ public abstract class AbstractNavigateToTests
protected static ExportProvider s_exportProvider =
MinimalTestExportProvider.CreateExportProvider(
TestExportProvider.CreateAssemblyCatalogWithCSharpAndVisualBasic().WithPart(
typeof(Dev14NavigateToOptionsService)));
typeof(Dev14NavigateToHostVersionService)));
protected readonly Mock<IGlyphService> _glyphServiceMock = new Mock<IGlyphService>(MockBehavior.Strict);
......@@ -71,7 +71,7 @@ private void InitializeWorkspace(TestWorkspace workspace)
workspace,
_glyphServiceMock.Object,
aggregateListener,
workspace.ExportProvider.GetExportedValues<Lazy<INavigateToOptionsService, VisualStudioVersionMetadata>>());
workspace.ExportProvider.GetExportedValues<Lazy<INavigateToHostVersionService, VisualStudioVersionMetadata>>());
_aggregator = new NavigateToTestAggregator(_provider);
}
......
......@@ -53,7 +53,7 @@ internal abstract partial class AbstractNavigateToSearchService
var patternMatches = patternMatcher.GetMatches(
GetSearchName(declaredSymbolInfo),
declaredSymbolInfo.FullyQualifiedContainerName,
includeMatchSpans: false);
includeMatchSpans: true);
if (!patternMatches.IsEmpty)
{
......@@ -79,8 +79,8 @@ private static string GetSearchName(DeclaredSymbolInfo declaredSymbolInfo)
}
private static INavigateToSearchResult ConvertResult(
bool containsDots, DeclaredSymbolInfo declaredSymbolInfo, Document document,
PatternMatches matches)
bool containsDots, DeclaredSymbolInfo declaredSymbolInfo,
Document document, PatternMatches matches)
{
var matchKind = GetNavigateToMatchKind(containsDots, matches);
......@@ -90,7 +90,9 @@ private static string GetSearchName(DeclaredSymbolInfo declaredSymbolInfo)
var kind = GetItemKind(declaredSymbolInfo);
var navigableItem = NavigableItemFactory.GetItemFromDeclaredSymbolInfo(declaredSymbolInfo, document);
return new SearchResult(document, declaredSymbolInfo, kind, matchKind, isCaseSensitive, navigableItem);
return new SearchResult(
document, declaredSymbolInfo, kind, matchKind,
isCaseSensitive, navigableItem, matches.CandidateMatches.SelectMany(m => m.MatchedSpans).ToImmutableArray());
}
private static string GetItemKind(DeclaredSymbolInfo declaredSymbolInfo)
......
// 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;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.NavigateTo
{
......@@ -22,6 +24,7 @@ private class SearchResult : INavigateToSearchResult
public INavigableItem NavigableItem { get; }
public string SecondarySort { get; }
public bool IsCaseSensitive { get; }
public ImmutableArray<TextSpan> NameMatchSpans { get; }
private readonly Document _document;
private readonly DeclaredSymbolInfo _declaredSymbolInfo;
......@@ -30,7 +33,8 @@ private class SearchResult : INavigateToSearchResult
public SearchResult(
Document document, DeclaredSymbolInfo declaredSymbolInfo, string kind,
NavigateToMatchKind matchKind, bool isCaseSensitive, INavigableItem navigableItem)
NavigateToMatchKind matchKind, bool isCaseSensitive, INavigableItem navigableItem,
ImmutableArray<TextSpan> nameMatchSpans)
{
_document = document;
_declaredSymbolInfo = declaredSymbolInfo;
......@@ -38,6 +42,7 @@ private class SearchResult : INavigateToSearchResult
MatchKind = matchKind;
IsCaseSensitive = isCaseSensitive;
NavigableItem = navigableItem;
NameMatchSpans = nameMatchSpans;
SecondarySort = ConstructSecondarySortString(document, declaredSymbolInfo);
var declaredNavigableItem = navigableItem as NavigableItemFactory.DeclaredSymbolNavigableItem;
......
// 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.Collections.Immutable;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.NavigateTo
{
......@@ -11,9 +13,10 @@ internal interface INavigateToSearchResult
NavigateToMatchKind MatchKind { get; }
bool IsCaseSensitive { get; }
string Name { get; }
ImmutableArray<TextSpan> NameMatchSpans { get; }
string SecondarySort { get; }
string Summary { get; }
INavigableItem NavigableItem { get; }
}
}
}
\ No newline at end of file
......@@ -39,6 +39,7 @@ internal class SerializableNavigateToSearchResult
public NavigateToMatchKind MatchKind;
public bool IsCaseSensitive;
public string Name;
public SerializableTextSpan[] NameMatchSpans;
public string SecondarySort;
public string Summary;
......@@ -53,6 +54,7 @@ internal static SerializableNavigateToSearchResult Dehydrate(INavigateToSearchRe
MatchKind = result.MatchKind,
IsCaseSensitive = result.IsCaseSensitive,
Name = result.Name,
NameMatchSpans = result.NameMatchSpans.Select(SerializableTextSpan.Dehydrate).ToArray(),
SecondarySort = result.SecondarySort,
Summary = result.Summary,
NavigableItem = SerializableNavigableItem.Dehydrate(result.NavigableItem)
......@@ -63,7 +65,8 @@ internal INavigateToSearchResult Rehydrate(Solution solution)
{
return new NavigateToSearchResult(
AdditionalInformation, Kind, MatchKind, IsCaseSensitive,
Name, SecondarySort, Summary, NavigableItem.Rehydrate(solution));
Name, NameMatchSpans.Select(s => s.Rehydrate()).ToImmutableArray(),
SecondarySort, Summary, NavigableItem.Rehydrate(solution));
}
private class NavigateToSearchResult : INavigateToSearchResult
......@@ -73,18 +76,23 @@ private class NavigateToSearchResult : INavigateToSearchResult
public NavigateToMatchKind MatchKind { get; }
public bool IsCaseSensitive { get; }
public string Name { get; }
public ImmutableArray<TextSpan> NameMatchSpans { get; }
public string SecondarySort { get; }
public string Summary { get; }
public INavigableItem NavigableItem { get; }
public NavigateToSearchResult(string additionalInformation, string kind, NavigateToMatchKind matchKind, bool isCaseSensitive, string name, string secondarySort, string summary, INavigableItem navigableItem)
public NavigateToSearchResult(
string additionalInformation, string kind, NavigateToMatchKind matchKind,
bool isCaseSensitive, string name, ImmutableArray<TextSpan> nameMatchSpans,
string secondarySort, string summary, INavigableItem navigableItem)
{
AdditionalInformation = additionalInformation;
Kind = kind;
MatchKind = matchKind;
IsCaseSensitive = isCaseSensitive;
Name = name;
NameMatchSpans = nameMatchSpans;
SecondarySort = secondarySort;
Summary = summary;
NavigableItem = navigableItem;
......
{
"dependencies": {
"Dev15BinariesForRoslyn": "4.0.0.0",
"Dev15BinariesForRoslyn": "5.0.0.0",
"Microsoft.VisualStudio.ImageCatalog": "15.0.25604-Preview4",
"NuGet.VisualStudio": {
"version": "3.3.0",
......
......@@ -3,7 +3,7 @@
"Newtonsoft.Json": "8.0.3",
"Moq": "4.2.1402.2112",
"Microsoft.VisualStudio.Composition": "14.2.19-pre",
"Dev15BinariesForRoslyn": "4.0.0.0",
"Dev15BinariesForRoslyn": "5.0.0.0",
"Microsoft.VisualStudio.Imaging": "15.0.25604-Preview4",
"Microsoft.VisualStudio.Utilities": "15.0.25604-Preview4",
"Microsoft.VisualStudio.ImageCatalog": "15.0.25604-Preview4",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册