本文整理汇总了C#中TextSpan.IntersectsWith方法的典型用法代码示例。如果您正苦于以下问题:C# TextSpan.IntersectsWith方法的具体用法?C# TextSpan.IntersectsWith怎么用?C# TextSpan.IntersectsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextSpan
的用法示例。
在下文中一共展示了TextSpan.IntersectsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsCaretOutsideItemBounds
private bool IsCaretOutsideItemBounds(
Model model,
SnapshotPoint caretPoint,
CompletionItem item,
Dictionary<TextSpan, string> textSpanToText,
Dictionary<TextSpan, ViewTextSpan> textSpanToViewSpan)
{
// Easy first check. See if the caret point is before the start of the item.
ViewTextSpan filterSpanInViewBuffer;
if (!textSpanToViewSpan.TryGetValue(item.FilterSpan, out filterSpanInViewBuffer))
{
filterSpanInViewBuffer = model.GetSubjectBufferFilterSpanInViewBuffer(item.FilterSpan);
textSpanToViewSpan[item.FilterSpan] = filterSpanInViewBuffer;
}
if (caretPoint < filterSpanInViewBuffer.TextSpan.Start)
{
return true;
}
var textSnapshot = caretPoint.Snapshot;
var currentText = model.GetCurrentTextInSnapshot(item.FilterSpan, textSnapshot, textSpanToText);
var currentTextSpan = new TextSpan(filterSpanInViewBuffer.TextSpan.Start, currentText.Length);
return !currentTextSpan.IntersectsWith(caretPoint);
}
示例2: GetTypeDeclaration
internal override SyntaxNode GetTypeDeclaration(Document document, int position, TypeDiscoveryRule typeDiscoveryRule, CancellationToken cancellationToken)
{
var tree = document.GetCSharpSyntaxTreeAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var token = tree.GetRoot(cancellationToken).FindToken(position != tree.Length ? position : Math.Max(0, position - 1));
var typeDeclaration = token.GetAncestor<TypeDeclarationSyntax>();
if (typeDeclaration == null ||
typeDiscoveryRule == TypeDiscoveryRule.TypeDeclaration)
{
return typeDeclaration;
}
var spanStart = typeDeclaration.Identifier.SpanStart;
var spanEnd = typeDeclaration.TypeParameterList != null ? typeDeclaration.TypeParameterList.Span.End : typeDeclaration.Identifier.Span.End;
var span = new TextSpan(spanStart, spanEnd - spanStart);
return span.IntersectsWith(position) ? typeDeclaration : null;
}
示例3: GetTypeDeclarationAsync
internal override async Task<SyntaxNode> GetTypeDeclarationAsync(Document document, int position, TypeDiscoveryRule typeDiscoveryRule, CancellationToken cancellationToken)
{
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
var token = root.FindToken(position != tree.Length ? position : Math.Max(0, position - 1));
var typeDeclaration = token.GetAncestor<TypeDeclarationSyntax>();
if (typeDeclaration == null ||
typeDiscoveryRule == TypeDiscoveryRule.TypeDeclaration)
{
return typeDeclaration;
}
var spanStart = typeDeclaration.Identifier.SpanStart;
var spanEnd = typeDeclaration.TypeParameterList != null ? typeDeclaration.TypeParameterList.Span.End : typeDeclaration.Identifier.Span.End;
var span = new TextSpan(spanStart, spanEnd - spanStart);
return span.IntersectsWith(position) ? typeDeclaration : null;
}
示例4: GetFirstDiagnosticWithFixAsync
public async Task<FirstDiagnosticResult> GetFirstDiagnosticWithFixAsync(Document document, TextSpan range, CancellationToken cancellationToken)
{
if (document == null || !document.IsOpen())
{
return default(FirstDiagnosticResult);
}
using (var diagnostics = SharedPools.Default<List<DiagnosticData>>().GetPooledObject())
{
var fullResult = await _diagnosticService.TryGetDiagnosticsForSpanAsync(document, range, diagnostics.Object, cancellationToken).ConfigureAwait(false);
foreach (var diagnostic in diagnostics.Object)
{
cancellationToken.ThrowIfCancellationRequested();
if (!range.IntersectsWith(diagnostic.TextSpan))
{
continue;
}
// REVIEW: 2 possible designs.
// 1. find the first fix and then return right away. if the lightbulb is actually expanded, find all fixes for the line synchronously. or
// 2. kick off a task that finds all fixes for the given range here but return once we find the first one.
// at the same time, let the task to run to finish. if the lightbulb is expanded, we just simply use the task to get all fixes.
//
// first approach is simpler, so I will implement that first. if the first approach turns out to be not good enough, then
// I will try the second approach which will be more complex but quicker
var hasFix = await ContainsAnyFix(document, diagnostic, cancellationToken).ConfigureAwait(false);
if (hasFix)
{
return new FirstDiagnosticResult(!fullResult, hasFix, diagnostic);
}
}
return new FirstDiagnosticResult(!fullResult, false, default(DiagnosticData));
}
}
示例5: TextSpanIntersection03
public void TextSpanIntersection03()
{
TextSpan span1 = new TextSpan(10, 0); // [10, 10)
TextSpan span2 = new TextSpan(10, 0); // [10, 10)
Assert.True(span1.IntersectsWith(span2));
Assert.True(span2.IntersectsWith(span1));
Assert.Equal(span1.Intersection(span2), new TextSpan(10, 0));
Assert.Equal(span2.Intersection(span1), new TextSpan(10, 0));
}
示例6: TextSpanIntersection02
public void TextSpanIntersection02()
{
TextSpan span1 = new TextSpan(10, 10); // 10..20
TextSpan span2 = new TextSpan(5, 10); // 5..15
Assert.True(span1.IntersectsWith(span2));
Assert.True(span2.IntersectsWith(span1));
Assert.Equal(span1.Intersection(span2), new TextSpan(10, 5));
Assert.Equal(span2.Intersection(span1), new TextSpan(10, 5));
}
示例7: TextSpanIntersection01
public void TextSpanIntersection01()
{
TextSpan span1 = new TextSpan(10, 10); // 10..20
TextSpan span2 = new TextSpan(5, 2); // 5..7
Assert.False(span1.IntersectsWith(span2));
Assert.False(span2.IntersectsWith(span1));
Assert.Null(span1.Intersection(span2));
Assert.Null(span2.Intersection(span1));
}
示例8: TextSpan_IntersectsWithEmpty
public void TextSpan_IntersectsWithEmpty()
{
var empty = new TextSpan(SourceText.From(""), 1, 0);
Assert.True(empty.IntersectsWith(empty));
}
示例9: TextSpan_IntersectsWithSelf
public void TextSpan_IntersectsWithSelf()
{
var textSpan = new TextSpan(SourceText.From(""), 2, 4);
Assert.True(textSpan.IntersectsWith(textSpan));
}
示例10: TextSpan_IntersectsWithSelf
public void TextSpan_IntersectsWithSelf()
{
var textSpan = new TextSpan(null, 2, 4);
Assert.True(textSpan.IntersectsWith(textSpan));
}
示例11: GetDiagnosticsForSpanAsync
public override async Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsync(Document document, TextSpan range, CancellationToken cancellationToken)
{
var diagnostics = await GetDiagnosticsAsync(document.Project.Solution, document.Project.Id, document.Id, cancellationToken).ConfigureAwait(false);
return diagnostics.Where(d => range.IntersectsWith(d.TextSpan));
}
示例12: TryGetSubTextChange
private bool TryGetSubTextChange(
SourceText originalText, TextSpan visibleSpanInOriginalText,
string rightText, TextSpan spanInOriginalText, TextSpan spanInRightText, out TextChange textChange)
{
textChange = default(TextChange);
var visibleFirstLineInOriginalText = originalText.Lines.GetLineFromPosition(visibleSpanInOriginalText.Start);
var visibleLastLineInOriginalText = originalText.Lines.GetLineFromPosition(visibleSpanInOriginalText.End);
// skip easy case
// 1. things are out of visible span
if (!visibleSpanInOriginalText.IntersectsWith(spanInOriginalText))
{
return false;
}
// 2. there are no intersects
var snippetInRightText = rightText.Substring(spanInRightText.Start, spanInRightText.Length);
if (visibleSpanInOriginalText.Contains(spanInOriginalText) && visibleSpanInOriginalText.End != spanInOriginalText.End)
{
textChange = new TextChange(spanInOriginalText, snippetInRightText);
return true;
}
// okay, more complex case. things are intersecting boundaries.
var firstLineOfRightTextSnippet = snippetInRightText.GetFirstLineText();
var lastLineOfRightTextSnippet = snippetInRightText.GetLastLineText();
// there are 4 complex cases - these are all heuristic. not sure what better way I have. and the heristic is heavily based on
// text differ's behavior.
// 1. it is a single line
if (visibleFirstLineInOriginalText.LineNumber == visibleLastLineInOriginalText.LineNumber)
{
// don't do anything
return false;
}
// 2. replacement contains visible spans
if (spanInOriginalText.Contains(visibleSpanInOriginalText))
{
// header
// don't do anything
// body
textChange = new TextChange(
TextSpan.FromBounds(visibleFirstLineInOriginalText.EndIncludingLineBreak, visibleLastLineInOriginalText.Start),
snippetInRightText.Substring(firstLineOfRightTextSnippet.Length, snippetInRightText.Length - firstLineOfRightTextSnippet.Length - lastLineOfRightTextSnippet.Length));
// footer
// don't do anything
return true;
}
// 3. replacement intersects with start
if (spanInOriginalText.Start < visibleSpanInOriginalText.Start &&
visibleSpanInOriginalText.Start <= spanInOriginalText.End &&
spanInOriginalText.End < visibleSpanInOriginalText.End)
{
// header
// don't do anything
// body
if (visibleFirstLineInOriginalText.EndIncludingLineBreak <= spanInOriginalText.End)
{
textChange = new TextChange(
TextSpan.FromBounds(visibleFirstLineInOriginalText.EndIncludingLineBreak, spanInOriginalText.End),
snippetInRightText.Substring(firstLineOfRightTextSnippet.Length));
return true;
}
return false;
}
// 4. replacement intersects with end
if (visibleSpanInOriginalText.Start < spanInOriginalText.Start &&
spanInOriginalText.Start <= visibleSpanInOriginalText.End &&
visibleSpanInOriginalText.End <= spanInOriginalText.End)
{
// body
if (spanInOriginalText.Start <= visibleLastLineInOriginalText.Start)
{
textChange = new TextChange(
TextSpan.FromBounds(spanInOriginalText.Start, visibleLastLineInOriginalText.Start),
snippetInRightText.Substring(0, snippetInRightText.Length - lastLineOfRightTextSnippet.Length));
return true;
}
// footer
// don't do anything
return false;
}
// if it got hit, then it means there is a missing case
throw ExceptionUtilities.Unreachable;
}
示例13: FilterFormattedChanges
public IEnumerable<TextChange> FilterFormattedChanges(Document document, TextSpan span, IList<TextChange> changes)
{
var visualStudioWorkspace = document.Project.Solution.Workspace as VisualStudioWorkspaceImpl;
if (visualStudioWorkspace == null)
{
return changes;
}
var containedDocument = visualStudioWorkspace.GetHostDocument(document.Id) as ContainedDocument;
if (containedDocument == null)
{
return changes;
}
// in case of a venus, when format document command is issued, venus will call format API with each script block spans.
// in that case, we need to make sure formatter doesn't overstep other script blocks content. in actual format selection case,
// we need to format more than given selection otherwise, we will not adjust indentation of first token of the given selection.
foreach (var visibleSpan in containedDocument.GetEditorVisibleSpans())
{
if (visibleSpan != span)
{
continue;
}
return changes.Where(c => span.IntersectsWith(c.Span));
}
return changes;
}
示例14: TextSpanIntersectionEmpty03
public void TextSpanIntersectionEmpty03()
{
TextSpan span1 = new TextSpan(2, 5); // [2, 7)
TextSpan span2 = new TextSpan(7, 0); // [7, 0)
Assert.True(span1.IntersectsWith(span2));
Assert.True(span2.IntersectsWith(span1));
Assert.Equal(span1.Intersection(span2), new TextSpan(7, 0));
Assert.Equal(span2.Intersection(span1), new TextSpan(7, 0));
}
示例15: IsInSpan
private static bool IsInSpan(ref TextSpan span, TextSpan childSpan)
{
return span.OverlapsWith(childSpan)
// special case for zero-width tokens (OverlapsWith never returns true for these)
|| (childSpan.Length == 0 && span.IntersectsWith(childSpan));
}