当前位置: 首页>>代码示例>>C#>>正文


C# TextSpan.IntersectsWith方法代码示例

本文整理汇总了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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:27,代码来源:Controller_CaretPositionChanged.cs

示例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;
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:18,代码来源:CSharpExtractInterfaceService.cs

示例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;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:19,代码来源:CSharpExtractInterfaceService.cs

示例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));
            }
        }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:36,代码来源:CodeFixService.cs

示例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));
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:TextSpanTest.cs

示例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));
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:TextSpanTest.cs

示例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));
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:TextSpanTest.cs

示例8: TextSpan_IntersectsWithEmpty

 public void TextSpan_IntersectsWithEmpty()
 {
     var empty = new TextSpan(SourceText.From(""), 1, 0);
     Assert.True(empty.IntersectsWith(empty));
 }
开发者ID:tgjones,项目名称:HlslTools,代码行数:5,代码来源:TextSpanTests.cs

示例9: TextSpan_IntersectsWithSelf

 public void TextSpan_IntersectsWithSelf()
 {
     var textSpan = new TextSpan(SourceText.From(""), 2, 4);
     Assert.True(textSpan.IntersectsWith(textSpan));
 }
开发者ID:tgjones,项目名称:HlslTools,代码行数:5,代码来源:TextSpanTests.cs

示例10: TextSpan_IntersectsWithSelf

 public void TextSpan_IntersectsWithSelf()
 {
     var textSpan = new TextSpan(null, 2, 4);
     Assert.True(textSpan.IntersectsWith(textSpan));
 }
开发者ID:davidlee80,项目名称:HlslTools,代码行数:5,代码来源:TextSpanTests.cs

示例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));
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:5,代码来源:DiagnosticIncrementalAnalyzer.cs

示例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;
        }
开发者ID:paul1956,项目名称:roslyn,代码行数:98,代码来源:ContainedDocument.cs

示例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;
            }
开发者ID:GloryChou,项目名称:roslyn,代码行数:29,代码来源:VisualStudioFormattingRuleFactoryServiceFactory.cs

示例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));
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:TextSpanTest.cs

示例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));
 }
开发者ID:riversky,项目名称:roslyn,代码行数:6,代码来源:SyntaxNode.Iterators.cs


注:本文中的TextSpan.IntersectsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。