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


C# SnapshotSpan.CreateTrackingSpan方法代码示例

本文整理汇总了C#中SnapshotSpan.CreateTrackingSpan方法的典型用法代码示例。如果您正苦于以下问题:C# SnapshotSpan.CreateTrackingSpan方法的具体用法?C# SnapshotSpan.CreateTrackingSpan怎么用?C# SnapshotSpan.CreateTrackingSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SnapshotSpan的用法示例。


在下文中一共展示了SnapshotSpan.CreateTrackingSpan方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateProjectionBuffer

        private static IProjectionBuffer CreateProjectionBuffer(
            IProjectionBufferFactoryService factoryService,
            IContentTypeRegistryService registryService,
            IEditorOptions editorOptions,
            ITextSnapshot snapshot,
            string separator,
            object suffixOpt,
            bool trim,
            params LineSpan[] exposedLineSpans)
        {
            var spans = new List<object>();
            if (exposedLineSpans.Length > 0)
            {
                if (exposedLineSpans[0].Start > 0 && !string.IsNullOrEmpty(separator))
                {
                    spans.Add(separator);
                    spans.Add(editorOptions.GetNewLineCharacter());
                }

                var snapshotSpanRanges = CreateSnapshotSpanRanges(snapshot, exposedLineSpans);
                var indentColumn = trim
                    ? DetermineIndentationColumn(editorOptions, snapshotSpanRanges.Flatten())
                    : 0;

                foreach (var snapshotSpanRange in snapshotSpanRanges)
                {
                    foreach (var snapshotSpan in snapshotSpanRange)
                    {
                        var line = snapshotSpan.Snapshot.GetLineFromPosition(snapshotSpan.Start);
                        var indentPosition = line.GetLineOffsetFromColumn(indentColumn, editorOptions) + line.Start;
                        var mappedSpan = new SnapshotSpan(snapshotSpan.Snapshot,
                            Span.FromBounds(indentPosition, snapshotSpan.End));

                        var trackingSpan = mappedSpan.CreateTrackingSpan(SpanTrackingMode.EdgeExclusive);

                        spans.Add(trackingSpan);

                        // Add a newline between every line.
                        if (snapshotSpan != snapshotSpanRange.Last())
                        {
                            spans.Add(editorOptions.GetNewLineCharacter());
                        }
                    }

                    // Add a separator between every set of lines.
                    if (snapshotSpanRange != snapshotSpanRanges.Last())
                    {
                        spans.Add(editorOptions.GetNewLineCharacter());
                        spans.Add(separator);
                        spans.Add(editorOptions.GetNewLineCharacter());
                    }
                }

                if (snapshot.GetLineNumberFromPosition(snapshotSpanRanges.Last().Last().End) < snapshot.LineCount - 1)
                {
                    spans.Add(editorOptions.GetNewLineCharacter());
                    spans.Add(separator);
                }
            }

            if (suffixOpt != null)
            {
                if (spans.Count >= 0)
                {
                    if (!separator.Equals(spans.Last()))
                    {
                        spans.Add(editorOptions.GetNewLineCharacter());
                        spans.Add(separator);
                    }

                    spans.Add(editorOptions.GetNewLineCharacter());
                }

                spans.Add(suffixOpt);
            }

            return factoryService.CreateProjectionBuffer(
                projectionEditResolver: null,
                sourceSpans: spans,
                options: ProjectionBufferOptions.None,
                contentType: registryService.GetContentType(ShaderPreviewContentType));
        }
开发者ID:tgjones,项目名称:HlslTools,代码行数:82,代码来源:IProjectionBufferFactoryServiceExtensions.cs

示例2: CreateProjectionBufferForBlockHeaders

            private ITextBuffer CreateProjectionBufferForBlockHeaders()
            {
                // We want to create a projection buffer that will show the block tags like so:
                //
                //      namespace N
                //          class C
                //              public void M()
                //
                // To do this, we grab the 'header' part of each block span and stich them 
                // all together one after the other.
                //
                // We consider hte 'header' to be from the start of the line containing the
                // block all the way to the end of the line, or the start of the collapsed
                // block region (whichever is closer).  That way, if you have multi-line
                // statement start (for example, with a multi-line if-expression) we'll only
                // take the first line.  In the case where we're cutting things off, we'll
                // put in a ... to indicate as such.

                var blockTags = GetBlockTags();

                var textSnapshot = blockTags[0].StatementSpan.Snapshot;

                // The list of mapping spans, ...'s and newlines that we'll build the 
                // projection buffer out of.
                var objects = new List<object>();

                for (var i = 0; i < blockTags.Count; i++)
                {
                    var blockTag = blockTags[i];
                    var fullStatementSpan = blockTag.StatementSpan;
                    
                    if (blockTag.Parent != null &&
                        textSnapshot.AreOnSameLine(fullStatementSpan.Start, blockTag.Parent.StatementSpan.Start))
                    {
                        // Ignore block tags on the same line as their parent.  We'll have already included
                        // the contents of the line when we added the parent tag, and the editor will crash
                        // if we create overlapping spans in the projection buffer.
                        continue;
                    }

                    if (i > 0)
                    {
                        objects.Add("\r\n");
                    }

                    var statementLine = textSnapshot.GetLineFromPosition(fullStatementSpan.Start);

                    var lineStart = statementLine.Start.Position;
                    var lineEnd = statementLine.End.Position;

                    var headerSpan = new SnapshotSpan(textSnapshot, Span.FromBounds(lineStart, lineEnd));
                    var mappingSpan = headerSpan.CreateTrackingSpan(SpanTrackingMode.EdgeExclusive);

                    objects.Add(mappingSpan);
                    if (lineEnd < blockTag.Span.Start)
                    {
                        // If we had to cut off the line, then add a ... to indicate as such.
                        objects.Add("...");
                    }
                }

                return _provider._projectionBufferFactoryService.CreateProjectionBuffer(
                    null, objects, ProjectionBufferOptions.None);
            }
开发者ID:lachbaer,项目名称:roslyn,代码行数:64,代码来源:BlockContextProvider.cs


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