Skip to content

Commit 89c6895

Browse files
[automated] Merge branch 'main' => 'main-vs-deps' (#79089)
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 * dibarbet ## 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 git@github.com: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 git@github.com:dotnet/roslyn merge/main-to-main-vs-deps (make changes) git commit -m "Updated PR with my changes" git push git@github.com: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 de67798 + f89c700 commit 89c6895

File tree

38 files changed

+487
-184
lines changed

38 files changed

+487
-184
lines changed

src/CodeStyle/Core/CodeFixes/LanguageServices/SemanticModelWorkspaceService/SemanticModelWorkspaceServiceFactory.SemanticModelWorkspaceService.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Features/ExternalAccess/OmniSharp.CSharp/Formatting/OmniSharpSyntaxFormattingOptionsFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static OmniSharpSyntaxFormattingOptionsWrapper Create(
108108
(spaceBeforeComma ? SpacePlacement.BeforeComma : 0) |
109109
(spaceAfterDot ? SpacePlacement.AfterDot : 0) |
110110
(spaceBeforeDot ? SpacePlacement.BeforeDot : 0),
111-
SpacingAroundBinaryOperator = (BinaryOperatorSpacingOptions)spacingAroundBinaryOperator,
111+
SpacingAroundBinaryOperator = (BinaryOperatorSpacingOptionsInternal)spacingAroundBinaryOperator,
112112
NewLines =
113113
(newLineForMembersInObjectInit ? NewLinePlacement.BeforeMembersInObjectInitializers : 0) |
114114
(newLineForMembersInAnonymousTypes ? NewLinePlacement.BeforeMembersInAnonymousTypes : 0) |
@@ -125,7 +125,7 @@ public static OmniSharpSyntaxFormattingOptionsWrapper Create(
125125
(newLinesForBracesInLambdaExpressionBody ? NewLinePlacement.BeforeOpenBraceInLambdaExpressionBody : 0) |
126126
(newLinesForBracesInControlBlocks ? NewLinePlacement.BeforeOpenBraceInControlBlocks : 0) |
127127
(newLineForClausesInQuery ? NewLinePlacement.BetweenQueryExpressionClauses : 0),
128-
LabelPositioning = (LabelPositionOptions)labelPositioning,
128+
LabelPositioning = (LabelPositionOptionsInternal)labelPositioning,
129129
Indentation =
130130
(indentBraces ? IndentationPlacement.Braces : 0) |
131131
(indentBlock ? IndentationPlacement.BlockContents : 0) |

src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,35 @@ private static async Task GetClassifiedSpansForDocumentAsync(
127127
var spans = await ClassifierHelper.GetClassifiedSpansAsync(
128128
document, textSpans, options, includeAdditiveSpans: true, cancellationToken).ConfigureAwait(false);
129129

130-
// The spans returned to us may include some empty spans, which we don't care about. We also don't care
131-
// about the 'text' classification. It's added for everything between real classifications (including
130+
// Some classified spans may not be relevant and should be filtered out before we convert to tokens.
131+
var filteredSpans = spans.Where(s => !ShouldFilterClassification(s));
132+
133+
classifiedSpans.AddRange(filteredSpans);
134+
}
135+
136+
private static bool ShouldFilterClassification(ClassifiedSpan s)
137+
{
138+
// The spans returned to us may include some empty spans, which we don't care about.
139+
if (s.TextSpan.IsEmpty)
140+
{
141+
return true;
142+
}
143+
144+
// We also don't care about the 'text' classification. It's added for everything between real classifications (including
132145
// whitespace), and just means 'don't classify this'. No need for us to actually include that in
133146
// semantic tokens as it just wastes space in the result.
134-
var nonEmptySpans = spans.Where(s => !s.TextSpan.IsEmpty && s.ClassificationType != ClassificationTypeNames.Text);
135-
classifiedSpans.AddRange(nonEmptySpans);
147+
if (s.ClassificationType == ClassificationTypeNames.Text)
148+
{
149+
return true;
150+
}
151+
152+
// Additive classification types that are mapped to TokenModifiers.None are not rendered by the client and do not need to be included.
153+
if (SemanticTokensSchema.AdditiveClassificationTypeToTokenModifier.TryGetValue(s.ClassificationType, out var modifier) && modifier == TokenModifiers.None)
154+
{
155+
return true;
156+
}
157+
158+
return false;
136159
}
137160

138161
private static void ConvertMultiLineToSingleLineSpans(SourceText text, SegmentedList<ClassifiedSpan> classifiedSpans, SegmentedList<ClassifiedSpan> updatedClassifiedSpans)
@@ -288,37 +311,21 @@ private static int ComputeNextToken(
288311
var tokenLength = originalTextSpan.Length;
289312
Contract.ThrowIfFalse(tokenLength > 0);
290313

291-
// We currently only have one modifier (static). The logic below will need to change in the future if other
292-
// modifiers are added in the future.
293314
var modifierBits = TokenModifiers.None;
294315
var tokenTypeIndex = 0;
295316

296317
// Classified spans with the same text span should be combined into one token.
297318
while (classifiedSpans[currentClassifiedSpanIndex].TextSpan == originalTextSpan)
298319
{
299320
var classificationType = classifiedSpans[currentClassifiedSpanIndex].ClassificationType;
300-
if (classificationType == ClassificationTypeNames.StaticSymbol)
301-
{
302-
// 4. Token modifiers - each set bit will be looked up in SemanticTokensLegend.tokenModifiers
303-
modifierBits |= TokenModifiers.Static;
304-
}
305-
else if (classificationType == ClassificationTypeNames.ReassignedVariable)
306-
{
307-
// 5. Token modifiers - each set bit will be looked up in SemanticTokensLegend.tokenModifiers
308-
modifierBits |= TokenModifiers.ReassignedVariable;
309-
}
310-
else if (classificationType == ClassificationTypeNames.ObsoleteSymbol)
311-
{
312-
// 6. Token modifiers - each set bit will be looked up in SemanticTokensLegend.tokenModifiers
313-
modifierBits |= TokenModifiers.Deprecated;
314-
}
315-
else if (classificationType == ClassificationTypeNames.TestCode)
321+
322+
if (SemanticTokensSchema.AdditiveClassificationTypeToTokenModifier.TryGetValue(classificationType, out var modifier))
316323
{
317-
// Skip additive types that are not being converted to token modifiers.
324+
modifierBits |= modifier;
318325
}
319326
else
320327
{
321-
// 7. Token type - looked up in SemanticTokensLegend.tokenTypes (language server defined mapping
328+
// 5. Token type - looked up in SemanticTokensLegend.tokenTypes (language server defined mapping
322329
// from integer to LSP token types).
323330
tokenTypeIndex = GetTokenTypeIndex(classificationType);
324331
}

src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensSchema.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ internal readonly struct SemanticTokensSchema
7575
classificationTypeName => classificationTypeName,
7676
classificationTypeName => IDictionaryExtensions.GetValueOrDefault(s_pureLspDirectTypeMap, classificationTypeName) ?? CustomLspSemanticTokenNames.ClassificationTypeNameToCustomTokenName[classificationTypeName]));
7777

78+
/// <summary>
79+
/// Mapping from additive classification type names to LSP token modifiers.
80+
/// </summary>
81+
public static ImmutableDictionary<string, TokenModifiers> AdditiveClassificationTypeToTokenModifier => new Dictionary<string, TokenModifiers>()
82+
{
83+
[ClassificationTypeNames.StaticSymbol] = SemanticTokens.TokenModifiers.Static,
84+
[ClassificationTypeNames.ReassignedVariable] = SemanticTokens.TokenModifiers.ReassignedVariable,
85+
[ClassificationTypeNames.ObsoleteSymbol] = SemanticTokens.TokenModifiers.Deprecated,
86+
[ClassificationTypeNames.TestCode] = SemanticTokens.TokenModifiers.None,
87+
}.ToImmutableDictionary();
88+
7889
/// <summary>
7990
/// Mapping from roslyn <see cref="ClassificationTypeNames"/> to the LSP token name. This is either a standard
8091
/// <see cref="SemanticTokenTypes"/> or a custom token name.

0 commit comments

Comments
 (0)