public ProjectionTextViewModel( IProjectionBufferFactoryService projectionBufferFactoryService, IContentTypeRegistryService contentTypeRegistryService, ITextDataModel dataModel) { DataModel = dataModel; // Initially, populate projection buffer with single span covering entire data buffer. // We'll update this before the view actually becomes visible. var snapshot = dataModel.DataBuffer.CurrentSnapshot; var span = snapshot.CreateTrackingSpan( new Span(0, snapshot.Length), SpanTrackingMode.EdgeExclusive); var projectionContentType = contentTypeRegistryService.GetContentType(ContentTypeNames.ShaderLabProjectionContentType); var projectionBuffer = projectionBufferFactoryService.CreateProjectionBuffer( null, new List <object> { span }, ProjectionBufferOptions.None, projectionContentType); EditBuffer = VisualBuffer = projectionBuffer; dataModel.DataBuffer.Properties.GetOrCreateSingletonProperty(() => projectionBuffer); Properties = new PropertyCollection(); }
public TemplateProjectionBuffer(IContentTypeRegistryService contentRegistry, IProjectionBufferFactoryService bufferFactory, ITextBuffer diskBuffer, IBufferGraphFactoryService bufferGraphFactory, IContentType contentType) { _diskBuffer = diskBuffer; _contentRegistry = contentRegistry; _contentType = contentType; _projBuffer = bufferFactory.CreateProjectionBuffer( this, new object[0], ProjectionBufferOptions.None ); _projBuffer.Properties.AddProperty(typeof(TemplateProjectionBuffer), this); _bufferGraph = bufferGraphFactory.CreateBufferGraph(_projBuffer); _htmlBuffer = CreateHtmlBuffer(bufferFactory); _templateBuffer = CreateTemplateBuffer(bufferFactory); IVsTextBuffer buffer; if (_diskBuffer.Properties.TryGetProperty <IVsTextBuffer>(typeof(IVsTextBuffer), out buffer)) { // keep the Venus HTML classifier happy - it wants to find a site via IVsTextBuffer _htmlBuffer.Properties.AddProperty(typeof(IVsTextBuffer), buffer); } var reader = new SnapshotSpanSourceCodeReader(new SnapshotSpan(diskBuffer.CurrentSnapshot, new Span(0, diskBuffer.CurrentSnapshot.Length))); UpdateTemplateSpans(reader); }
private IProjectionBuffer CreateProjectionBuffer(IProjectionBufferFactoryService bufferFactory) { var res = bufferFactory.CreateProjectionBuffer(this, new object[0], ProjectionBufferOptions.None); res.Properties.AddProperty(typeof(PhpProjectionBuffer), this); return(res); }
public ProjectionBufferManager(ITextBuffer diskBuffer, IProjectionBufferFactoryService projectionBufferFactoryService, IContentTypeRegistryService contentTypeRegistryService, string topLevelContentTypeName, string secondaryContentTypeName) { _diskBuffer = diskBuffer; _contentTypeRegistryService = contentTypeRegistryService; var contentType = _contentTypeRegistryService.GetContentType(topLevelContentTypeName); ViewBuffer = projectionBufferFactoryService.CreateProjectionBuffer(null, new List <object>(0), ProjectionBufferOptions.None, contentType); contentType = _contentTypeRegistryService.GetContentType(secondaryContentTypeName); ContainedLanguageBuffer = projectionBufferFactoryService.CreateProjectionBuffer(null, new List <object>(0), ProjectionBufferOptions.WritableLiteralSpans, contentType); ServiceManager.AddService <IProjectionBufferManager>(this, _diskBuffer); }
public ProjectionBufferManager(ITextBuffer diskBuffer, IProjectionBufferFactoryService projectionBufferFactoryService, IContentTypeRegistryService contentTypeRegistryService, ICoreShell coreShell, string topLevelContentTypeName, string secondaryContentTypeName) { DiskBuffer = diskBuffer; _contentTypeRegistryService = contentTypeRegistryService; var contentType = _contentTypeRegistryService.GetContentType(topLevelContentTypeName); ViewBuffer = projectionBufferFactoryService.CreateProjectionBuffer(null, new List<object>(0), ProjectionBufferOptions.None, contentType); contentType = _contentTypeRegistryService.GetContentType(secondaryContentTypeName); ContainedLanguageBuffer = projectionBufferFactoryService.CreateProjectionBuffer(null, new List<object>(0), ProjectionBufferOptions.WritableLiteralSpans, contentType); ServiceManager.AddService<IProjectionBufferManager>(this, DiskBuffer, coreShell); ServiceManager.AddService<IProjectionBufferManager>(this, ViewBuffer, coreShell); }
public static IProjectionBuffer CreatePreviewProjectionBuffer( this IProjectionBufferFactoryService factoryService, IList <object> sourceSpans, IContentTypeRegistryService registryService) { return(factoryService.CreateProjectionBuffer( projectionEditResolver: null, sourceSpans: sourceSpans, options: ProjectionBufferOptions.None, contentType: registryService.GetContentType(RoslynPreviewContentType))); }
public ProjectionBufferManager(ITextBuffer diskBuffer, IProjectionBufferFactoryService projectionBufferFactoryService, IContentTypeRegistryService contentTypeRegistryService, string secondaryContentTypeName) { DiskBuffer = diskBuffer; _contentTypeRegistryService = contentTypeRegistryService; var snapshot = diskBuffer.CurrentSnapshot; var shaderLabSyntaxTree = SyntaxFactory.ParseUnitySyntaxTree(new Text.VisualStudioSourceText(snapshot, null, true)); var cgBlockVisitor = new CgBlockVisitor(); //cgBlockVisitor.Visit(shaderLabSyntaxTree.Root); var cgBlockSpans = cgBlockVisitor.CgBlockSpans; var dataBufferSpans = new List <object>(); var secondaryContentType = _contentTypeRegistryService.GetContentType(secondaryContentTypeName); var primaryIndex = 0; foreach (var cgBlockSpan in cgBlockSpans) { var primarySpan = Span.FromBounds(primaryIndex, cgBlockSpan.Start); if (!primarySpan.IsEmpty) { dataBufferSpans.Add(snapshot.CreateTrackingSpan(primarySpan, SpanTrackingMode.EdgeExclusive)); } var elisionBuffer = projectionBufferFactoryService.CreateElisionBuffer(null, new NormalizedSnapshotSpanCollection(new SnapshotSpan(snapshot, cgBlockSpan)), ElisionBufferOptions.None, secondaryContentType); dataBufferSpans.Add(elisionBuffer.CurrentSnapshot.CreateTrackingSpan(0, elisionBuffer.CurrentSnapshot.Length, SpanTrackingMode.EdgeInclusive)); primaryIndex = cgBlockSpan.End; } // Last span. { var primarySpan = Span.FromBounds(primaryIndex, snapshot.Length); if (!primarySpan.IsEmpty) { dataBufferSpans.Add(snapshot.CreateTrackingSpan(primarySpan, SpanTrackingMode.EdgeExclusive)); } } ViewBuffer = projectionBufferFactoryService.CreateProjectionBuffer(null, dataBufferSpans, ProjectionBufferOptions.None); DiskBuffer.Properties.AddProperty(typeof(IProjectionBufferManager), this); ViewBuffer.Properties.AddProperty(typeof(IProjectionBufferManager), this); }
private IProjectionBuffer CreateTemplateBuffer(IProjectionBufferFactoryService bufferFactory) { var res = bufferFactory.CreateProjectionBuffer( this, new object[] { _diskBuffer.CurrentSnapshot.CreateTrackingSpan( 0, _diskBuffer.CurrentSnapshot.Length, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward ) }, ProjectionBufferOptions.None, _contentRegistry.GetContentType(TemplateContentType.ContentTypeName) ); res.Properties.AddProperty(typeof(TemplateProjectionBuffer), this); return(res); }
private ITextBuffer CreateTrimmedProjectionBuffer(ITextBuffer elisionBuffer) { // The elision buffer is too long. We've already trimmed it, but now we want to add // a "..." to it. We do that by creating a projection of both the elision buffer and // a new text buffer wrapping the ellipsis. var elisionSpan = new SnapshotSpan(elisionBuffer.CurrentSnapshot, 0, elisionBuffer.CurrentSnapshot.Length); var sourceSpans = new List <object>() { elisionSpan.Snapshot.CreateTrackingSpan(elisionSpan, SpanTrackingMode.EdgeExclusive), "..." }; var projectionBuffer = _projectionBufferFactoryService.CreateProjectionBuffer( projectionEditResolver: null, sourceSpans: sourceSpans, options: ProjectionBufferOptions.None); return(projectionBuffer); }
public InteractiveWindow( IInteractiveWindowEditorFactoryService host, IContentTypeRegistryService contentTypeRegistry, ITextBufferFactoryService bufferFactory, IProjectionBufferFactoryService projectionBufferFactory, IEditorOperationsFactoryService editorOperationsFactory, ITextEditorFactoryService editorFactory, IIntellisenseSessionStackMapService intellisenseSessionStackMap, ISmartIndentationService smartIndenterService, IInteractiveEvaluator evaluator) { if (evaluator == null) { throw new ArgumentNullException(nameof(evaluator)); } _dangerous_uiOnly = new UIThreadOnly(this, host); this.Properties = new PropertyCollection(); _history = new History(); _intellisenseSessionStackMap = intellisenseSessionStackMap; _smartIndenterService = smartIndenterService; var textContentType = contentTypeRegistry.GetContentType("text"); var replContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveContentTypeName); var replOutputContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveOutputContentTypeName); _outputBuffer = bufferFactory.CreateTextBuffer(replOutputContentType); _standardInputBuffer = bufferFactory.CreateTextBuffer(); var projBuffer = projectionBufferFactory.CreateProjectionBuffer( new EditResolver(this), Array.Empty<object>(), ProjectionBufferOptions.None, replContentType); // we need to set IReplPromptProvider property before TextViewHost is instantiated so that ReplPromptTaggerProvider can bind to it projBuffer.Properties.AddProperty(typeof(InteractiveWindow), this); _projectionBuffer = projBuffer; _dangerous_uiOnly.AppendNewOutputProjectionBuffer(); // Constructor runs on UI thread. projBuffer.Changed += new EventHandler<TextContentChangedEventArgs>(ProjectionBufferChanged); var roleSet = editorFactory.CreateTextViewRoleSet( PredefinedTextViewRoles.Analyzable, PredefinedTextViewRoles.Editable, PredefinedTextViewRoles.Interactive, PredefinedTextViewRoles.Zoomable, PredefinedInteractiveTextViewRoles.InteractiveTextViewRole); _textView = host.CreateTextView(this, projBuffer, roleSet); _textView.Caret.PositionChanged += CaretPositionChanged; _textView.Options.SetOptionValue(DefaultTextViewHostOptions.HorizontalScrollBarId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.OutliningMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.GlyphMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStyles.WordWrap); _lineBreakString = _textView.Options.GetNewLineCharacter(); _dangerous_uiOnly.EditorOperations = editorOperationsFactory.GetEditorOperations(_textView); // Constructor runs on UI thread. _buffer = new OutputBuffer(this); _outputWriter = new InteractiveWindowWriter(this, spans: null); SortedSpans errorSpans = new SortedSpans(); _errorOutputWriter = new InteractiveWindowWriter(this, errorSpans); OutputClassifierProvider.AttachToBuffer(_outputBuffer, errorSpans); RequiresUIThread(); evaluator.CurrentWindow = this; _evaluator = evaluator; }
public static IProjectionBuffer CreateProjectionBufferWithoutIndentation( this IProjectionBufferFactoryService factoryService, IEditorOptions editorOptions, IContentType?contentType, IEnumerable <SnapshotSpan> exposedSpans ) { var spans = new NormalizedSnapshotSpanCollection(exposedSpans); if (spans.Count > 0) { // BUG(6335): We have to make sure that the spans refer to the current snapshot of // the buffer. var buffer = spans.First().Snapshot.TextBuffer; var currentSnapshot = buffer.CurrentSnapshot; spans = new NormalizedSnapshotSpanCollection( spans.Select( s => s.TranslateTo(currentSnapshot, SpanTrackingMode.EdgeExclusive) ) ); } contentType ??= factoryService.ProjectionContentType; var projectionBuffer = factoryService.CreateProjectionBuffer( projectionEditResolver: null, sourceSpans: Array.Empty <object>(), options: ProjectionBufferOptions.None, contentType: contentType ); if (spans.Count > 0) { var finalSpans = new List <object>(); // We need to figure out the shorted indentation level of the exposed lines. We'll // then remove that indentation from all lines. var indentationColumn = DetermineIndentationColumn(editorOptions, spans); foreach (var span in spans) { var snapshot = span.Snapshot; var startLineNumber = snapshot.GetLineNumberFromPosition(span.Start); var endLineNumber = snapshot.GetLineNumberFromPosition(span.End); for ( var lineNumber = startLineNumber; lineNumber <= endLineNumber; lineNumber++ ) { // Compute the span clamped to this line var line = snapshot.GetLineFromLineNumber(lineNumber); var finalSpanStart = Math.Max(line.Start, span.Start); var finalSpanEnd = Math.Min(line.EndIncludingLineBreak, span.End); // We'll only offset if our span doesn't already start at the start of the line. See the similar exclusion in // DetermineIndentationColumn that this matches. if (line.Start == finalSpanStart) { finalSpanStart += line.GetLineOffsetFromColumn( indentationColumn, editorOptions ); // Paranoia: what if the indentation reversed our ordering? if (finalSpanStart > finalSpanEnd) { finalSpanStart = finalSpanEnd; } } // We don't expect edits to happen while this projection buffer is active. We'll choose EdgeExclusive so // if they do we don't end up in any cases where there is overlapping source spans. finalSpans.Add( snapshot.CreateTrackingSpan( Span.FromBounds(finalSpanStart, finalSpanEnd), SpanTrackingMode.EdgeExclusive ) ); } } projectionBuffer.InsertSpans(0, finalSpans); } return(projectionBuffer); }
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) )); }
public InteractiveWindow( IInteractiveWindowEditorFactoryService host, IContentTypeRegistryService contentTypeRegistry, ITextBufferFactoryService bufferFactory, IProjectionBufferFactoryService projectionBufferFactory, IEditorOperationsFactoryService editorOperationsFactory, ITextEditorFactoryService editorFactory, IRtfBuilderService rtfBuilderService, IIntellisenseSessionStackMapService intellisenseSessionStackMap, ISmartIndentationService smartIndenterService, IInteractiveEvaluator evaluator) { if (evaluator == null) { throw new ArgumentNullException(nameof(evaluator)); } _dangerous_uiOnly = new UIThreadOnly(this, host); this.Properties = new PropertyCollection(); _history = new History(); _intellisenseSessionStackMap = intellisenseSessionStackMap; _smartIndenterService = smartIndenterService; var replContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveContentTypeName); var replOutputContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveOutputContentTypeName); _outputBuffer = bufferFactory.CreateTextBuffer(replOutputContentType); _standardInputBuffer = bufferFactory.CreateTextBuffer(); _promptBuffer = bufferFactory.CreateTextBuffer(); _secondaryPromptBuffer = bufferFactory.CreateTextBuffer(); _standardInputPromptBuffer = bufferFactory.CreateTextBuffer(); _outputLineBreakBuffer = bufferFactory.CreateTextBuffer(); var projBuffer = projectionBufferFactory.CreateProjectionBuffer( new EditResolver(this), Array.Empty <object>(), ProjectionBufferOptions.None, replContentType); projBuffer.Properties.AddProperty(typeof(InteractiveWindow), this); _projectionBuffer = projBuffer; _dangerous_uiOnly.AppendNewOutputProjectionBuffer(); // Constructor runs on UI thread. projBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(ProjectionBufferChanged); var roleSet = editorFactory.CreateTextViewRoleSet( PredefinedTextViewRoles.Analyzable, PredefinedTextViewRoles.Editable, PredefinedTextViewRoles.Interactive, PredefinedTextViewRoles.Zoomable, PredefinedInteractiveTextViewRoles.InteractiveTextViewRole); _textView = host.CreateTextView(this, projBuffer, roleSet); _textView.Caret.PositionChanged += CaretPositionChanged; _textView.Options.SetOptionValue(DefaultTextViewHostOptions.HorizontalScrollBarId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.OutliningMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewHostOptions.GlyphMarginId, false); _textView.Options.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStyles.WordWrap); _lineBreakString = _textView.Options.GetNewLineCharacter(); _dangerous_uiOnly.EditorOperations = editorOperationsFactory.GetEditorOperations(_textView); // Constructor runs on UI thread. _buffer = new OutputBuffer(this); _outputWriter = new InteractiveWindowWriter(this, spans: null); SortedSpans errorSpans = new SortedSpans(); _errorOutputWriter = new InteractiveWindowWriter(this, errorSpans); OutputClassifierProvider.AttachToBuffer(_outputBuffer, errorSpans); _rtfBuilderService = rtfBuilderService; RequiresUIThread(); evaluator.CurrentWindow = this; _evaluator = evaluator; }
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)); }
public UIThreadOnly( InteractiveWindow window, IInteractiveWindowEditorFactoryService factory, IContentTypeRegistryService contentTypeRegistry, ITextBufferFactoryService bufferFactory, IProjectionBufferFactoryService projectionBufferFactory, IEditorOperationsFactoryService editorOperationsFactory, ITextEditorFactoryService editorFactory, IRtfBuilderService rtfBuilderService, IIntellisenseSessionStackMapService intellisenseSessionStackMap, ISmartIndentationService smartIndenterService, IInteractiveEvaluator evaluator, IWaitIndicator waitIndicator) { _window = window; _factory = factory; _rtfBuilderService = (IRtfBuilderService2)rtfBuilderService; _intellisenseSessionStackMap = intellisenseSessionStackMap; _smartIndenterService = smartIndenterService; _waitIndicator = waitIndicator; Evaluator = evaluator; var replContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveContentTypeName); var replOutputContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveOutputContentTypeName); OutputBuffer = bufferFactory.CreateTextBuffer(replOutputContentType); StandardInputBuffer = bufferFactory.CreateTextBuffer(); _inertType = bufferFactory.InertContentType; _projectionBuffer = projectionBufferFactory.CreateProjectionBuffer( new EditResolver(window), Array.Empty<object>(), ProjectionBufferOptions.None, replContentType); _projectionBuffer.Properties.AddProperty(typeof(InteractiveWindow), window); AppendNewOutputProjectionBuffer(); _projectionBuffer.Changed += new EventHandler<TextContentChangedEventArgs>(ProjectionBufferChanged); var roleSet = editorFactory.CreateTextViewRoleSet( PredefinedTextViewRoles.Analyzable, PredefinedTextViewRoles.Editable, PredefinedTextViewRoles.Interactive, PredefinedTextViewRoles.Zoomable, PredefinedInteractiveTextViewRoles.InteractiveTextViewRole); TextView = factory.CreateTextView(window, _projectionBuffer, roleSet); TextView.Caret.PositionChanged += CaretPositionChanged; var options = TextView.Options; options.SetOptionValue(DefaultTextViewHostOptions.HorizontalScrollBarId, true); options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false); options.SetOptionValue(DefaultTextViewHostOptions.OutliningMarginId, false); options.SetOptionValue(DefaultTextViewHostOptions.GlyphMarginId, false); options.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStyles.None); _lineBreakString = options.GetNewLineCharacter(); EditorOperations = editorOperationsFactory.GetEditorOperations(TextView); _buffer = new OutputBuffer(window); OutputWriter = new InteractiveWindowWriter(window, spans: null); SortedSpans errorSpans = new SortedSpans(); ErrorOutputWriter = new InteractiveWindowWriter(window, errorSpans); OutputClassifierProvider.AttachToBuffer(OutputBuffer, errorSpans); }
// Code taken from https://github.com/dotnet/roslyn/blob/master/src/EditorFeatures/Core/Shared/Extensions/IProjectionBufferFactoryServiceExtensions.cs public static IProjectionBuffer CreateProjectionBufferWithoutIndentation( this IProjectionBufferFactoryService projectionBufferFactoryService, IEditorOptions editorOptions, ITextSnapshot textSnapshot, string separator, 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()); } IList <IList <SnapshotSpan> > snapshotSpanRanges = CreateSnapshotSpanRanges(textSnapshot, exposedLineSpans); int indentColumn = DetermineIndentationColumn(editorOptions, snapshotSpanRanges.SelectMany(s => s)); foreach (IList <SnapshotSpan> snapshotSpanRange in snapshotSpanRanges) { foreach (SnapshotSpan snapshotSpan in snapshotSpanRange) { ITextSnapshotLine line = snapshotSpan.Snapshot.GetLineFromPosition(snapshotSpan.Start); int indentPosition = line.GetText().GetLineOffsetFromColumn(indentColumn, editorOptions.GetTabSize()) + line.Start; var mappedSpan = new SnapshotSpan(snapshotSpan.Snapshot, Span.FromBounds(indentPosition, snapshotSpan.End)); ITrackingSpan trackingSpan = mappedSpan.Snapshot.CreateTrackingSpan(mappedSpan, 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 (textSnapshot.GetLineNumberFromPosition(snapshotSpanRanges.Last().Last().End) < textSnapshot.LineCount - 1) { spans.Add(editorOptions.GetNewLineCharacter()); spans.Add(separator); } } return(projectionBufferFactoryService.CreateProjectionBuffer( projectionEditResolver: null, sourceSpans: spans, options: ProjectionBufferOptions.None, contentType: textSnapshot.ContentType)); }