|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Collections.Immutable; |
| 8 | +using System.Composition; |
| 9 | +using System.Threading; |
| 10 | +using System.Threading.Tasks; |
| 11 | +using Microsoft.CodeAnalysis.Classification; |
| 12 | +using Microsoft.CodeAnalysis.Collections; |
| 13 | +using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; |
| 14 | +using Microsoft.CodeAnalysis.Host; |
| 15 | +using Microsoft.CodeAnalysis.Host.Mef; |
| 16 | +using Microsoft.CodeAnalysis.Text; |
| 17 | + |
| 18 | +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript; |
| 19 | + |
| 20 | +[ExportLanguageService(typeof(IClassificationService), InternalLanguageNames.TypeScript), Shared] |
| 21 | +internal sealed class VSTypeScriptClassificationService : IClassificationService |
| 22 | +{ |
| 23 | + private readonly IVSTypeScriptClassificationService? _classificationService; |
| 24 | + |
| 25 | + [ImportingConstructor] |
| 26 | + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] |
| 27 | + public VSTypeScriptClassificationService( |
| 28 | + [Import(AllowDefault = true)] IVSTypeScriptClassificationService? classificationService) |
| 29 | + { |
| 30 | + _classificationService = classificationService; |
| 31 | + } |
| 32 | + |
| 33 | + public void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken) |
| 34 | + { |
| 35 | + } |
| 36 | + |
| 37 | + public void AddSyntacticClassifications(SolutionServices services, SyntaxNode? root, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken) |
| 38 | + { |
| 39 | + } |
| 40 | + |
| 41 | + public Task AddSyntacticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken) |
| 42 | + { |
| 43 | + return Task.CompletedTask; |
| 44 | + } |
| 45 | + |
| 46 | + public Task AddEmbeddedLanguageClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken) |
| 47 | + { |
| 48 | + return Task.CompletedTask; |
| 49 | + } |
| 50 | + |
| 51 | + public ClassifiedSpan AdjustStaleClassification(SourceText text, ClassifiedSpan classifiedSpan) |
| 52 | + { |
| 53 | + return classifiedSpan; |
| 54 | + } |
| 55 | + |
| 56 | + public ValueTask<TextChangeRange?> ComputeSyntacticChangeRangeAsync(Document oldDocument, Document newDocument, TimeSpan timeout, CancellationToken cancellationToken) |
| 57 | + { |
| 58 | + return default; |
| 59 | + } |
| 60 | + |
| 61 | + public TextChangeRange? ComputeSyntacticChangeRange(SolutionServices workspace, SyntaxNode oldRoot, SyntaxNode newRoot, TimeSpan timeout, CancellationToken cancellationToken) |
| 62 | + { |
| 63 | + return null; |
| 64 | + } |
| 65 | + |
| 66 | + public async Task AddSemanticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken) |
| 67 | + { |
| 68 | + if (_classificationService is null) |
| 69 | + return; |
| 70 | + |
| 71 | + using var _ = SharedPools.BigDefault<List<ClassifiedSpan>>().GetPooledObject(out var list); |
| 72 | + |
| 73 | + await _classificationService.AddSemanticClassificationsAsync(document, textSpans, list, cancellationToken).ConfigureAwait(false); |
| 74 | + |
| 75 | + foreach (var classifiedSpan in list) |
| 76 | + result.Add(classifiedSpan); |
| 77 | + } |
| 78 | +} |
0 commit comments