Skip to content

Commit

Permalink
Merge pull request #19525 from CyrusNajmabadi/moveDocHighlights
Browse files Browse the repository at this point in the history
Move DocumentHighlights data types down to the 'Features' layer.
  • Loading branch information
CyrusNajmabadi authored May 17, 2017
2 parents 30429b6 + a97af6e commit 3f35adf
Show file tree
Hide file tree
Showing 36 changed files with 401 additions and 139 deletions.
2 changes: 0 additions & 2 deletions src/EditorFeatures/CSharp/CSharpEditorFeatures.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@
<Compile Include="Highlighting\KeywordHighlighters\UnsafeStatementHighlighter.cs" />
<Compile Include="Highlighting\KeywordHighlighters\UsingStatementHighlighter.cs" />
<Compile Include="Highlighting\KeywordHighlighters\YieldStatementHighlighter.cs" />
<Compile Include="HighlightReferences\CSharpDocumentHighlightsService.cs" />
<Compile Include="InlineRename\CSharpEditorInlineRenameService.cs" />
<Compile Include="LanguageServices\CSharpContentTypeLanguageService.cs" />
<Compile Include="LineSeparators\CSharpLineSeparatorService.cs" />
<Compile Include="NavigationBar\CSharpNavigationBarItemService.cs" />
<Compile Include="QuickInfo\SemanticQuickInfoProvider.cs" />
<Compile Include="QuickInfo\SyntacticQuickInfoProvider.cs" />
<Compile Include="ReferenceHighlighting\ReferenceHighlightingAdditionalReferenceProvider.cs" />
<Compile Include="RenameTracking\CSharpRenameTrackingCodeFixProvider.cs" />
<Compile Include="RenameTracking\CSharpRenameTrackingLanguageHeuristicsService.cs" />
<Compile Include="SplitStringLiteral\SplitStringLiteralCommandHandler.cs" />
Expand Down

This file was deleted.

20 changes: 9 additions & 11 deletions src/EditorFeatures/Core/EditorFeatures.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,19 @@
<Compile Include="Implementation\Intellisense\QuickInfo\Providers\LinkedFileDiscrepancyException.cs" />
<Compile Include="Implementation\Intellisense\Completion\CompletionFilterReason.cs" />
<Compile Include="Implementation\Intellisense\Completion\FilterResult.cs" />
<Compile Include="ReferenceHighlighting\IDocumentHighlightsService.cs" />
<Compile Include="Implementation\Structure\BlockTagState.cs" />
<Compile Include="Implementation\Suggestions\ISuggestedActionCallback.cs" />
<Compile Include="Implementation\Suggestions\SuggestedActionSetComparer.cs" />
<Compile Include="Implementation\Suggestions\SuggestedActionsSource.cs" />
<Compile Include="ReferenceHighlighting\NagivateToHighlightReferenceCommandHandler.cs" />
<Compile Include="ReferenceHighlighting\NagivateToHighlightReferenceCommandHandler.StartComparer.cs" />
<Compile Include="ReferenceHighlighting\ReferenceHighlightingViewTaggerProvider.cs" />
<Compile Include="ReferenceHighlighting\Tags\DefinitionHighlightTag.cs" />
<Compile Include="ReferenceHighlighting\Tags\DefinitionHighlightTagDefinition.cs" />
<Compile Include="ReferenceHighlighting\Tags\ReferenceHighlightTag.cs" />
<Compile Include="ReferenceHighlighting\Tags\WrittenReferenceHighlightTag.cs" />
<Compile Include="ReferenceHighlighting\Tags\WrittenReferenceHighlightTagDefinition.cs" />
<Compile Include="Implementation\InfoBar\EditorInfoBarService.cs" />
<Compile Include="SymbolSearch\IAddReferenceDatabaseWrapper.cs" />
<Compile Include="SymbolSearch\IDatabaseFactoryService.cs" />
Expand Down Expand Up @@ -632,8 +641,6 @@
<Compile Include="Implementation\Peek\PeekableItemSource.cs" />
<Compile Include="Implementation\Peek\PeekableItemSourceProvider.cs" />
<Compile Include="Implementation\Peek\PeekHelpers.cs" />
<Compile Include="Implementation\ReferenceHighlighting\WrittenReferenceHighlightTag.cs" />
<Compile Include="Implementation\ReferenceHighlighting\WrittenReferenceHighlightTagDefinition.cs" />
<Compile Include="Implementation\RenameTracking\IRenameTrackingLanguageHeuristicsService.cs" />
<Compile Include="Implementation\RenameTracking\RenameTrackingCancellationCommandHandler.cs" />
<Compile Include="Implementation\RenameTracking\RenameTrackingTagDefinition.cs" />
Expand All @@ -645,15 +652,6 @@
<Compile Include="Implementation\Preview\PreviewConflictViewTaggerProvider.cs" />
<Compile Include="Implementation\Preview\PreviewFactoryService.cs" />
<Compile Include="Implementation\Preview\PreviewWarningViewTaggerProvider.cs" />
<Compile Include="Implementation\ReferenceHighlighting\AbstractDocumentHighlightsService.cs" />
<Compile Include="Implementation\ReferenceHighlighting\DefinitionHighlightTag.cs" />
<Compile Include="Implementation\ReferenceHighlighting\DefinitionHighlightTagDefinition.cs" />
<Compile Include="Implementation\ReferenceHighlighting\IDocumentHighlightsService.cs" />
<Compile Include="Implementation\ReferenceHighlighting\IReferenceHighlightingAdditionalReferenceProvider.cs" />
<Compile Include="Implementation\ReferenceHighlighting\NagivateToHighlightReferenceCommandHandler.cs" />
<Compile Include="Implementation\ReferenceHighlighting\NagivateToHighlightReferenceCommandHandler.StartComparer.cs" />
<Compile Include="Implementation\ReferenceHighlighting\ReferenceHighlightingViewTaggerProvider.cs" />
<Compile Include="Implementation\ReferenceHighlighting\ReferenceHighlightTag.cs" />
<Compile Include="Implementation\RenameTracking\AbstractRenameTrackingCodeFixProvider.cs" />
<Compile Include="Implementation\RenameTracking\RenameTrackingDiagnosticAnalyzer.cs" />
<Compile Include="Implementation\RenameTracking\RenameTrackingTaggerProvider.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;
using Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting;
using Microsoft.CodeAnalysis.Editor.ReferenceHighlighting;

namespace Microsoft.CodeAnalysis.Editor.Implementation.Preview
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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.Collections.Generic;
using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -41,9 +41,13 @@ public DocumentHighlights(Document document, ImmutableArray<HighlightSpan> highl
}
}

/// <summary>
/// Note: kept around for back compat until F# and TypeScript move over to
/// <see cref="Microsoft.CodeAnalysis.DocumentHighlighting.IDocumentHighlightsService"/>.
/// </summary>
internal interface IDocumentHighlightsService : ILanguageService
{
Task<ImmutableArray<DocumentHighlights>> GetDocumentHighlightsAsync(
Document document, int position, IImmutableSet<Document> documentsToSearch, CancellationToken cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.Text;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
namespace Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
{
internal partial class NavigateToHighlightReferenceCommandHandler
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using Microsoft.VisualStudio.Text.Tagging;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
namespace Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
{
[ExportCommandHandler(PredefinedCommandHandlerNames.NavigateToHighlightedReference,
ContentTypeNames.RoslynContentType)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.DocumentHighlighting;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
Expand All @@ -21,7 +25,7 @@
using Microsoft.VisualStudio.Utilities;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
namespace Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
{
[Export(typeof(IViewTaggerProvider))]
[ContentType(ContentTypeNames.RoslynContentType)]
Expand Down Expand Up @@ -110,13 +114,12 @@ protected override Task ProduceTagsAsync(TaggerContext<NavigableHighlightTag> co
}

// Otherwise, we need to go produce all tags.
return ProduceTagsAsync(context, caretPosition, workspace, document);
return ProduceTagsAsync(context, caretPosition, document);
}

internal async Task ProduceTagsAsync(
TaggerContext<NavigableHighlightTag> context,
SnapshotPoint position,
Workspace workspace,
Document document)
{
var cancellationToken = context.CancellationToken;
Expand All @@ -127,25 +130,73 @@ internal async Task ProduceTagsAsync(
{
if (document != null)
{
var documentHighlightsService = document.Project.LanguageServices.GetService<IDocumentHighlightsService>();
if (documentHighlightsService != null)
// As we transition to the new API (defined at the Features layer) we support
// calling into both it and the old API (defined at the EditorFeatures layer).
//
// Once TypeScript and F# can move over, then we can remove the calls to the old
// API.
await TryNewServiceAsync(context, position, document).ConfigureAwait(false);
await TryOldServiceAsync(context, position, document).ConfigureAwait(false);
}
}
}

private Task TryOldServiceAsync(TaggerContext<NavigableHighlightTag> context, SnapshotPoint position, Document document)
{
return TryServiceAsync<IDocumentHighlightsService>(
context, position, document,
(s, d, p, ds, c) => s.GetDocumentHighlightsAsync(d, p, ds, c));
}

private Task TryNewServiceAsync(
TaggerContext<NavigableHighlightTag> context, SnapshotPoint position, Document document)
{
return TryServiceAsync<DocumentHighlighting.IDocumentHighlightsService>(
context, position, document,
async (service, doc, point, documents, cancellation) =>
{
// Call into the new service.
var newHighlights = await service.GetDocumentHighlightsAsync(doc, point, documents, cancellation).ConfigureAwait(false);

// then convert the result to the form the old service would return.
return ConvertHighlights(newHighlights);
});
}

private async Task TryServiceAsync<T>(
TaggerContext<NavigableHighlightTag> context, SnapshotPoint position, Document document,
Func<T, Document, SnapshotPoint, ImmutableHashSet<Document>, CancellationToken, Task<ImmutableArray<DocumentHighlights>>> getDocumentHighlightsAsync)
where T : class, ILanguageService
{
var cancellationToken = context.CancellationToken;
var documentHighlightsService = document.GetLanguageService<T>();
if (documentHighlightsService != null)
{
// We only want to search inside documents that correspond to the snapshots
// we're looking at
var documentsToSearch = ImmutableHashSet.CreateRange(context.SpansToTag.Select(vt => vt.Document).WhereNotNull());
var documentHighlightsList = await getDocumentHighlightsAsync(
documentHighlightsService, document, position, documentsToSearch, cancellationToken).ConfigureAwait(false);
if (documentHighlightsList != null)
{
foreach (var documentHighlights in documentHighlightsList)
{
// We only want to search inside documents that correspond to the snapshots
// we're looking at
var documentsToSearch = ImmutableHashSet.CreateRange(context.SpansToTag.Select(vt => vt.Document).WhereNotNull());
var documentHighlightsList = await documentHighlightsService.GetDocumentHighlightsAsync(document, position, documentsToSearch, cancellationToken).ConfigureAwait(false);
if (documentHighlightsList != null)
{
foreach (var documentHighlights in documentHighlightsList)
{
await AddTagSpansAsync(context, solution, documentHighlights).ConfigureAwait(false);
}
}
await AddTagSpansAsync(
context, document.Project.Solution, documentHighlights).ConfigureAwait(false);
}
}
}
}

private ImmutableArray<DocumentHighlights> ConvertHighlights(ImmutableArray<DocumentHighlighting.DocumentHighlights> newHighlights)
=> newHighlights.SelectAsArray(
documentHighlights => new DocumentHighlights(
documentHighlights.Document,
documentHighlights.HighlightSpans.SelectAsArray(
highlightSpan => new HighlightSpan(
highlightSpan.TextSpan,
(HighlightSpanKind)highlightSpan.Kind))));

private async Task AddTagSpansAsync(
TaggerContext<NavigableHighlightTag> context,
Solution solution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Microsoft.CodeAnalysis.Editor.Shared.Tagging;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
namespace Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
{
internal class DefinitionHighlightTag : NavigableHighlightTag
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
namespace Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
{
[Export(typeof(EditorFormatDefinition))]
[Name(DefinitionHighlightTag.TagId)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Microsoft.CodeAnalysis.Editor.Shared.Tagging;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
namespace Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
{
internal class ReferenceHighlightTag : NavigableHighlightTag
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Microsoft.CodeAnalysis.Editor.Shared.Tagging;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
namespace Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
{
internal class WrittenReferenceHighlightTag : NavigableHighlightTag
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
namespace Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
{
[Export(typeof(EditorFormatDefinition))]
[Name(WrittenReferenceHighlightTag.TagId)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
' 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
Imports Microsoft.CodeAnalysis.Editor.Implementation.ReferenceHighlighting
Imports Microsoft.CodeAnalysis.DocumentHighlighting
Imports Microsoft.CodeAnalysis.Editor.ReferenceHighlighting
Imports Microsoft.CodeAnalysis.Editor.Shared.Extensions
Imports Microsoft.CodeAnalysis.Editor.Shared.Options
Imports Microsoft.CodeAnalysis.Editor.Shared.Tagging
Expand All @@ -16,9 +17,17 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.ReferenceHighlighting

Public MustInherit Class AbstractReferenceHighlightingTests
Protected Async Function VerifyHighlightsAsync(test As XElement, Optional optionIsEnabled As Boolean = True) As Tasks.Task
Await VerifyHighlightsAsync(test, optionIsEnabled, outOfProcess:=False)
Await VerifyHighlightsAsync(test, optionIsEnabled, outOfProcess:=True)
End Function

Private Async Function VerifyHighlightsAsync(test As XElement, optionIsEnabled As Boolean, outOfProcess As Boolean) As Tasks.Task
Using workspace = TestWorkspace.Create(test)
WpfTestCase.RequireWpfFact($"{NameOf(AbstractReferenceHighlightingTests)}.VerifyHighlightsAsync creates asynchronous taggers")

workspace.Options = workspace.Options.WithChangedOption(
DocumentHighlightingOptions.OutOfProcessAllowed, outOfProcess)

Dim tagProducer = New ReferenceHighlightingViewTaggerProvider(
workspace.GetService(Of IForegroundNotificationService),
workspace.GetService(Of ISemanticChangeNotificationService),
Expand Down
2 changes: 0 additions & 2 deletions src/EditorFeatures/VisualBasic/BasicEditorFeatures.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
<Compile Include="Highlighting\KeywordHighlighters\XmlEmbeddedExpressionHighlighter.vb" />
<Compile Include="Highlighting\KeywordHighlighters\XmlProcessingInstructionHighlighter.vb" />
<Compile Include="Highlighting\KeywordHighlightingHelpers.vb" />
<Compile Include="HighlightReferences\VisualBasicDocumentHighlightsService.vb" />
<Compile Include="ImplementAbstractClass\ImplementAbstractClassCommandHandler.vb" />
<Compile Include="ImplementInterface\ImplementInterfaceCommandHandler.vb" />
<Compile Include="InlineRename\VisualBasicEditorInlineRenameService.vb" />
Expand All @@ -155,7 +154,6 @@
<Compile Include="NavigationBar\GenerateMethodItem.vb" />
<Compile Include="NavigationBar\VisualBasicNavigationBarItemService.vb" />
<Compile Include="QuickInfo\SemanticQuickInfoProvider.vb" />
<Compile Include="ReferenceHighlighting\ReferenceHighlightingAdditionalReferenceProvider.vb" />
<Compile Include="RenameTracking\BasicRenameTrackingLanguageHeuristicsService.vb" />
<Compile Include="RenameTracking\RenameTrackingCodeFixProvider.vb" />
<Compile Include="TextStructureNavigation\TextStructureNavigatorProvider.vb" />
Expand Down
Loading

0 comments on commit 3f35adf

Please sign in to comment.