本文整理汇总了C#中SyntaxToken.GetCommonRoot方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.GetCommonRoot方法的具体用法?C# SyntaxToken.GetCommonRoot怎么用?C# SyntaxToken.GetCommonRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.GetCommonRoot方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInitialIndentBlockOperations
private List<IndentBlockOperation> GetInitialIndentBlockOperations(SyntaxToken startToken, SyntaxToken endToken)
{
var span = TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End);
var node = startToken.GetCommonRoot(endToken).GetParentWithBiggerSpan();
var previous = default(SyntaxNode);
// starting from the common node, move up to the parent
var operations = new List<IndentBlockOperation>();
var list = new List<IndentBlockOperation>();
while (node != null)
{
// get all operations for the nodes that contains the formatting span, but not ones contained by the span
node.DescendantNodesAndSelf(n => n != previous && n.Span.IntersectsWith(span) && !span.Contains(n.Span))
.Do(n =>
{
this.formattingRules.AddIndentBlockOperations(list, n);
foreach (var element in list)
{
if (element != null)
{
operations.Add(element);
}
}
list.Clear();
});
// found some. use these as initial indentation
if (operations.Any(o => o.TextSpan.Contains(span)))
{
break;
}
previous = node;
node = node.Parent;
}
// make sure operations we have has effects over the formatting span
operations.RemoveAll(o => o == null || !o.TextSpan.IntersectsWith(span));
// we couldn't find anything
// return initial location so that we can get base indentation correctly
if (operations.Count == 0)
{
operations.Add(new IndentBlockOperation(
startToken: this.rootNode.GetFirstToken(includeZeroWidth: true),
endToken: this.rootNode.GetLastToken(includeZeroWidth: true),
textSpan: this.rootNode.FullSpan,
indentationDelta: 0,
option: IndentBlockOption.AbsolutePosition));
return operations;
}
operations.Sort(CommonFormattingHelpers.IndentBlockOperationComparer);
return operations;
}
示例2: FormatRange
public IList<TextChange> FormatRange(
Workspace workspace, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken)
{
Contract.ThrowIfTrue(startToken.Kind() == SyntaxKind.None || startToken.Kind() == SyntaxKind.EndOfFileToken);
Contract.ThrowIfTrue(endToken.Kind() == SyntaxKind.None || endToken.Kind() == SyntaxKind.EndOfFileToken);
var smartTokenformattingRules = _formattingRules;
var common = startToken.GetCommonRoot(endToken);
if (common.ContainsDiagnostics)
{
// if there is errors, do not touch lines
smartTokenformattingRules = (new NoLineChangeFormattingRule()).Concat(_formattingRules);
}
return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
}
示例3: FormatRange
public IList<TextChange> FormatRange(
Workspace workspace, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken)
{
Contract.ThrowIfTrue(startToken.Kind() == SyntaxKind.None || startToken.Kind() == SyntaxKind.EndOfFileToken);
Contract.ThrowIfTrue(endToken.Kind() == SyntaxKind.None || endToken.Kind() == SyntaxKind.EndOfFileToken);
var smartTokenformattingRules = _formattingRules;
var common = startToken.GetCommonRoot(endToken);
// if there are errors, do not touch lines
// Exception: In the case of try-catch-finally block, a try block without a catch/finally block is considered incomplete
// but we would like to apply line operation in a completed try block even if there is no catch/finally block
if (common.ContainsDiagnostics && !CloseBraceOfTryBlock(endToken))
{
smartTokenformattingRules = (new NoLineChangeFormattingRule()).Concat(_formattingRules);
}
return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
}
示例4: GetNodeWithTokens
internal SyntaxNode GetNodeWithTokens(SyntaxToken startToken, SyntaxToken endToken, SyntaxNode root)
{
if (IsEndOfFileToken(endToken))
{
return root;
}
else
{
return startToken.GetCommonRoot(endToken);
}
}
示例5: SetInnermostNodeForSpan
private void SetInnermostNodeForSpan(SyntaxNode root, ref TextSpan span, out SyntaxToken token1, out SyntaxToken token2, out SyntaxNode commonNode)
{
commonNode = default(SyntaxNode);
GetTokens(root, span, out token1, out token2);
span = GetSpanFromTokens(span, token1, token2);
if (token1.RawKind == 0 || token2.RawKind == 0)
{
return;
}
commonNode = token1.GetCommonRoot(token2);
}