diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptClassificationService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptClassificationService.cs new file mode 100644 index 0000000000000..ed76545a29beb --- /dev/null +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptClassificationService.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Classification; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; + +internal interface IVSTypeScriptClassificationService +{ + Task AddSemanticClassificationsAsync(Document document, ImmutableArray textSpans, List result, CancellationToken cancellationToken); +} diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptClassificationService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptClassificationService.cs new file mode 100644 index 0000000000000..41399a5c6c11e --- /dev/null +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptClassificationService.cs @@ -0,0 +1,61 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Composition; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Classification; +using Microsoft.CodeAnalysis.Collections; +using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; +using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript; + +[ExportLanguageService(typeof(IClassificationService), InternalLanguageNames.TypeScript), Shared] +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class VSTypeScriptClassificationService( + [Import(AllowDefault = true)] IVSTypeScriptClassificationService? classificationService) : IClassificationService +{ + public void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList result, CancellationToken cancellationToken) + { + } + + public void AddSyntacticClassifications(SolutionServices services, SyntaxNode? root, ImmutableArray textSpans, SegmentedList result, CancellationToken cancellationToken) + { + } + + public Task AddSyntacticClassificationsAsync(Document document, ImmutableArray textSpans, SegmentedList result, CancellationToken cancellationToken) + => Task.CompletedTask; + + public Task AddEmbeddedLanguageClassificationsAsync(Document document, ImmutableArray textSpans, ClassificationOptions options, SegmentedList result, CancellationToken cancellationToken) + => Task.CompletedTask; + + public ClassifiedSpan AdjustStaleClassification(SourceText text, ClassifiedSpan classifiedSpan) + => classifiedSpan; + + public ValueTask ComputeSyntacticChangeRangeAsync(Document oldDocument, Document newDocument, TimeSpan timeout, CancellationToken cancellationToken) + => default; + + public TextChangeRange? ComputeSyntacticChangeRange(SolutionServices workspace, SyntaxNode oldRoot, SyntaxNode newRoot, TimeSpan timeout, CancellationToken cancellationToken) + => null; + + public async Task AddSemanticClassificationsAsync(Document document, ImmutableArray textSpans, ClassificationOptions options, SegmentedList result, CancellationToken cancellationToken) + { + if (classificationService is null) + return; + + using var _ = SharedPools.BigDefault>().GetPooledObject(out var list); + + await classificationService.AddSemanticClassificationsAsync(document, textSpans, list, cancellationToken).ConfigureAwait(false); + + foreach (var classifiedSpan in list) + result.Add(classifiedSpan); + } +} diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs index 1d2f818cef885..7b4675dde2770 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs @@ -4,6 +4,7 @@ using System; using System.Composition; +using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.CommentSelection; using Microsoft.CodeAnalysis.Host.Mef;