public ITagAggregator <T> CreateTagAggregator <T>(ITextBuffer textBuffer, TagAggregatorOptions options) where T : ITag
 {
     if (textBuffer == null)
     {
         throw new ArgumentNullException(nameof(textBuffer));
     }
     return(new TextBufferTagAggregator <T>(taggerFactory, bufferGraphFactoryService.CreateBufferGraph(textBuffer), textBuffer, options));
 }
Esempio n. 2
0
        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);
        }
        public PhpProjectionBuffer(
            IContentTypeRegistryService contentRegistry,
            IProjectionBufferFactoryService bufferFactory,
            IBufferTagAggregatorFactoryService bufferTagAggregatorFactory,
            ITextBuffer diskBuffer,
            IBufferGraphFactoryService bufferGraphFactory,
            IContentType contentType)
        {
            _diskBuffer      = diskBuffer;
            _contentRegistry = contentRegistry;
            _contentType     = contentType;

            _projBuffer     = CreateProjectionBuffer(bufferFactory);
            _htmlBuffer     = CreateHtmlBuffer(bufferFactory);
            _templateBuffer = CreateTemplateBuffer(bufferFactory);

            _bufferGraph = bufferGraphFactory.CreateBufferGraph(_projBuffer);

            _contentTypeTagger              = bufferTagAggregatorFactory.CreateTagAggregator <ContentTypeTag>(_diskBuffer);
            _contentTypeTagger.TagsChanged += HandleContentTypeTagsChanged;

            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);
            }

            HandleContentTypeTagsChanged();
        }
        private static SnapshotSpan MapTo(IBufferGraphFactoryService bufferGraphFactoryService, SnapshotSpan span, ITextSnapshot snapshot, SpanTrackingMode spanTrackingMode)
        {
            if (span.Snapshot.TextBuffer == snapshot.TextBuffer)
                return span.TranslateTo(snapshot, spanTrackingMode);

            var graph = bufferGraphFactoryService.CreateBufferGraph(snapshot.TextBuffer);
            var mappingSpan = graph.CreateMappingSpan(span, spanTrackingMode);
            var mapped = mappingSpan.GetSpans(snapshot);
            if (mapped.Count == 1)
                return mapped[0];

            return new SnapshotSpan(mapped[0].Start, mapped[mapped.Count - 1].End);
        }
Esempio n. 5
0
        internal static TSLParser GetParser(ITextBuffer buffer)
        {
            Debug.Assert(Ready);
            IBufferGraph bufferGraph = null;

            bufferGraph = buffer.Properties.GetOrCreateSingletonProperty <IBufferGraph>(() =>
            {
                return(_bufferGraphFactory.CreateBufferGraph(buffer));
            });
            var parser = buffer.Properties.GetOrCreateSingletonProperty <TSLParser>(() =>
            {
                return(new TSLParser(buffer, bufferGraph));
            });

            return(parser);
        }
Esempio n. 6
0
        private static SnapshotSpan MapTo(IBufferGraphFactoryService bufferGraphFactoryService, SnapshotSpan span, ITextSnapshot snapshot, SpanTrackingMode spanTrackingMode)
        {
            if (span.Snapshot.TextBuffer == snapshot.TextBuffer)
            {
                return(span.TranslateTo(snapshot, spanTrackingMode));
            }

            var graph       = bufferGraphFactoryService.CreateBufferGraph(snapshot.TextBuffer);
            var mappingSpan = graph.CreateMappingSpan(span, spanTrackingMode);
            var mapped      = mappingSpan.GetSpans(snapshot);

            if (mapped.Count == 1)
            {
                return(mapped[0]);
            }

            return(new SnapshotSpan(mapped[0].Start, mapped[mapped.Count - 1].End));
        }
        private SnapshotSpan MapTo(SnapshotSpan span, ITextSnapshot snapshot, SpanTrackingMode spanTrackingMode)
        {
            if (span.Snapshot.TextBuffer == snapshot.TextBuffer)
            {
                return(span.TranslateTo(snapshot, spanTrackingMode));
            }

            IBufferGraph graph       = _bufferGraphFactoryService.CreateBufferGraph(snapshot.TextBuffer);
            IMappingSpan mappingSpan = graph.CreateMappingSpan(span, spanTrackingMode);
            NormalizedSnapshotSpanCollection mapped = mappingSpan.GetSpans(snapshot);

            if (mapped.Count == 1)
            {
                return(mapped[0]);
            }

            return(new SnapshotSpan(mapped[0].Start, mapped[mapped.Count - 1].End));
        }
        internal virtual bool TryGetWorkspaceFromProjectionBuffer(ITextBuffer textBuffer, out Workspace workspace)
        {
            var graph = _bufferGraphService.CreateBufferGraph(textBuffer);
            var projectedCSharpBuffer = graph.GetTextBuffers(buffer => buffer.ContentType.IsOfType("CSharp")).FirstOrDefault();

            if (projectedCSharpBuffer is null)
            {
                workspace = null;
                return(false);
            }

            workspace = projectedCSharpBuffer.GetWorkspace();
            if (workspace is null)
            {
                // Couldn't resolve a workspace for the projected csharp buffer.
                return(false);
            }

            return(true);
        }
        public override bool TryGetFromDocument(TextDocument document, out ITextBuffer textBuffer)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            textBuffer = null;

            if (!document.TryGetText(out var sourceText))
            {
                // Could not retrieve source text from the document. We have no way have locating an ITextBuffer.
                return(false);
            }

            var         container = sourceText.Container;
            ITextBuffer buffer;

            try
            {
                buffer = container.GetTextBuffer();
            }
            catch (ArgumentException)
            {
                // The source text container was not built from an ITextBuffer.
                return(false);
            }

            var bufferGraph = _bufferGraphService.CreateBufferGraph(buffer);
            var razorBuffer = bufferGraph.GetRazorBuffers().FirstOrDefault();

            if (razorBuffer == null)
            {
                // Could not find a text buffer associated with the text document.
                return(false);
            }

            textBuffer = razorBuffer;
            return(true);
        }
        private bool TrySetContext(
            bool isImmediateWindow)
        {
            // Get the workspace, and from there, the solution and document containing this buffer.
            // If there's an ExternalSource, we won't get a document. Give up in that case.
            Document document = ContextBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();

            if (document == null)
            {
                _projectionBuffer       = null;
                _debuggerTextView       = null;
                _workspace              = null;
                _immediateWindowContext = null;
                return(false);
            }

            var solution = document.Project.Solution;

            // Get the appropriate ITrackingSpan for the window the user is typing in
            var viewSnapshot = _textView.TextSnapshot;

            _immediateWindowContext = null;
            var debuggerMappedSpan = isImmediateWindow
                ? CreateImmediateWindowProjectionMapping(document, out _immediateWindowContext)
                : viewSnapshot.CreateFullTrackingSpan(SpanTrackingMode.EdgeInclusive);

            // Wrap the original ContextBuffer in a projection buffer that we can make read-only
            this.ContextBuffer = this.ProjectionBufferFactoryService.CreateProjectionBuffer(null,
                                                                                            new object[] { this.ContextBuffer.CurrentSnapshot.CreateFullTrackingSpan(SpanTrackingMode.EdgeInclusive) }, ProjectionBufferOptions.None, _contentType);

            // Make projection readonly so we can't edit it by mistake.
            using (var regionEdit = this.ContextBuffer.CreateReadOnlyRegionEdit())
            {
                regionEdit.CreateReadOnlyRegion(new Span(0, this.ContextBuffer.CurrentSnapshot.Length), SpanTrackingMode.EdgeInclusive, EdgeInsertionMode.Deny);
                regionEdit.Apply();
            }

            // Adjust the context point to ensure that the right information is in scope.
            // For example, we may need to move the point to the end of the last statement in a method body
            // in order to be able to access all local variables.
            var contextPoint         = this.ContextBuffer.CurrentSnapshot.GetLineFromLineNumber(CurrentStatementSpan.iEndLine).Start + CurrentStatementSpan.iEndIndex;
            var adjustedContextPoint = GetAdjustedContextPoint(contextPoint, document);

            // Get the previous span/text. We might have to insert another newline or something.
            var previousStatementSpan = GetPreviousStatementBufferAndSpan(adjustedContextPoint, document);

            // Build the tracking span that includes the rest of the file
            var restOfFileSpan = ContextBuffer.CurrentSnapshot.CreateTrackingSpanFromIndexToEnd(adjustedContextPoint, SpanTrackingMode.EdgePositive);

            // Put it all into a projection buffer
            _projectionBuffer = this.ProjectionBufferFactoryService.CreateProjectionBuffer(null,
                                                                                           new object[] { previousStatementSpan, debuggerMappedSpan, this.StatementTerminator, restOfFileSpan }, ProjectionBufferOptions.None, _contentType);

            // Fork the solution using this new primary buffer for the document and all of its linked documents.
            var forkedSolution = solution.WithDocumentText(document.Id, _projectionBuffer.CurrentSnapshot.AsText(), PreservationMode.PreserveIdentity);

            foreach (var link in document.GetLinkedDocumentIds())
            {
                forkedSolution = forkedSolution.WithDocumentText(link, _projectionBuffer.CurrentSnapshot.AsText(), PreservationMode.PreserveIdentity);
            }

            // Put it into a new workspace, and open it and its related documents
            // with the projection buffer as the text.
            _workspace = new DebuggerIntelliSenseWorkspace(forkedSolution);
            _workspace.OpenDocument(document.Id, _projectionBuffer.AsTextContainer());
            foreach (var link in document.GetLinkedDocumentIds())
            {
                _workspace.OpenDocument(link, _projectionBuffer.AsTextContainer());
            }

            // Start getting the compilation so the PartialSolution will be ready when the user starts typing in the window
            document.Project.GetCompilationAsync(System.Threading.CancellationToken.None);

            _textView.TextBuffer.ChangeContentType(_contentType, null);

            var bufferGraph = _bufferGraphFactoryService.CreateBufferGraph(_projectionBuffer);

            _debuggerTextView = new DebuggerTextView(_textView, bufferGraph, _debuggerTextLines, InImmediateWindow);
            return(true);
        }
 public ReplAggregateClassifier(IBufferGraphFactoryService bufferGraphFactory, ITextBuffer buffer)
 {
     _primaryBuffer = buffer;
     _bufGraphFact  = bufferGraphFactory;
     _bufferGraph   = bufferGraphFactory.CreateBufferGraph(buffer);
 }
 public ReplAggregateClassifier(IBufferGraphFactoryService bufferGraphFactory, ITextBuffer buffer) {            
     _primaryBuffer = buffer;
     _bufGraphFact = bufferGraphFactory;
     _bufferGraph = bufferGraphFactory.CreateBufferGraph(buffer);
 }
Esempio n. 13
0
#pragma warning restore 0169

		public WpfTextView(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, IEditorOptionsFactoryService editorOptionsFactoryService, ICommandService commandService, ISmartIndentationService smartIndentationService, IFormattedTextSourceFactoryService formattedTextSourceFactoryService, IViewClassifierAggregatorService viewClassifierAggregatorService, ITextAndAdornmentSequencerFactoryService textAndAdornmentSequencerFactoryService, IClassificationFormatMapService classificationFormatMapService, IEditorFormatMapService editorFormatMapService, IAdornmentLayerDefinitionService adornmentLayerDefinitionService, ILineTransformProviderService lineTransformProviderService, ISpaceReservationStackProvider spaceReservationStackProvider, IWpfTextViewConnectionListenerServiceProvider wpfTextViewConnectionListenerServiceProvider, IBufferGraphFactoryService bufferGraphFactoryService, Lazy<IWpfTextViewCreationListener, IDeferrableContentTypeAndTextViewRoleMetadata>[] wpfTextViewCreationListeners) {
			if (textViewModel == null)
				throw new ArgumentNullException(nameof(textViewModel));
			if (roles == null)
				throw new ArgumentNullException(nameof(roles));
			if (parentOptions == null)
				throw new ArgumentNullException(nameof(parentOptions));
			if (editorOptionsFactoryService == null)
				throw new ArgumentNullException(nameof(editorOptionsFactoryService));
			if (commandService == null)
				throw new ArgumentNullException(nameof(commandService));
			if (smartIndentationService == null)
				throw new ArgumentNullException(nameof(smartIndentationService));
			if (formattedTextSourceFactoryService == null)
				throw new ArgumentNullException(nameof(formattedTextSourceFactoryService));
			if (viewClassifierAggregatorService == null)
				throw new ArgumentNullException(nameof(viewClassifierAggregatorService));
			if (textAndAdornmentSequencerFactoryService == null)
				throw new ArgumentNullException(nameof(textAndAdornmentSequencerFactoryService));
			if (classificationFormatMapService == null)
				throw new ArgumentNullException(nameof(classificationFormatMapService));
			if (editorFormatMapService == null)
				throw new ArgumentNullException(nameof(editorFormatMapService));
			if (adornmentLayerDefinitionService == null)
				throw new ArgumentNullException(nameof(adornmentLayerDefinitionService));
			if (lineTransformProviderService == null)
				throw new ArgumentNullException(nameof(lineTransformProviderService));
			if (spaceReservationStackProvider == null)
				throw new ArgumentNullException(nameof(spaceReservationStackProvider));
			if (wpfTextViewCreationListeners == null)
				throw new ArgumentNullException(nameof(wpfTextViewCreationListeners));
			if (wpfTextViewConnectionListenerServiceProvider == null)
				throw new ArgumentNullException(nameof(wpfTextViewConnectionListenerServiceProvider));
			if (bufferGraphFactoryService == null)
				throw new ArgumentNullException(nameof(bufferGraphFactoryService));
			mouseHoverHelper = new MouseHoverHelper(this);
			physicalLineCache = new PhysicalLineCache(32);
			visiblePhysicalLines = new List<PhysicalLine>();
			invalidatedRegions = new List<SnapshotSpan>();
			this.formattedTextSourceFactoryService = formattedTextSourceFactoryService;
			zoomLevel = ZoomConstants.DefaultZoom;
			DsImage.SetZoom(VisualElement, zoomLevel / 100);
			this.adornmentLayerDefinitionService = adornmentLayerDefinitionService;
			this.lineTransformProviderService = lineTransformProviderService;
			this.wpfTextViewCreationListeners = wpfTextViewCreationListeners.Where(a => roles.ContainsAny(a.Metadata.TextViewRoles)).ToArray();
			recreateLineTransformProvider = true;
			normalAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Normal);
			overlayAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Overlay);
			underlayAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Underlay);
			IsVisibleChanged += WpfTextView_IsVisibleChanged;
			Properties = new PropertyCollection();
			TextViewModel = textViewModel;
			BufferGraph = bufferGraphFactoryService.CreateBufferGraph(TextViewModel.VisualBuffer);
			Roles = roles;
			Options = editorOptionsFactoryService.GetOptions(this);
			Options.Parent = parentOptions;
			ViewScroller = new ViewScroller(this);
			hasKeyboardFocus = IsKeyboardFocusWithin;
			oldViewState = new ViewState(this);
			aggregateClassifier = viewClassifierAggregatorService.GetClassifier(this);
			textAndAdornmentSequencer = textAndAdornmentSequencerFactoryService.Create(this);
			classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(this);
			editorFormatMap = editorFormatMapService.GetEditorFormatMap(this);
			spaceReservationStack = spaceReservationStackProvider.Create(this);

			textLayer = new TextLayer(GetAdornmentLayer(PredefinedAdornmentLayers.Text));
			Selection = new TextSelection(this, GetAdornmentLayer(PredefinedAdornmentLayers.Selection), editorFormatMap);
			TextCaret = new TextCaret(this, GetAdornmentLayer(PredefinedAdornmentLayers.Caret), smartIndentationService, classificationFormatMap);

			Children.Add(underlayAdornmentLayerCollection);
			Children.Add(normalAdornmentLayerCollection);
			Children.Add(overlayAdornmentLayerCollection);
			Cursor = Cursors.IBeam;
			Focusable = true;
			FocusVisualStyle = null;
			InitializeOptions();

			Options.OptionChanged += EditorOptions_OptionChanged;
			TextBuffer.ChangedLowPriority += TextBuffer_ChangedLowPriority;
			TextViewModel.DataModel.ContentTypeChanged += DataModel_ContentTypeChanged;
			aggregateClassifier.ClassificationChanged += AggregateClassifier_ClassificationChanged;
			textAndAdornmentSequencer.SequenceChanged += TextAndAdornmentSequencer_SequenceChanged;
			classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
			editorFormatMap.FormatMappingChanged += EditorFormatMap_FormatMappingChanged;
			spaceReservationStack.GotAggregateFocus += SpaceReservationStack_GotAggregateFocus;
			spaceReservationStack.LostAggregateFocus += SpaceReservationStack_LostAggregateFocus;

			UpdateBackground();
			CreateFormattedLineSource(ViewportWidth);
			InitializeZoom();
			UpdateRemoveExtraTextLineVerticalPixels();

			if (Roles.Contains(PredefinedTextViewRoles.Interactive))
				RegisteredCommandElement = commandService.Register(VisualElement, this);
			else
				RegisteredCommandElement = NullRegisteredCommandElement.Instance;

			wpfTextViewConnectionListenerServiceProvider.Create(this);
			NotifyTextViewCreated(TextViewModel.DataModel.ContentType, null);
		}