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; }
internal InteractiveWindowWriter(IInteractiveWindow window, SortedSpans spans) { Debug.Assert(window != null); _window = window; _spans = spans; }
public void CheckOverlap() { var spans = new SortedSpans(); // no overlap with empty span list Assert.Empty(spans.GetOverlap(new Span(0, 10))); // add span [10, 20) spans.Add(new Span(10, 10)); // no overlap with [0, 5) Assert.Empty(spans.GetOverlap(new Span(0, 5))); // no overlap with [25, 30) Assert.Empty(spans.GetOverlap(new Span(25, 5))); // no overlap with [0, 10) Assert.Empty(spans.GetOverlap(new Span(0, 10))); // no overlap with [20, 30) Assert.Empty(spans.GetOverlap(new Span(20, 10))); // overlap with [5, 15) Assert.Equal(new Span[] { new Span(10, 5) }, spans.GetOverlap(new Span(5, 10))); // overlap with [0, 11) Assert.Equal(new Span[] { new Span(10, 1) }, spans.GetOverlap(new Span(0, 11))); // overlap with [15, 25) Assert.Equal(new Span[] { new Span(15, 5) }, spans.GetOverlap(new Span(15, 10))); // overlap with [11, 15] Assert.Equal(new Span[] { new Span(11, 5) }, spans.GetOverlap(new Span(11, 5))); // overlap with [10, 20) Assert.Equal(new Span[] { new Span(10, 10) }, spans.GetOverlap(new Span(10, 10))); // overlap with [0, 30) Assert.Equal(new Span[] { new Span(10, 10) }, spans.GetOverlap(new Span(0, 30))); // no overlap with [0, 0] Assert.Empty(spans.GetOverlap(new Span(0, 0))); // no overlap with [10, 10] Assert.Empty(spans.GetOverlap(new Span(10, 0))); // no overlap with [15, 15] Assert.Empty(spans.GetOverlap(new Span(15, 0))); // now has both [10, 20) and [30, 40) spans.Add(new Span(30, 10)); // no overlap with [20, 30) Assert.Empty(spans.GetOverlap(new Span(20, 10))); // no overlap with [0, 10) Assert.Empty(spans.GetOverlap(new Span(0, 10))); // no overlap with [40, 50) Assert.Empty(spans.GetOverlap(new Span(40, 10))); // overlap with [0, 15) Assert.Equal(new Span[] { new Span(10, 5) }, spans.GetOverlap(new Span(0, 15))); // overlap with [20, 35) Assert.Equal(new Span[] { new Span(30, 5) }, spans.GetOverlap(new Span(20, 15))); // overlap with [0, 35) Assert.Equal(new Span[] { new Span(10, 10), new Span(30, 5) }, spans.GetOverlap(new Span(0, 35))); // overlap with [15, 35) Assert.Equal(new Span[] { new Span(15, 5), new Span(30, 5) }, spans.GetOverlap(new Span(15, 20))); // overlap with [15, 50) Assert.Equal(new Span[] { new Span(15, 5), new Span(30, 10) }, spans.GetOverlap(new Span(15, 35))); // overlap with [0, 25) Assert.Equal(new Span[] { new Span(10, 10) }, spans.GetOverlap(new Span(0, 25))); // overlap with [25, 45) Assert.Equal(new Span[] { new Span(30, 10) }, spans.GetOverlap(new Span(25, 20))); // overlap with [0, 50) Assert.Equal(new Span[] { new Span(10, 10), new Span(30, 10) }, spans.GetOverlap(new Span(0, 50))); }
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); }
internal static void AttachToBuffer(ITextBuffer buffer, SortedSpans spans) { buffer.Properties[s_textBufferPropertyKey] = spans; }