Skip to content

Commit 70e036b

Browse files
Introduce EA layer for TS to integrate with classification
1 parent f650a15 commit 70e036b

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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.Collections.Generic;
6+
using System.Collections.Immutable;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using Microsoft.CodeAnalysis.Classification;
10+
using Microsoft.CodeAnalysis.Text;
11+
12+
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
13+
14+
internal interface IVSTypeScriptClassificationService
15+
{
16+
Task AddSemanticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, List<ClassifiedSpan> result, CancellationToken cancellationToken);
17+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
}

src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptCommentSelectionService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Composition;
7+
using Microsoft.CodeAnalysis.Classification;
78
using Microsoft.CodeAnalysis.CommentSelection;
89
using Microsoft.CodeAnalysis.Host.Mef;
910

0 commit comments

Comments
 (0)