Skip to content

Commit 25357a9

Browse files
[automated] Merge branch 'main' => 'main-vs-deps' (#78903)
I detected changes in the main branch which have not been merged yet to main-vs-deps. I'm a robot and am configured to help you automatically keep main-vs-deps up to date, so I've opened this PR. This PR merges commits made on main by the following committers: * CyrusNajmabadi ## Instructions for merging from UI This PR will not be auto-merged. When pull request checks pass, complete this PR by creating a merge commit, *not* a squash or rebase commit. <img alt="merge button instructions" src="https://i.imgur.com/GepcNJV.png" width="300" /> If this repo does not allow creating merge commits from the GitHub UI, use command line instructions. ## Instructions for merging via command line Run these commands to merge this pull request from the command line. ``` sh git fetch git checkout main git pull --ff-only git checkout main-vs-deps git pull --ff-only git merge --no-ff main # If there are merge conflicts, resolve them and then run git merge --continue to complete the merge # Pushing the changes to the PR branch will re-trigger PR validation. git push https://github.com/dotnet/roslyn HEAD:merge/main-to-main-vs-deps ``` <details> <summary>or if you are using SSH</summary> ``` git push [email protected]:dotnet/roslyn HEAD:merge/main-to-main-vs-deps ``` </details> After PR checks are complete push the branch ``` git push ``` ## Instructions for resolving conflicts :warning: If there are merge conflicts, you will need to resolve them manually before merging. You can do this [using GitHub][resolve-github] or using the [command line][resolve-cli]. [resolve-github]: https://help.github.com/articles/resolving-a-merge-conflict-on-github/ [resolve-cli]: https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/ ## Instructions for updating this pull request Contributors to this repo have permission update this pull request by pushing to the branch 'merge/main-to-main-vs-deps'. This can be done to resolve conflicts or make other changes to this pull request before it is merged. The provided examples assume that the remote is named 'origin'. If you have a different remote name, please replace 'origin' with the name of your remote. ``` git fetch git checkout -b merge/main-to-main-vs-deps origin/main-vs-deps git pull https://github.com/dotnet/roslyn merge/main-to-main-vs-deps (make changes) git commit -m "Updated PR with my changes" git push https://github.com/dotnet/roslyn HEAD:merge/main-to-main-vs-deps ``` <details> <summary>or if you are using SSH</summary> ``` git fetch git checkout -b merge/main-to-main-vs-deps origin/main-vs-deps git pull [email protected]:dotnet/roslyn merge/main-to-main-vs-deps (make changes) git commit -m "Updated PR with my changes" git push [email protected]:dotnet/roslyn HEAD:merge/main-to-main-vs-deps ``` </details> Contact .NET Core Engineering (dotnet/dnceng) if you have questions or issues. Also, if this PR was generated incorrectly, help us fix it. See https://github.com/dotnet/arcade/blob/main/.github/workflows/scripts/inter-branch-merge.ps1.
2 parents c0e50e9 + 5aaba99 commit 25357a9

File tree

6 files changed

+108
-14
lines changed

6 files changed

+108
-14
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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
[method: ImportingConstructor]
22+
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
23+
internal sealed class VSTypeScriptClassificationService(
24+
[Import(AllowDefault = true)] IVSTypeScriptClassificationService? classificationService) : IClassificationService
25+
{
26+
public void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
27+
{
28+
}
29+
30+
public void AddSyntacticClassifications(SolutionServices services, SyntaxNode? root, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
31+
{
32+
}
33+
34+
public Task AddSyntacticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
35+
=> Task.CompletedTask;
36+
37+
public Task AddEmbeddedLanguageClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
38+
=> Task.CompletedTask;
39+
40+
public ClassifiedSpan AdjustStaleClassification(SourceText text, ClassifiedSpan classifiedSpan)
41+
=> classifiedSpan;
42+
43+
public ValueTask<TextChangeRange?> ComputeSyntacticChangeRangeAsync(Document oldDocument, Document newDocument, TimeSpan timeout, CancellationToken cancellationToken)
44+
=> default;
45+
46+
public TextChangeRange? ComputeSyntacticChangeRange(SolutionServices workspace, SyntaxNode oldRoot, SyntaxNode newRoot, TimeSpan timeout, CancellationToken cancellationToken)
47+
=> null;
48+
49+
public async Task AddSemanticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
50+
{
51+
if (classificationService is null)
52+
return;
53+
54+
using var _ = SharedPools.BigDefault<List<ClassifiedSpan>>().GetPooledObject(out var list);
55+
56+
await classificationService.AddSemanticClassificationsAsync(document, textSpans, list, cancellationToken).ConfigureAwait(false);
57+
58+
foreach (var classifiedSpan in list)
59+
result.Add(classifiedSpan);
60+
}
61+
}

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

src/LanguageServer/Protocol/Protocol/Internal/Converters/ImageElementConverter.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public override ImageElement Read(ref Utf8JsonReader reader, Type typeToConvert,
3333

3434
if (reader.TokenType == JsonTokenType.PropertyName)
3535
{
36-
var valueLength = reader.HasValueSequence ? reader.ValueSequence.Length : reader.ValueSpan.Length;
37-
38-
var propertyNameLength = valueLength <= scratchChars.Length ? reader.CopyString(scratchChars) : -1;
39-
var propertyName = propertyNameLength >= 0 ? scratchChars[..propertyNameLength] : reader.GetString().AsSpan();
36+
var propertyName = reader.GetStringSpan(scratchChars);
4037

4138
reader.Read();
4239
switch (propertyName)
@@ -48,10 +45,9 @@ public override ImageElement Read(ref Utf8JsonReader reader, Type typeToConvert,
4845
automationName = reader.GetString();
4946
break;
5047
case ObjectContentConverter.TypeProperty:
51-
var typePropertyLength = valueLength <= scratchChars.Length ? reader.CopyString(scratchChars) : -1;
52-
var typeProperty = typePropertyLength >= 0 ? scratchChars[..typePropertyLength] : reader.GetString().AsSpan();
48+
var typePropertyValue = reader.GetStringSpan(scratchChars);
5349

54-
if (!typeProperty.SequenceEqual(nameof(ImageElement).AsSpan()))
50+
if (!typePropertyValue.SequenceEqual(nameof(ImageElement).AsSpan()))
5551
throw new JsonException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ImageElement)}");
5652
break;
5753
default:

src/LanguageServer/Protocol/Protocol/Internal/Converters/ImageIdConverter.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ public override ImageId Read(ref Utf8JsonReader reader, Type objectType, JsonSer
3434

3535
if (reader.TokenType == JsonTokenType.PropertyName)
3636
{
37-
var valueLength = reader.HasValueSequence ? reader.ValueSequence.Length : reader.ValueSpan.Length;
38-
39-
var propertyNameLength = valueLength <= scratchChars.Length ? reader.CopyString(scratchChars) : -1;
40-
var propertyName = propertyNameLength >= 0 ? scratchChars[..propertyNameLength] : reader.GetString().AsSpan();
37+
var propertyName = reader.GetStringSpan(scratchChars);
4138

4239
reader.Read();
4340
switch (propertyName)
@@ -49,10 +46,9 @@ public override ImageId Read(ref Utf8JsonReader reader, Type objectType, JsonSer
4946
id = reader.GetInt32();
5047
break;
5148
case ObjectContentConverter.TypeProperty:
52-
var typePropertyLength = valueLength <= scratchChars.Length ? reader.CopyString(scratchChars) : -1;
53-
var typeProperty = typePropertyLength >= 0 ? scratchChars[..typePropertyLength] : reader.GetString().AsSpan();
49+
var typePropertyValue = reader.GetStringSpan(scratchChars);
5450

55-
if (!typeProperty.SequenceEqual(nameof(ImageId).AsSpan()))
51+
if (!typePropertyValue.SequenceEqual(nameof(ImageId).AsSpan()))
5652
throw new JsonException($"Expected {ObjectContentConverter.TypeProperty} property value {nameof(ImageId)}");
5753
break;
5854
default:

src/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using System.Collections.Generic;
67
using System.Text.Json;
78
using System.Text.Json.Serialization;
@@ -71,4 +72,26 @@ void AddOrReplaceConverter<TBase, TExtension>()
7172
converters.Add(new VSExtensionConverter<TBase, TExtension>());
7273
}
7374
}
75+
76+
/// <summary>
77+
/// Returns a string read from the <see cref="Utf8JsonReader"/>. If the string is small enough
78+
/// to fit into the provided <paramref name="scratchChars"/>, no allocations will be needed.
79+
/// </summary>
80+
internal static ReadOnlySpan<char> GetStringSpan(this ref readonly Utf8JsonReader reader, Span<char> scratchChars)
81+
{
82+
var valueLength = reader.HasValueSequence ? reader.ValueSequence.Length : reader.ValueSpan.Length;
83+
84+
if (valueLength <= scratchChars.Length)
85+
{
86+
// If the value fits into the scratch buffer, copy it there, and return a span from that.
87+
var actualLength = reader.CopyString(scratchChars);
88+
89+
return scratchChars.Slice(0, actualLength);
90+
}
91+
else
92+
{
93+
// Otherwise, ask the reader to allocate a string and return a span from that.
94+
return reader.GetString().AsSpan();
95+
}
96+
}
7497
}

0 commit comments

Comments
 (0)