/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Features/CSharp/Portable/Structure/Providers/InitializerExpressionStructureProvider.cs
74 строки
3 KB
Deepak Singh Rathore
Fix structure guideline anchor for initializer expressions with multi-line argument lists (#82946)
27 мар 2026, 21:28
Не верифицирован
27 мар 2026, 21:28
00f4340
Код
Авторство
О чём код?
// 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. #nullable disable using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Structure; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CSharp.Structure; internal sealed class InitializerExpressionStructureProvider : AbstractSyntaxNodeStructureProvider<InitializerExpressionSyntax> { protected override void CollectBlockSpans( SyntaxToken previousToken, InitializerExpressionSyntax node, ArrayBuilder<BlockSpan> spans, BlockStructureOptions options, CancellationToken cancellationToken) { if (node.Parent is InitializerExpressionSyntax) { // We have something like: // // new Dictionary<int, string> // { // ... // { // ... // }, // ... // } // // In this case, we want to collapse the "{ ... }," (including the comma). var nextToken = node.CloseBraceToken.GetNextToken(); var end = nextToken.Kind() == SyntaxKind.CommaToken ? nextToken.Span.End : node.Span.End; spans.Add(new BlockSpan( isCollapsible: true, textSpan: TextSpan.FromBounds(node.SpanStart, end), hintSpan: TextSpan.FromBounds(node.SpanStart, end), type: BlockTypes.Expression)); } else { // Parent is something like: // // new Dictionary<int, string> { // ... // } // // The collapsed textspan should be from the { to the } // // The hint span is the containing statement for hover context. var containingStatement = node.FirstAncestorOrSelf<StatementSyntax>(); var hintSpan = containingStatement != null ? containingStatement.Span : node.Parent.Span; spans.Add(new BlockSpan( isCollapsible: true, textSpan: TextSpan.FromBounds(node.SpanStart, node.Span.End), hintSpan: hintSpan, type: BlockTypes.Expression)); } } }