Example #1
0
        internal override void OnModelUpdated(Model modelOpt, bool updateController)
        {
            AssertIsForeground();

            if (updateController)
            {
                if (modelOpt == null)
                {
                    this.StopModelComputation();
                }
                else
                {
                    var triggerSpan = modelOpt.GetCurrentSpanInView(this.TextView.TextSnapshot);

                    // We want the span to actually only go up to the caret.  So get the expected span
                    // and then update its end point accordingly.
                    var updatedSpan = new SnapshotSpan(triggerSpan.Snapshot, Span.FromBounds(
                                                           triggerSpan.Start,
                                                           Math.Max(Math.Min(triggerSpan.End, GetCaretPointInViewBuffer().Position), triggerSpan.Start)));

                    var trackingSpan = updatedSpan.CreateTrackingSpan(SpanTrackingMode.EdgeInclusive);

                    this.sessionOpt.PresenterSession.PresentItems(
                        trackingSpan, modelOpt.Items, modelOpt.SelectedItem, modelOpt.SelectedParameter);
                }
            }

            ModelUpdated?.Invoke(this, new ModelUpdatedEventsArgs(modelOpt));
        }
Example #2
0
            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++)
                {
                    if (i > 0)
                    {
                        objects.Add("\r\n");
                    }

                    var blockTag          = blockTags[i];
                    var fullStatementSpan = blockTag.StatementSpan;
                    var collapseSpan      = blockTag.Span;

                    var statementLine = textSnapshot.GetLineFromPosition(blockTag.StatementSpan.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 (statementLine.End.Position < collapseSpan.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));
            }
        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(RoslynPreviewContentType)
                       ));
        }
        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));
        }
Example #5
0
            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);
            }