未验证 提交 b980a389 编写于 作者: H Heejae Chang 提交者: GitHub

first work to remove IEditorClassificationService (#31734)

* removed IEditorClassificationService that is marked obsolete since 2017 and bunch of other code that only existed for the IEditorClassificationService.

according to vso, only F# still has dependency so I talked to them to move to new API (IClassificationService) - https://devdiv.visualstudio.com/DevDiv/_git/DotNet-Source-Build-Tarball?path=%2Fsrc%2Ffsharp%2Fvsintegration%2Fsrc%2FFSharp.Editor%2FClassification%2FColorizationService.fs&version=GBmaster

and a bunch of clean up and move code that has no dependency to the editor to lower layers so that I can consume in razor scenario.

* added shim project for FSharp that has internal visible to FSharp editor

* merged https://github.com/dotnet/roslyn/pull/31941

* addressing PR feedback

* moved some type (such as DocumentSpan, ClassifiedSpan and etc) back to where fsharp has IVT to.

can't move those since partner team is using them and they don't have IVT to workspace layer for some reasons.

also, have put the IEditorClassificationService back and add a proxy in FSharp External Access so that it can still work until they remove all IVT.
上级 fe1368e3
......@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.FindUsages;
......
......@@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Features.RQName;
using Microsoft.CodeAnalysis.FindSymbols;
......
......@@ -53,59 +53,4 @@ internal interface IEditorClassificationService : ILanguageService
/// </summary>
ClassifiedSpan AdjustStaleClassification(SourceText text, ClassifiedSpan classifiedSpan);
}
/// <summary>
/// Exists to bridge between <see cref="IEditorClassificationService"/> and <see cref="IClassificationService"/>
/// </summary>
internal interface IClassificationDelegationService<TClassificationService>
{
void AddLexicalClassifications(TClassificationService service, SourceText text, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken);
Task AddSyntacticClassificationsAsync(TClassificationService service, Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken);
Task AddSemanticClassificationsAsync(TClassificationService service, Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken);
ClassifiedSpan AdjustStaleClassification(TClassificationService service, SourceText text, ClassifiedSpan classifiedSpan);
}
internal class WorkspaceClassificationDelegationService : IClassificationDelegationService<IClassificationService>
{
public static readonly IClassificationDelegationService<IClassificationService> Instance = new WorkspaceClassificationDelegationService();
private WorkspaceClassificationDelegationService()
{
}
public void AddLexicalClassifications(IClassificationService service, SourceText text, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
=> service.AddLexicalClassifications(text, textSpan, result, cancellationToken);
public Task AddSyntacticClassificationsAsync(IClassificationService service, Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
=> service.AddSyntacticClassificationsAsync(document, textSpan, result, cancellationToken);
public Task AddSemanticClassificationsAsync(IClassificationService service, Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
=> service.AddSemanticClassificationsAsync(document, textSpan, result, cancellationToken);
public ClassifiedSpan AdjustStaleClassification(IClassificationService service, SourceText text, ClassifiedSpan classifiedSpan)
=> service.AdjustStaleClassification(text, classifiedSpan);
}
#pragma warning disable CS0618 // Type or member is obsolete
internal class EditorClassificationDelegationService : IClassificationDelegationService<IEditorClassificationService>
{
public static readonly IClassificationDelegationService<IEditorClassificationService> Instance = new EditorClassificationDelegationService();
private EditorClassificationDelegationService()
{
}
public void AddLexicalClassifications(IEditorClassificationService service, SourceText text, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
=> service.AddLexicalClassifications(text, textSpan, result, cancellationToken);
public Task AddSyntacticClassificationsAsync(IEditorClassificationService service, Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
=> service.AddSyntacticClassificationsAsync(document, textSpan, result, cancellationToken);
public Task AddSemanticClassificationsAsync(IEditorClassificationService service, Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
=> service.AddSemanticClassificationsAsync(document, textSpan, result, cancellationToken);
public ClassifiedSpan AdjustStaleClassification(IEditorClassificationService service, SourceText text, ClassifiedSpan classifiedSpan)
=> service.AdjustStaleClassification(text, classifiedSpan);
}
#pragma warning restore CS0612 // Type or member is obsolete
}
......@@ -6,10 +6,10 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
......@@ -167,25 +167,13 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetAllTags(NormalizedSnapshotSp
}
private Task ProduceTagsAsync(TaggerContext<IClassificationTag> context, DocumentSnapshotSpan documentSpan, ClassificationTypeMap typeMap)
{
return Task.WhenAll(
ProduceTagsAsync(context, documentSpan, typeMap, WorkspaceClassificationDelegationService.Instance),
ProduceTagsAsync(context, documentSpan, typeMap, EditorClassificationDelegationService.Instance));
}
private Task ProduceTagsAsync<TClassificationService>(
TaggerContext<IClassificationTag> context,
DocumentSnapshotSpan documentSpan,
ClassificationTypeMap typeMap,
IClassificationDelegationService<TClassificationService> delegationService) where TClassificationService : class, ILanguageService
{
var document = documentSpan.Document;
var classificationService = document.GetLanguageService<TClassificationService>();
var classificationService = document.GetLanguageService<IClassificationService>();
if (classificationService != null)
{
return SemanticClassificationUtilities.ProduceTagsAsync(
context, documentSpan, delegationService, classificationService, typeMap);
return SemanticClassificationUtilities.ProduceTagsAsync(context, documentSpan, classificationService, typeMap);
}
return Task.CompletedTask;
......
......@@ -2,11 +2,11 @@
using System;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -20,11 +20,10 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Classification
{
internal static class SemanticClassificationUtilities
{
public static async Task ProduceTagsAsync<TClassificationService>(
public static async Task ProduceTagsAsync(
TaggerContext<IClassificationTag> context,
DocumentSnapshotSpan spanToTag,
IClassificationDelegationService<TClassificationService> delegationService,
TClassificationService classificationService,
IClassificationService classificationService,
ClassificationTypeMap typeMap)
{
var document = spanToTag.Document;
......@@ -34,7 +33,7 @@ internal static class SemanticClassificationUtilities
}
var classified = await TryClassifyContainingMemberSpan(
context, spanToTag, delegationService, classificationService, typeMap).ConfigureAwait(false);
context, spanToTag, classificationService, typeMap).ConfigureAwait(false);
if (classified)
{
return;
......@@ -43,14 +42,13 @@ internal static class SemanticClassificationUtilities
// We weren't able to use our specialized codepaths for semantic classifying.
// Fall back to classifying the full span that was asked for.
await ClassifySpansAsync(
context, spanToTag, delegationService, classificationService, typeMap).ConfigureAwait(false);
context, spanToTag, classificationService, typeMap).ConfigureAwait(false);
}
private static async Task<bool> TryClassifyContainingMemberSpan<TClassificationService>(
private static async Task<bool> TryClassifyContainingMemberSpan(
TaggerContext<IClassificationTag> context,
DocumentSnapshotSpan spanToTag,
IClassificationDelegationService<TClassificationService> delegationService,
TClassificationService classificationService,
IClassificationService classificationService,
ClassificationTypeMap typeMap)
{
var range = context.TextChangeRange;
......@@ -110,15 +108,14 @@ internal static class SemanticClassificationUtilities
// re-classify only the member we're inside.
await ClassifySpansAsync(
context, subSpanToTag, delegationService, classificationService, typeMap).ConfigureAwait(false);
context, subSpanToTag, classificationService, typeMap).ConfigureAwait(false);
return true;
}
private static async Task ClassifySpansAsync<TClassificationService>(
private static async Task ClassifySpansAsync(
TaggerContext<IClassificationTag> context,
DocumentSnapshotSpan spanToTag,
IClassificationDelegationService<TClassificationService> delegationService,
TClassificationService classificationService,
IClassificationService classificationService,
ClassificationTypeMap typeMap)
{
try
......@@ -132,8 +129,8 @@ internal static class SemanticClassificationUtilities
{
var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList();
await delegationService.AddSemanticClassificationsAsync(
classificationService, document, snapshotSpan.Span.ToTextSpan(), classifiedSpans, cancellationToken: cancellationToken).ConfigureAwait(false);
await classificationService.AddSemanticClassificationsAsync(
document, snapshotSpan.Span.ToTextSpan(), classifiedSpans, cancellationToken: cancellationToken).ConfigureAwait(false);
ClassificationUtilities.Convert(typeMap, snapshotSpan.Snapshot, classifiedSpans, context.AddTag);
ClassificationUtilities.ReturnClassifiedSpanList(classifiedSpans);
......
......@@ -5,12 +5,12 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -92,31 +92,18 @@ protected override Task ProduceTagsAsync(TaggerContext<IClassificationTag> conte
var spanToTag = context.SpansToTag.Single();
var task1 = ProduceTagsAsync(context, spanToTag, WorkspaceClassificationDelegationService.Instance);
var task2 = ProduceTagsAsync(context, spanToTag, EditorClassificationDelegationService.Instance);
return Task.WhenAll(task1, task2);
}
private Task ProduceTagsAsync<TClassificationService>(
TaggerContext<IClassificationTag> context,
DocumentSnapshotSpan spanToTag,
IClassificationDelegationService<TClassificationService> delegationService)
where TClassificationService : class, ILanguageService
{
var document = spanToTag.Document;
// Attempt to get a classification service which will actually produce the results.
// If we can't (because we have no Document, or because the language doesn't support
// this service), then bail out immediately.
var classificationService = document?.GetLanguageService<TClassificationService>();
var classificationService = document?.GetLanguageService<IClassificationService>();
if (classificationService == null)
{
return Task.CompletedTask;
}
return SemanticClassificationUtilities.ProduceTagsAsync(
context, spanToTag, delegationService, classificationService, _typeMap);
return SemanticClassificationUtilities.ProduceTagsAsync(context, spanToTag, classificationService, _typeMap);
}
}
}
......@@ -246,8 +246,7 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
var languageServices = _workspace.Services.GetLanguageServices(firstSpan.Snapshot.ContentType);
if (languageServices != null)
{
var result = GetTags(spans, languageServices, WorkspaceClassificationDelegationService.Instance) ??
GetTags(spans, languageServices, EditorClassificationDelegationService.Instance);
var result = GetTags(spans, languageServices);
if (result != null)
{
return result;
......@@ -259,13 +258,10 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
}
}
private IEnumerable<ITagSpan<IClassificationTag>> GetTags<TClassificationService>(
NormalizedSnapshotSpanCollection spans,
HostLanguageServices languageServices,
IClassificationDelegationService<TClassificationService> delegationService) where TClassificationService : class, ILanguageService
private IEnumerable<ITagSpan<IClassificationTag>> GetTags(
NormalizedSnapshotSpanCollection spans, HostLanguageServices languageServices)
{
var classificationService = languageServices.GetService<TClassificationService>();
var classificationService = languageServices.GetService<IClassificationService>();
if (classificationService == null)
{
return null;
......@@ -275,16 +271,15 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
foreach (var span in spans)
{
AddClassifiedSpans(delegationService, classificationService, span, classifiedSpans);
AddClassifiedSpans(classificationService, span, classifiedSpans);
}
return ClassificationUtilities.ConvertAndReturnList(
_typeMap, spans[0].Snapshot, classifiedSpans);
}
private void AddClassifiedSpans<TClassificationService>(
IClassificationDelegationService<TClassificationService> delegationService,
TClassificationService classificationService,
private void AddClassifiedSpans(
IClassificationService classificationService,
SnapshotSpan span,
List<ClassifiedSpan> classifiedSpans)
{
......@@ -302,7 +297,7 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
if (lastDocument == null)
{
// We don't have a syntax tree yet. Just do a lexical classification of the document.
AddClassifiedSpansForTokens(delegationService, classificationService, span, classifiedSpans);
AddClassifiedSpansForTokens(classificationService, span, classifiedSpans);
return;
}
......@@ -313,20 +308,19 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
if (lastSnapshot.Version.ReiteratedVersionNumber == span.Snapshot.Version.ReiteratedVersionNumber)
{
AddClassifiedSpansForCurrentTree(
delegationService, classificationService, span, lastDocument, classifiedSpans);
classificationService, span, lastDocument, classifiedSpans);
}
else
{
// Slightly more complicated. We have a parse tree, it's just not for the snapshot
// we're being asked for.
AddClassifiedSpansForPreviousTree(
delegationService, classificationService, span, lastSnapshot, lastDocument, classifiedSpans);
classificationService, span, lastSnapshot, lastDocument, classifiedSpans);
}
}
private void AddClassifiedSpansForCurrentTree<TClassificationService>(
IClassificationDelegationService<TClassificationService> delegationService,
TClassificationService classificationService,
private void AddClassifiedSpansForCurrentTree(
IClassificationService classificationService,
SnapshotSpan span,
Document document,
List<ClassifiedSpan> classifiedSpans)
......@@ -335,8 +329,8 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
{
tempList = ClassificationUtilities.GetOrCreateClassifiedSpanList();
delegationService.AddSyntacticClassificationsAsync(
classificationService, document, span.Span.ToTextSpan(), tempList, CancellationToken.None).Wait(CancellationToken.None);
classificationService.AddSyntacticClassificationsAsync(
document, span.Span.ToTextSpan(), tempList, CancellationToken.None).Wait(CancellationToken.None);
_lastLineCache.Update(span, tempList);
}
......@@ -347,9 +341,8 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
classifiedSpans.AddRange(tempList);
}
private void AddClassifiedSpansForPreviousTree<TClassificationService>(
IClassificationDelegationService<TClassificationService> delegationService,
TClassificationService classificationService,
private void AddClassifiedSpansForPreviousTree(
IClassificationService classificationService,
SnapshotSpan span,
ITextSnapshot lastSnapshot,
Document lastDocument,
......@@ -389,13 +382,13 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
{
// well, there is no information we can get from previous tree, use lexer to
// classify given span. soon we will re-classify the region.
AddClassifiedSpansForTokens(delegationService, classificationService, span, classifiedSpans);
AddClassifiedSpansForTokens(classificationService, span, classifiedSpans);
return;
}
var tempList = ClassificationUtilities.GetOrCreateClassifiedSpanList();
AddClassifiedSpansForCurrentTree(
delegationService, classificationService, translatedSpan, lastDocument, tempList);
classificationService, translatedSpan, lastDocument, tempList);
var currentSnapshot = span.Snapshot;
var currentText = currentSnapshot.AsText();
......@@ -411,8 +404,7 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
// 3) The classifications may be incorrect due to changes in the text. For example,
// if "clss" becomes "class", then we want to changes the classification from
// 'identifier' to 'keyword'.
currentClassifiedSpan = delegationService.AdjustStaleClassification(
classificationService, currentText, currentClassifiedSpan);
currentClassifiedSpan = classificationService.AdjustStaleClassification(currentText, currentClassifiedSpan);
classifiedSpans.Add(currentClassifiedSpan);
}
......@@ -420,14 +412,13 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
ClassificationUtilities.ReturnClassifiedSpanList(tempList);
}
private void AddClassifiedSpansForTokens<TClassificationService>(
IClassificationDelegationService<TClassificationService> delegationService,
TClassificationService classificationService,
private void AddClassifiedSpansForTokens(
IClassificationService classificationService,
SnapshotSpan span,
List<ClassifiedSpan> classifiedSpans)
{
delegationService.AddLexicalClassifications(
classificationService, span.Snapshot.AsText(), span.Span.ToTextSpan(), classifiedSpans, CancellationToken.None);
classificationService.AddLexicalClassifications(
span.Snapshot.AsText(), span.Span.ToTextSpan(), classifiedSpans, CancellationToken.None);
}
private void OnDocumentActiveContextChanged(object sender, DocumentActiveContextChangedEventArgs args)
......
......@@ -100,7 +100,7 @@ internal static class IntellisenseQuickInfoBuilder
var classifiedSpanList = new List<ClassifiedSpan>();
foreach (var span in quickInfoItem.RelatedSpans)
{
var classifiedSpans = await EditorClassifier.GetClassifiedSpansAsync(document, span, cancellationToken).ConfigureAwait(false);
var classifiedSpans = await ClassifierHelper.GetClassifiedSpansAsync(document, span, cancellationToken).ConfigureAwait(false);
classifiedSpanList.AddRange(classifiedSpans);
}
......
......@@ -13,7 +13,7 @@
<PackageId>Microsoft.CodeAnalysis.EditorFeatures.Common</PackageId>
<IsPackable>true</IsPackable>
<PackageDescription>
.NET Compiler Platform ("Roslyn") support for editor features inside the Visual Studio editor.
.NET Compiler Platform ("Roslyn") support for editor features inside the Visual Studio editor.
</PackageDescription>
</PropertyGroup>
<ItemGroup Label="Project References">
......@@ -53,6 +53,7 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Remote.ServiceHub" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Editor.UI.Wpf" />
<InternalsVisibleTo Include="Roslyn.Hosting.Diagnostics" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.FSharp" />
<!-- BEGIN MONODEVELOP
These MonoDevelop dependencies don't ship with Visual Studio, so can't break our
binary insertions and are exempted from the ExternalAccess adapter assembly policies.
......
......@@ -114,24 +114,23 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Classification
End Function
#Disable Warning BC40000 ' Type or member is obsolete
<ExportLanguageService(GetType(IEditorClassificationService), "NoCompilation"), [Shared]>
<ExportLanguageService(GetType(IClassificationService), "NoCompilation"), [Shared]>
Private Class NoCompilationEditorClassificationService
Implements IEditorClassificationService
Implements IClassificationService
Public Sub AddLexicalClassifications(text As SourceText, textSpan As TextSpan, result As List(Of ClassifiedSpan), cancellationToken As CancellationToken) Implements IEditorClassificationService.AddLexicalClassifications
Public Sub AddLexicalClassifications(text As SourceText, textSpan As TextSpan, result As List(Of ClassifiedSpan), cancellationToken As CancellationToken) Implements IClassificationService.AddLexicalClassifications
End Sub
Public Function AddSemanticClassificationsAsync(document As Document, textSpan As TextSpan, result As List(Of ClassifiedSpan), cancellationToken As CancellationToken) As Task Implements IEditorClassificationService.AddSemanticClassificationsAsync
Public Function AddSemanticClassificationsAsync(document As Document, textSpan As TextSpan, result As List(Of ClassifiedSpan), cancellationToken As CancellationToken) As Task Implements IClassificationService.AddSemanticClassificationsAsync
Return Task.CompletedTask
End Function
Public Function AddSyntacticClassificationsAsync(document As Document, textSpan As TextSpan, result As List(Of ClassifiedSpan), cancellationToken As CancellationToken) As Task Implements IEditorClassificationService.AddSyntacticClassificationsAsync
Public Function AddSyntacticClassificationsAsync(document As Document, textSpan As TextSpan, result As List(Of ClassifiedSpan), cancellationToken As CancellationToken) As Task Implements IClassificationService.AddSyntacticClassificationsAsync
Return Task.CompletedTask
End Function
Public Function AdjustStaleClassification(text As SourceText, classifiedSpan As ClassifiedSpan) As ClassifiedSpan Implements IEditorClassificationService.AdjustStaleClassification
Public Function AdjustStaleClassification(text As SourceText, classifiedSpan As ClassifiedSpan) As ClassifiedSpan Implements IClassificationService.AdjustStaleClassification
End Function
End Class
#Enable Warning BC40008 ' Type or member is obsolete
End Class
End Namespace
// 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.Classification;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.FindUsages
namespace Microsoft.CodeAnalysis.Classification
{
internal struct ClassifiedSpansAndHighlightSpan
{
......
......@@ -3,13 +3,10 @@
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
namespace Microsoft.CodeAnalysis.Editor.FindUsages
namespace Microsoft.CodeAnalysis.Classification
{
internal static class ClassifiedSpansAndHighlightSpanFactory
{
......@@ -77,7 +74,7 @@ private static TextSpan GetLineSpanForReference(SourceText sourceText, TextSpan
private static async Task<ImmutableArray<ClassifiedSpan>> GetClassifiedSpansAsync(
Document document, TextSpan narrowSpan, TextSpan widenedSpan, CancellationToken cancellationToken)
{
var result = await EditorClassifier.GetClassifiedSpansAsync(
var result = await ClassifierHelper.GetClassifiedSpansAsync(
document, widenedSpan, cancellationToken).ConfigureAwait(false);
if (!result.IsDefault)
{
......
......@@ -22,44 +22,44 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Features\Core\Portable\Microsoft.CodeAnalysis.Features.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Features\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Features.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Features\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Features.vbproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\EditorFeatures\Core\Microsoft.CodeAnalysis.EditorFeatures.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\EditorFeatures\Core.Wpf\Microsoft.CodeAnalysis.EditorFeatures.Wpf.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\EditorFeatures\Text\Microsoft.CodeAnalysis.EditorFeatures.Text.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\EditorFeatures\CSharp\Microsoft.CodeAnalysis.CSharp.EditorFeatures.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\EditorFeatures\VisualBasic\Microsoft.CodeAnalysis.VisualBasic.EditorFeatures.vbproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Tools\ExternalAccess\Debugger\Microsoft.CodeAnalysis.ExternalAccess.Debugger.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Workspaces\Core\Desktop\Microsoft.CodeAnalysis.Workspaces.Desktop.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Workspaces\Core\MSBuild\Microsoft.CodeAnalysis.Workspaces.MSBuild.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Workspaces\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Workspaces.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Workspaces\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Workspaces\Remote\Core\Microsoft.CodeAnalysis.Remote.Workspaces.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Workspaces\Remote\Razor\Microsoft.CodeAnalysis.Remote.Razor.ServiceHub.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Workspaces\Remote\ServiceHub\Microsoft.CodeAnalysis.Remote.ServiceHub.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\VisualStudio\Core\Def\Microsoft.VisualStudio.LanguageServices.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\VisualStudio\Core\Impl\Microsoft.VisualStudio.LanguageServices.Implementation.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\VisualStudio\Core\SolutionExplorerShim\Microsoft.VisualStudio.LanguageServices.SolutionExplorer.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\VisualStudio\Core\SolutionExplorerShim\Microsoft.VisualStudio.LanguageServices.SolutionExplorer.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\VisualStudio\CSharp\Impl\Microsoft.VisualStudio.LanguageServices.CSharp.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\VisualStudio\VisualBasic\Impl\Microsoft.VisualStudio.LanguageServices.VisualBasic.vbproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\VisualStudio\Xaml\Impl\Microsoft.VisualStudio.LanguageServices.Xaml.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\VisualStudio\Razor\Microsoft.VisualStudio.LanguageServices.Razor.RemoteClient.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\Core\Source\ExpressionCompiler\Microsoft.CodeAnalysis.ExpressionCompiler.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\CSharp\Source\ExpressionCompiler\Microsoft.CodeAnalysis.CSharp.ExpressionCompiler.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\VisualBasic\Source\ExpressionCompiler\Microsoft.CodeAnalysis.VisualBasic.ExpressionCompiler.vbproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\Core\Source\FunctionResolver\Microsoft.CodeAnalysis.FunctionResolver.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\Core\Source\ResultProvider\Portable\Microsoft.CodeAnalysis.ResultProvider.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\Core\Source\ResultProvider\NetFX20\ResultProvider.NetFX20.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\CSharp\Source\ResultProvider\Portable\Microsoft.CodeAnalysis.CSharp.ResultProvider.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\CSharp\Source\ResultProvider\NetFX20\CSharpResultProvider.NetFX20.csproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\VisualBasic\Source\ResultProvider\Portable\Microsoft.CodeAnalysis.VisualBasic.ResultProvider.vbproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\ExpressionEvaluator\VisualBasic\Source\ResultProvider\NetFX20\BasicResultProvider.NetFX20.vbproj" PrivateAssets="all"/>
<ProjectReference Include="..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Features\Core\Portable\Microsoft.CodeAnalysis.Features.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Features\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Features.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Features\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Features.vbproj" PrivateAssets="all" />
<ProjectReference Include="..\..\EditorFeatures\Core\Microsoft.CodeAnalysis.EditorFeatures.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\EditorFeatures\Core.Wpf\Microsoft.CodeAnalysis.EditorFeatures.Wpf.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\EditorFeatures\Text\Microsoft.CodeAnalysis.EditorFeatures.Text.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\EditorFeatures\CSharp\Microsoft.CodeAnalysis.CSharp.EditorFeatures.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\EditorFeatures\VisualBasic\Microsoft.CodeAnalysis.VisualBasic.EditorFeatures.vbproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Tools\ExternalAccess\FSharp\Microsoft.CodeAnalysis.ExternalAccess.FSharp.csproj" />
<ProjectReference Include="..\..\Tools\ExternalAccess\Debugger\Microsoft.CodeAnalysis.ExternalAccess.Debugger.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Workspaces\Core\Desktop\Microsoft.CodeAnalysis.Workspaces.Desktop.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Workspaces\Core\MSBuild\Microsoft.CodeAnalysis.Workspaces.MSBuild.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Workspaces\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Workspaces.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Workspaces\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Workspaces\Remote\Core\Microsoft.CodeAnalysis.Remote.Workspaces.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Workspaces\Remote\Razor\Microsoft.CodeAnalysis.Remote.Razor.ServiceHub.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Workspaces\Remote\ServiceHub\Microsoft.CodeAnalysis.Remote.ServiceHub.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\VisualStudio\Core\Def\Microsoft.VisualStudio.LanguageServices.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\VisualStudio\Core\Impl\Microsoft.VisualStudio.LanguageServices.Implementation.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\VisualStudio\Core\SolutionExplorerShim\Microsoft.VisualStudio.LanguageServices.SolutionExplorer.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\VisualStudio\CSharp\Impl\Microsoft.VisualStudio.LanguageServices.CSharp.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\VisualStudio\VisualBasic\Impl\Microsoft.VisualStudio.LanguageServices.VisualBasic.vbproj" PrivateAssets="all" />
<ProjectReference Include="..\..\VisualStudio\Xaml\Impl\Microsoft.VisualStudio.LanguageServices.Xaml.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\VisualStudio\Razor\Microsoft.VisualStudio.LanguageServices.Razor.RemoteClient.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\Core\Source\ExpressionCompiler\Microsoft.CodeAnalysis.ExpressionCompiler.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\CSharp\Source\ExpressionCompiler\Microsoft.CodeAnalysis.CSharp.ExpressionCompiler.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\VisualBasic\Source\ExpressionCompiler\Microsoft.CodeAnalysis.VisualBasic.ExpressionCompiler.vbproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\Core\Source\FunctionResolver\Microsoft.CodeAnalysis.FunctionResolver.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\Core\Source\ResultProvider\Portable\Microsoft.CodeAnalysis.ResultProvider.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\Core\Source\ResultProvider\NetFX20\ResultProvider.NetFX20.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\CSharp\Source\ResultProvider\Portable\Microsoft.CodeAnalysis.CSharp.ResultProvider.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\CSharp\Source\ResultProvider\NetFX20\CSharpResultProvider.NetFX20.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\VisualBasic\Source\ResultProvider\Portable\Microsoft.CodeAnalysis.VisualBasic.ResultProvider.vbproj" PrivateAssets="all" />
<ProjectReference Include="..\..\ExpressionEvaluator\VisualBasic\Source\ResultProvider\NetFX20\BasicResultProvider.NetFX20.vbproj" PrivateAssets="all" />
</ItemGroup>
<Target Name="_GetFilesToPackage">
......@@ -87,6 +87,7 @@
<_File Include="$(ArtifactsBinDir)Microsoft.VisualStudio.LanguageServices.CSharp\$(Configuration)\net472\Microsoft.VisualStudio.LanguageServices.CSharp.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.VisualStudio.LanguageServices.Implementation\$(Configuration)\net472\Microsoft.VisualStudio.LanguageServices.Implementation.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.VisualStudio.LanguageServices.Razor.RemoteClient\$(Configuration)\net472\Microsoft.VisualStudio.LanguageServices.Razor.RemoteClient.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.ExternalAccess.FSharp\$(Configuration)\net472\Microsoft.CodeAnalysis.ExternalAccess.FSharp.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.VisualStudio.LanguageServices.SolutionExplorer\$(Configuration)\net472\Microsoft.VisualStudio.LanguageServices.SolutionExplorer.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.VisualStudio.LanguageServices.VisualBasic\$(Configuration)\net472\Microsoft.VisualStudio.LanguageServices.VisualBasic.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.VisualStudio.LanguageServices.Xaml\$(Configuration)\net472\Microsoft.VisualStudio.LanguageServices.Xaml.dll" TargetDir="" />
......@@ -122,7 +123,7 @@
<!-- Add xml doc comment files -->
<ItemGroup>
<_File Include="%(_File.RootDir)%(_File.Directory)%(_File.FileName).xml" TargetDir="%(_File.TargetDir)" Condition="Exists('%(_File.RootDir)%(_File.Directory)%(_File.FileName).xml')"/>
<_File Include="%(_File.RootDir)%(_File.Directory)%(_File.FileName).xml" TargetDir="%(_File.TargetDir)" Condition="Exists('%(_File.RootDir)%(_File.Directory)%(_File.FileName).xml')" />
</ItemGroup>
<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.Collections.Generic;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.ExternalAccess.Classification
{
[ExportLanguageServiceFactory(typeof(IClassificationService), LanguageNames.FSharp), Shared]
internal class FSharpClassificationServiceFactory : ILanguageServiceFactory
{
#pragma warning disable CS0618 // Type or member is obsolete
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
{
return new ProxyService(languageServices.GetService<IEditorClassificationService>());
}
private class ProxyService : IClassificationService
{
private readonly IEditorClassificationService _delegatee;
public ProxyService(IEditorClassificationService classificationService)
{
// connect to existing FSharp classification service that uses old obsolete service and
// export as new classification service.
// this is a temporary until fsharp team get our new bits
_delegatee = classificationService ?? new NullService();
}
public void AddLexicalClassifications(SourceText text, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
{
_delegatee.AddLexicalClassifications(text, textSpan, result, cancellationToken);
}
public Task AddSemanticClassificationsAsync(Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
{
return _delegatee.AddSemanticClassificationsAsync(document, textSpan, result, cancellationToken);
}
public Task AddSyntacticClassificationsAsync(Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken)
{
return _delegatee.AddSyntacticClassificationsAsync(document, textSpan, result, cancellationToken);
}
public ClassifiedSpan AdjustStaleClassification(SourceText text, ClassifiedSpan classifiedSpan)
{
return _delegatee.AdjustStaleClassification(text, classifiedSpan);
}
private class NullService : IEditorClassificationService
{
public void AddLexicalClassifications(SourceText text, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken) { }
public Task AddSemanticClassificationsAsync(Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken) => Task.CompletedTask;
public Task AddSyntacticClassificationsAsync(Document document, TextSpan textSpan, List<ClassifiedSpan> result, CancellationToken cancellationToken) => Task.CompletedTask;
public ClassifiedSpan AdjustStaleClassification(SourceText text, ClassifiedSpan classifiedSpan) => classifiedSpan;
}
}
#pragma warning restore CS0618 // Type or member is obsolete
}
}
......@@ -14,7 +14,7 @@
https://github.com/Microsoft/visualfsharp
</PackageDescription>
</PropertyGroup>
<ItemGroup>
<!--
⚠ ONLY F# ASSEMBLIES MAY BE ADDED HERE ⚠
......@@ -25,6 +25,8 @@
<ItemGroup>
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\EditorFeatures\CSharp\Microsoft.CodeAnalysis.CSharp.EditorFeatures.csproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
</ItemGroup>
<ItemGroup>
......
......@@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.DocumentHighlighting;
using Microsoft.CodeAnalysis.Editor.FindUsages;
using Microsoft.CodeAnalysis.FindUsages;
......
......@@ -180,7 +180,7 @@ public DocumentExcerpter(ITextBuffer primaryBuffer)
// we don't have gurantee that pirmary snapshot is from same snapshot as roslyn snapshot. make sure
// we map it to right snapshot
var fixedUpSpan = roslynSpan.TranslateTo(roslynSnapshot, SpanTrackingMode.EdgeExclusive);
var classifiedSpans = await EditorClassifier.GetClassifiedSpansAsync(document, fixedUpSpan.Span.ToTextSpan(), cancellationToken).ConfigureAwait(false);
var classifiedSpans = await ClassifierHelper.GetClassifiedSpansAsync(document, fixedUpSpan.Span.ToTextSpan(), cancellationToken).ConfigureAwait(false);
if (classifiedSpans.IsDefault)
{
continue;
......@@ -211,7 +211,7 @@ public DocumentExcerpter(ITextBuffer primaryBuffer)
// the EditorClassifier call above fills all the gaps for the span it is called with, but we are combining
// multiple spans with html code, so we need to fill those gaps
var builder = ArrayBuilder<ClassifiedSpan>.GetInstance();
EditorClassifier.FillInClassifiedSpanGaps(startPositionOnContentSpan, list, builder);
ClassifierHelper.FillInClassifiedSpanGaps(startPositionOnContentSpan, list, builder);
// add html after roslyn content if there is any
if (builder.Count == 0)
......
......@@ -29,6 +29,7 @@
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="EditorFeatures.Wpf" Path="|EditorFeatures.Wpf|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="Microsoft.CodeAnalysis.EditorFeatures.Text.dll" />
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="Microsoft.VisualStudio.LanguageServices.dll" />
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="Microsoft.CodeAnalysis.ExternalAccess.FSharp.dll" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="XamlVisualStudio" Path="|XamlVisualStudio|" />
<Asset Type="Microsoft.ServiceHub.Service" d:Source="File" Path="roslynRemoteHost.servicehub.service.json" />
<Asset Type="Microsoft.ServiceHub.Service" d:Source="File" Path="roslynSnapshot.servicehub.service.json" />
......
......@@ -4,51 +4,25 @@
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Editor
namespace Microsoft.CodeAnalysis.Classification
{
internal static class EditorClassifier
internal static class ClassifierHelper
{
/// <summary>
/// Classifies the provided <paramref name="span"/> in the given <paramref name="document"/>.
/// This will first try to do this using an appropriate <see cref="IClassificationService"/>
/// if it can be found, followed by an appropriate <see cref="IEditorClassificationService"/>
/// This will do this using an appropriate <see cref="IClassificationService"/>
/// if that can be found. <see cref="ImmutableArray{T}.IsDefault"/> will be returned if this
/// fails.
/// </summary>
public static async Task<ImmutableArray<ClassifiedSpan>> GetClassifiedSpansAsync(
Document document, TextSpan span, CancellationToken cancellationToken)
{
var result = await GetClassifiedSpansAsync(
WorkspaceClassificationDelegationService.Instance,
document, span, cancellationToken).ConfigureAwait(false);
if (!result.IsDefault)
{
return result;
}
result = await GetClassifiedSpansAsync(
EditorClassificationDelegationService.Instance,
document, span, cancellationToken).ConfigureAwait(false);
if (!result.IsDefault)
{
return result;
}
return default;
}
private static async Task<ImmutableArray<ClassifiedSpan>> GetClassifiedSpansAsync<TClassificationService>(
IClassificationDelegationService<TClassificationService> delegationService,
Document document, TextSpan widenedSpan, CancellationToken cancellationToken) where TClassificationService : class, ILanguageService
{
var classificationService = document.GetLanguageService<TClassificationService>();
var classificationService = document.GetLanguageService<IClassificationService>();
if (classificationService == null)
{
return default;
......@@ -65,12 +39,8 @@ internal static class EditorClassifier
var semanticSpans = ListPool<ClassifiedSpan>.Allocate();
try
{
var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
await delegationService.AddSyntacticClassificationsAsync(
classificationService, document, widenedSpan, syntaxSpans, cancellationToken).ConfigureAwait(false);
await delegationService.AddSemanticClassificationsAsync(
classificationService, document, widenedSpan, semanticSpans, cancellationToken).ConfigureAwait(false);
await classificationService.AddSyntacticClassificationsAsync(document, span, syntaxSpans, cancellationToken).ConfigureAwait(false);
await classificationService.AddSemanticClassificationsAsync(document, span, semanticSpans, cancellationToken).ConfigureAwait(false);
// MergeClassifiedSpans will ultimately filter multiple classifications for the same
// span down to one. We know that additive classifications are there just to
......@@ -80,8 +50,7 @@ internal static class EditorClassifier
RemoveAdditiveSpans(syntaxSpans);
RemoveAdditiveSpans(semanticSpans);
var classifiedSpans = MergeClassifiedSpans(
syntaxSpans, semanticSpans, widenedSpan, sourceText);
var classifiedSpans = MergeClassifiedSpans(syntaxSpans, semanticSpans, span);
return classifiedSpans;
}
finally
......@@ -104,8 +73,7 @@ private static void RemoveAdditiveSpans(List<ClassifiedSpan> spans)
}
private static ImmutableArray<ClassifiedSpan> MergeClassifiedSpans(
List<ClassifiedSpan> syntaxSpans, List<ClassifiedSpan> semanticSpans,
TextSpan widenedSpan, SourceText sourceText)
List<ClassifiedSpan> syntaxSpans, List<ClassifiedSpan> semanticSpans, TextSpan widenedSpan)
{
// The spans produced by the language services may not be ordered
// (indeed, this happens with semantic classification as different
......@@ -184,7 +152,8 @@ private static void AdjustSpans(List<ClassifiedSpan> spans, TextSpan widenedSpan
}
}
public static void FillInClassifiedSpanGaps(int startPosition, IEnumerable<ClassifiedSpan> classifiedSpans, ArrayBuilder<ClassifiedSpan> result)
public static void FillInClassifiedSpanGaps(
int startPosition, IEnumerable<ClassifiedSpan> classifiedSpans, ArrayBuilder<ClassifiedSpan> result)
{
foreach (var span in classifiedSpans)
{
......
......@@ -256,6 +256,7 @@
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.SolutionExplorer" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.VisualBasic" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Xaml" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.FSharp" />
<InternalsVisibleTo Include="Roslyn.Hosting.Diagnostics" />
<InternalsVisibleTo Include="Roslyn.VisualStudio.Setup" />
<InternalsVisibleTo Include="Roslyn.VisualStudio.DiagnosticsWindow" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册