public ILineTransformSource Create(IWpfTextView textView)
        {
            Contract.Assume(textView != null);

            if (VSServiceProvider.Current == null || VSServiceProvider.Current.ExtensionHasFailed)
            {
                //If the VSServiceProvider is not initialize, we can't do anything.
                return(null);// new DummyLineTransformSource();
            }

            try {
                VSServiceProvider.Current.ExtensionFailed += OnFailed;

                if (hasFailed)
                {
                    return(null);
                }

                Contract.Assume(this.OutliningManagerService != null, "Import attribute guarantees this.");

                var outliningManager = OutliningManagerService.GetOutliningManager(textView);
                if (outliningManager == null)
                {
                    return(null);//new DummyLineTransformSource();
                }
                var inheritanceManager = AdornmentManager.GetOrCreateAdornmentManager(textView, "InheritanceAdornments", outliningManager, VSServiceProvider.Current.Logger);
                var metadataManager    = AdornmentManager.GetOrCreateAdornmentManager(textView, "MetadataAdornments", outliningManager, VSServiceProvider.Current.Logger);

                return(new LineTransformSource(VSServiceProvider.Current.Logger, inheritanceManager.Adornments.Values, metadataManager.Adornments.Values));
            } catch (Exception exn) {
                VSServiceProvider.Current.Logger.PublicEntryException(exn, "Create");
                return(null);// new DummyLineTransformSource();
            }
        }
Esempio n. 2
0
    public void VsTextViewCreated(IVsTextView textViewAdapter)
    {
        IComponentModel componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));

        if (componentModel != null)
        {
            IOutliningManagerService outliningManagerService = componentModel.GetService <IOutliningManagerService>();
            _editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            if (outliningManagerService != null)
            {
                if (textViewAdapter != null && _editorAdaptersFactoryService != null)
                {
                    var textView     = _editorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
                    var snapshot     = textView.TextSnapshot;
                    var snapshotSpan = new Microsoft.VisualStudio.Text.SnapshotSpan(snapshot, new Microsoft.VisualStudio.Text.Span(0, snapshot.Length));
                    _outliningManager = outliningManagerService.GetOutliningManager(textView);
                    var regions = _outliningManager.GetAllRegions(snapshotSpan);
                    foreach (var reg in regions)
                    {
                        _outliningManager.TryCollapse(reg);
                    }
                }
            }
        }
    }
Esempio n. 3
0
        public void TextViewCreated(IWpfTextView textView)
        {
            var generalOptions = Setting.getGeneralOptions(_serviceProvider);

            if (generalOptions == null || !generalOptions.OutliningEnabled)
            {
                return;
            }
            var  textBuffer       = textView.TextBuffer;
            var  outliningTagger  = CreateTagger <IOutliningRegionTag>(textBuffer);
            bool isFirstOutlining = true;

            outliningTagger.TagsChanged += (sender, e) =>
            {
                if (isFirstOutlining)
                {
                    var fullSpan = new SnapshotSpan(textView.TextSnapshot, 0, textView.TextSnapshot.Length);
                    // Ensure that first tags have been computed.
                    var tags             = outliningTagger.GetTags(new NormalizedSnapshotSpanCollection(fullSpan));
                    var outliningManager = _outliningManagerService.GetOutliningManager(textView);
                    // Keep the outlining manager in the lifetime of the text view.
                    // This prevents the outlining manager being disposed while it should still be used.
                    textView.Properties.GetOrCreateSingletonProperty(() => outliningManager);
                    if (outliningManager != null)
                    {
                        outliningManager.CollapseAll(fullSpan, match: c => c.Tag.IsDefaultCollapsed);
                    }
                    isFirstOutlining = false;
                }
            };
        }
Esempio n. 4
0
        public void TextViewCreated(IWpfTextView textView)
        {
            var generalOptions = Setting.getGeneralOptions(_serviceProvider);

            if (generalOptions == null || !generalOptions.OutliningEnabled)
            {
                return;
            }

            var  textBuffer       = textView.TextBuffer;
            var  outliningTagger  = CreateTagger <IOutliningRegionTag>(textBuffer);
            bool isFirstOutlining = true;

            outliningTagger.TagsChanged += (sender, e) =>
            {
                if (isFirstOutlining)
                {
                    // Try to collapse tags once at view opening
                    isFirstOutlining = false;

                    var outliningManager = textView.Properties.GetOrCreateSingletonProperty(
                        () => _outliningManagerService.GetOutliningManager(textView));
                    if (outliningManager != null)
                    {
                        var fullSpan = new SnapshotSpan(textBuffer.CurrentSnapshot, 0, textBuffer.CurrentSnapshot.Length);
                        outliningManager.CollapseAll(fullSpan, match: c => c.Tag.IsDefaultCollapsed);
                    }
                }
            };
        }
Esempio n. 5
0
        public static bool TryMoveCaretToAndEnsureVisible(this ITextView textView, VirtualSnapshotPoint point, IOutliningManagerService outliningManagerService = null, EnsureSpanVisibleOptions ensureSpanVisibleOptions = EnsureSpanVisibleOptions.None)
        {
            if (textView.IsClosed)
            {
                return(false);
            }

            var pointInView = textView.GetPositionInView(point.Position);

            if (!pointInView.HasValue)
            {
                return(false);
            }

            // If we were given an outlining service, we need to expand any outlines first, or else
            // the Caret.MoveTo won't land in the correct location if our target is inside a
            // collapsed outline.
            var outliningManager = outliningManagerService?.GetOutliningManager(textView);

            outliningManager?.ExpandAll(new SnapshotSpan(pointInView.Value, length: 0), match: _ => true);

            var newPosition = textView.Caret.MoveTo(new VirtualSnapshotPoint(pointInView.Value, point.VirtualSpaces));

            // We use the caret's position in the view's current snapshot here in case something
            // changed text in response to a caret move (e.g. line commit)
            var spanInView = new SnapshotSpan(newPosition.BufferPosition, 0);

            textView.ViewScroller.EnsureSpanVisible(spanInView, ensureSpanVisibleOptions);

            return(true);
        }
Esempio n. 6
0
 public FoldingManagerAdapter(
     IWpfTextView textView,
     IOutliningManagerService outliningManagerService)
 {
     _outliningManager = outliningManagerService.GetOutliningManager(textView);
     _outliningManager.RegionsExpanded  += OnExpanded;
     _outliningManager.RegionsCollapsed += OnCollapsed;
 }
Esempio n. 7
0
 public static IOutliningManager GetOutliningManager(IOutliningManagerService outliningManagerService, ITextView textView)
 {
     if (outliningManagerService == null)
     {
         return(null);
     }
     return(outliningManagerService.GetOutliningManager(textView));
 }
        private DiagnosticInfosViewModel CreateSut()
        {
            A.CallTo(() => _outliningManagerService.GetOutliningManager(_wpfTextView)).Returns(_outliningManager);
            A.CallTo(() => _textView.TextView).Returns(_wpfTextView);

            return(new DiagnosticInfosViewModel(
                       _textView,
                       _diagnosticsProvider,
                       _outliningManagerService,
                       _adornmentSpaceReservation));
        }
        public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                for (var i = 0; i < cCmds; i++)
                {
                    switch ((VSConstants.VSStd2KCmdID)prgCmds[i].cmdID)
                    {
                    case VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING:
                        var outliningManager = _outliningManagerService.GetOutliningManager(_textView);
                        if (outliningManager != null && !outliningManager.Enabled)
                        {
                            prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED);
                        }
                        return(VSConstants.S_OK);
                    }
                }
            }

            return(_nextCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText));
        }
        public CommandState GetCommandState(StartAutomaticOutliningCommandArgs args)
        {
            var outliningManager = _outliningManagerService.GetOutliningManager(args.TextView);
            var enabled          = false;

            if (outliningManager != null)
            {
                enabled = outliningManager.Enabled;
            }

            return(new CommandState(isAvailable: !enabled));
        }
        void ExpandCollapsedRegions(ITextView textView, SnapshotSpan span)
        {
            var outlining = outliningService.GetOutliningManager(textView);

            if (outlining != null)
            {
                foreach (var collapsed in outlining.GetCollapsedRegions(span))
                {
                    outlining.Expand(collapsed);
                }
            }
        }
Esempio n. 12
0
        private RegionTextViewHandler(IWpfTextView textView, IOutliningManagerService outliningManagerService)
        {
            _outliningManager = outliningManagerService.GetOutliningManager(textView);

            if (_outliningManager == null)
            {
                return;
            }

            _textView = textView;
            _outliningManager.RegionsCollapsed += OnRegionsCollapsed;
            _textView.Closed += OnClosed;
        }
Esempio n. 13
0
        public async Task R_OutlineToggleAll()
        {
            string text = _files.LoadDestinationFile("lsfit.r");

            using (var script = await _editorHost.StartScript(_exportProvider, text, "filename", RContentTypeDefinition.ContentType, null)) {
                script.DoIdle(500);

                IOutliningManagerService svc = _exportProvider.GetExportedValue <IOutliningManagerService>();
                IOutliningManager        mgr = svc.GetOutliningManager(script.View);
                var snapshot = script.TextBuffer.CurrentSnapshot;

                var viewLines = script.View.TextViewLines;
                viewLines.Count.Should().Be(22);
                script.DoIdle(500);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(1000);

                IEnumerable <ICollapsed> collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(20);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(500);

                viewLines = script.View.TextViewLines;
                viewLines.Count.Should().Be(22);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(false);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(true);

                script.MoveDown(9);
                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(500);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(1);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(200);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(0);
            }
        }
Esempio n. 14
0
        public void R_OutlineToggleAll()
        {
            string text = _files.LoadDestinationFile("lsfit.r");

            using (var script = new TestScript(text, RContentTypeDefinition.ContentType)) {
                script.DoIdle(500);

                IOutliningManagerService svc = EditorShell.Current.ExportProvider.GetExportedValue <IOutliningManagerService>();
                IOutliningManager        mgr = svc.GetOutliningManager(EditorWindow.CoreEditor.View);
                var snapshot = EditorWindow.TextBuffer.CurrentSnapshot;

                var viewLines = EditorWindow.CoreEditor.View.TextViewLines;
                viewLines.Count.Should().Be(40);
                script.DoIdle(500);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(1000);

                IEnumerable <ICollapsed> collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(20);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(500);

                viewLines = EditorWindow.CoreEditor.View.TextViewLines;
                viewLines.Count.Should().Be(40);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(false);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(true);

                script.MoveDown(9);
                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(500);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(1);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(200);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(0);
            }
        }
Esempio n. 15
0
        /// <inheritdoc />
        public int GetComputedLineNumber(int absoluteLineNumber)
        {
            try
            {
                // a line could not get any further than 0 even by collapsing regions
                if (absoluteLineNumber == 0)
                {
                    return(0);
                }

                // if no snapshot line found return 0
                var lineSnapshot = _textView.GetSnapshotForLineNumber(absoluteLineNumber);
                if (lineSnapshot == null)
                {
                    return(0);
                }

                // if no collapsed region than line number fits as normal
                var outliningManager = _outliningManagerService.GetOutliningManager(_textView);
                var snapshotSpan     = lineSnapshot.Extent;
                var region           = outliningManager?.GetCollapsedRegions(snapshotSpan) ?? Enumerable.Empty <ICollapsible>();
                if (!region.Any())
                {
                    return(absoluteLineNumber);
                }

                // I assume that the longest collapsed region is the outermost
                var regionSnapshot = region
                                     .Select(x => x.Extent.GetSpan(_textView.TextSnapshot))
                                     .ToDictionary(x => x.Length)
                                     .OrderByDescending(x => x.Key)
                                     .First()
                                     .Value;

                var collapsedLineNumber = _textView.TextSnapshot.GetLineNumberFromPosition(regionSnapshot.End.Position);
                return(collapsedLineNumber);
            }
            catch (ObjectDisposedException ex)
            {
                if (ex.ObjectName == "OutliningMnger")
                {
                    // TODO: when we have a logger service add logging
                }

                // I assume that this case seems to happen, if the TextView gets closed and we receive a
                // DiagnosticChanged event right in the time frame before we dispose the whole container graph.
                return(absoluteLineNumber);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Attempts to get the outlining manager associated with the specified document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <returns>The associated outlining manager, otherwise null.</returns>
        private IOutliningManager GetOutliningManager(Document document)
        {
            try
            {
                _wpfTextView = GetWpfTextView(document);
                if (_wpfTextView != null && _outliningManagerService != null)
                {
                    return(_outliningManagerService.GetOutliningManager(_wpfTextView));
                }
            }
            catch (Exception ex)
            {
                OutputWindowHelper.ExceptionWriteLine($"Unable to retrieve an outlining manager for '{document.FullName}'", ex);
            }

            return(null);
        }
        internal static IOutliningManager GetOutliningManager(this IServiceProvider serviceProvider, ITextView textView)
        {
            if (serviceProvider == null || textView == null)
            {
                return(null);
            }

            IComponentModel          componentModel          = serviceProvider.GetService <SComponentModel, IComponentModel>();
            IOutliningManagerService outliningManagerService = componentModel?.GetService <IOutliningManagerService>();

            if (outliningManagerService == null)
            {
                return(null);
            }

            return(outliningManagerService.GetOutliningManager(textView));
        }
Esempio n. 18
0
        internal static async Task <IOutliningManager> GetOutliningManagerAsync(this Shell.IAsyncServiceProvider serviceProvider, ITextView textView)
        {
            if (serviceProvider == null || textView == null)
            {
                return(null);
            }

            IComponentModel componentModel = await serviceProvider.GetServiceAsync <SComponentModel, IComponentModel>();

            IOutliningManagerService outliningManagerService = componentModel?.GetService <IOutliningManagerService>();

            if (outliningManagerService == null)
            {
                return(null);
            }

            return(outliningManagerService.GetOutliningManager(textView));
        }
Esempio n. 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiagnosticInfosViewModel"/> class.
        /// </summary>
        /// <param name="textView">The <see cref="IQualityTextView"/>.</param>
        /// <param name="diagnosticProvider">The <see cref="IDiagnosticProvider"/>.</param>
        /// <param name="outliningManagerService">THe <see cref="IOutliningManagerService"/> for the <paramref name="textView"/>.</param>
        /// <param name="adornmentSpaceReservation">The <see cref="IAdornmentSpaceReservation"/>.</param>
        public DiagnosticInfosViewModel(
            IQualityTextView textView,
            IDiagnosticProvider diagnosticProvider,
            IOutliningManagerService outliningManagerService,
            IAdornmentSpaceReservation adornmentSpaceReservation)
        {
            _diagnosticProvider       = diagnosticProvider ?? throw new ArgumentNullException(nameof(diagnosticProvider));
            TextView                  = textView ?? throw new ArgumentNullException(nameof(textView));
            AdornmentSpaceReservation = adornmentSpaceReservation ?? throw new ArgumentNullException(nameof(adornmentSpaceReservation));
            OutliningManager          = outliningManagerService.GetOutliningManager(TextView.TextView);

            WeakEventManager <IDiagnosticProvider, DiagnosticsChangedEventArgs> .AddHandler(_diagnosticProvider, nameof(IDiagnosticProvider.DiagnosticsChanged), OnDiagnosticsChanged);

            OutliningManager.RegionsExpanded  += OnRegionsExpanded;
            OutliningManager.RegionsCollapsed += OnRegionsCollapsed;

            OnDiagnosticsChanged(this, new DiagnosticsChangedEventArgs(_diagnosticProvider.CurrentDiagnostics));
        }
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            //provide highlighting only on the top buffer
            if (textView.TextBuffer != buffer)
            {
                return(null);
            }

            var wpfView = textView as IWpfTextView;

            if (wpfView != null)
            {
                var outMgr = OutliningManagerService.GetOutliningManager(textView);
                Func <Navigation.Navigator> createHandler = () => { return(new Navigation.Navigator(wpfView, outMgr)); };
                wpfView.Properties.GetOrCreateSingletonProperty(createHandler);
            }

            return(new BraceHighlightTagger(textView, buffer) as ITagger <T>);
        }
Esempio n. 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="editorOperationsService"></param>
        /// <param name="textStructureNavigator"></param>
        /// <param name="outliningManagerService"></param>
        public Selector(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            ITextStructureNavigator textStructureNavigator,
            IOutliningManagerService outliningManagerService)
        {
            this.view = view;

            // Services
            this.textSearchService      = textSearchService;
            this.EditorOperations       = editorOperationsService.GetEditorOperations(this.view);
            this.textStructureNavigator = textStructureNavigator;
            this.outliningManager       = outliningManagerService?.GetOutliningManager(this.view);
            this.Dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            this.Selections     = new List <Selection>();
            this.historyManager = new HistoryManager();
        }
Esempio n. 22
0
        private void SelectSpan(ITextView textView, SnapshotSpan snapshotSpan)
        {
            var source = textView.BufferGraph.MapUpToSnapshot(snapshotSpan, SpanTrackingMode.EdgeExclusive,
                                                              textView.TextSnapshot);
            var span = source.First <SnapshotSpan>();

            if (_outliningManagerService != null)
            {
                var outliningManager = _outliningManagerService.GetOutliningManager(textView);
                if (outliningManager != null)
                {
                    outliningManager.ExpandAll(span, (_) => true);
                }
            }
            var virtualSnapshotSpan = new VirtualSnapshotSpan(span);

            _editorOperationsFactory.GetEditorOperations(textView).SelectAndMoveCaret(
                virtualSnapshotSpan.Start, virtualSnapshotSpan.End,
                TextSelectionMode.Stream, EnsureSpanVisibleOptions.AlwaysCenter);
        }
Esempio n. 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="IEditorOperationsFactoryService"></param>
        /// <param name="IEditorFormatMapService"></param>
        /// <param name="ITextStructureNavigator"></param>
        /// <param name="IOutliningManagerService"></param>
        public Selector(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            IEditorFormatMapService formatMapService         = null,
            ITextStructureNavigator textStructureNavigator   = null,
            IOutliningManagerService outliningManagerService = null
            )
        {
            this.view = view;

            // Services
            this.textSearchService      = textSearchService ?? throw new ArgumentNullException("textSearchService");
            this.editorOperations       = editorOperationsService.GetEditorOperations(this.view);
            this.textStructureNavigator = textStructureNavigator;
            this.outliningManager       = outliningManagerService?.GetOutliningManager(this.view);
            this.Dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            this.Selections = new List <Selection>();
        }
Esempio n. 24
0
        /// <summary>
        /// An event handler raised when a code item parent's expanded state has changed.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="eventArgs">The event arguments.</param>
        private static void OnIsExpandedChanged(object sender, EventArgs eventArgs)
        {
            var item = sender as IMembers;

            if (item != null)
            {
                var iCollapsible = FindCollapsibleFromCodeItem((CodeItem)item, _outliningManagerService, _textView);
                if (iCollapsible != null)
                {
                    var outliningManager = _outliningManagerService.GetOutliningManager(_textView);

                    if (item.IsExpanded && iCollapsible.IsCollapsed)
                    {
                        outliningManager.Expand(iCollapsible as ICollapsed);
                    }
                    else if (!item.IsExpanded && !iCollapsible.IsCollapsed)
                    {
                        outliningManager.TryCollapse(iCollapsible);
                    }
                }
            }
        }
Esempio n. 25
0
 public void TextViewCreated(IWpfTextView textView)
 {
     var generalOptions = Setting.getGeneralOptions(_serviceProvider);
     if (generalOptions == null || !generalOptions.OutliningEnabled) return;
     var textBuffer = textView.TextBuffer;
     var outliningTagger = CreateTagger<IOutliningRegionTag>(textBuffer);
     bool isFirstOutlining = true;
     outliningTagger.TagsChanged += (sender, e) =>
     {
         if (isFirstOutlining)
         {
             var fullSpan = new SnapshotSpan(textView.TextSnapshot, 0, textView.TextSnapshot.Length);
             // Ensure that first tags have been computed.
             var tags = outliningTagger.GetTags(new NormalizedSnapshotSpanCollection(fullSpan));
             var outliningManager = _outliningManagerService.GetOutliningManager(textView);
             if (outliningManager != null)
             {
                 outliningManager.CollapseAll(fullSpan, match: c => c.Tag.IsDefaultCollapsed);
             }
             isFirstOutlining = false;
         }
     };
 }
#pragma warning disable CS0649

        public void TextViewCreated(IWpfTextView wpfTextView)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            textView = wpfTextView;

            settings = new Settings();
            settings.LoadFromStore();

            textView.Closed += OnClosed;
            outliningManager = outliningManagerService.GetOutliningManager(textView);

            if (settings.BehaviorMode != BehaviorMode.DoNothing)
            {
                outliningManager.RegionsChanged += OutliningManagerOnRegionsChanged;
            }

            if (settings.BehaviorMode == BehaviorMode.PreventCollapse)
            {
                outliningManager.RegionsCollapsed += OnRegionsCollapsed;
            }

            TinyMessageBroker.Instance.Subscribe(this);
        }
 public void TextViewCreated(IWpfTextView textView)
 {
     RegionExpander.Register(textView, _outliningManagerService.GetOutliningManager(textView));
 }
        /// <summary>
        /// When a new text view is created, hook up the various "trackers" (<see cref="TextViewTracker"/>, <see cref="InheritanceTracker"/>, <see cref="QuickInfoTracker"/>).
        /// </summary>
        /// <param name="textView"></param>
        public void TextViewCreated(IWpfTextView textView)
        {
            Contract.Assume(textView != null);

            if (VSServiceProvider.Current == null || VSServiceProvider.Current.ExtensionHasFailed)
            {
                //If the VSServiceProvider is not initialize, we can't do anything.
                return;
            }

            VSServiceProvider.Current.Logger.PublicEntry(() => {
                #region Check if textView is valid
                var fileName = textView.GetFileName();
                if (fileName == null)
                {
                    VSServiceProvider.Current.Logger.WriteToLog("Couldn't retrieve file name for current view.");
                    return;
                }
                if (!File.Exists(fileName))
                {
                    VSServiceProvider.Current.Logger.WriteToLog("Couldn't find file for current view.");
                    return;
                }
                #endregion
                VSServiceProvider.Current.Logger.WriteToLog("Text view found: " + fileName);
                #region Check if textView is a CSharp file
                var IsCSharpFile = Path.GetExtension(fileName) == ".cs";
                #endregion
                #region Get text view properties
                var vsTextProperties = VSTextPropertiesProvider.GetVSTextProperties(textView);
                #endregion
                var vsProject = VSServiceProvider.Current.GetProjectForFile(fileName);//May be null!
                ProjectTracker projectTracker = null;
                if (vsProject != null)
                {
                    projectTracker = ProjectTracker.GetOrCreateProjectTracker(vsProject);
                    if (projectTracker != null)
                    {
                        textView.Properties.AddProperty(typeof(ProjectTracker), projectTracker);
                    }
                    else
                    {
                        VSServiceProvider.Current.Logger.WriteToLog("Warning: Couldn't create a 'ProjectTracker', we won't be able to show inheritance contract information for this text view. Close and reopen the text view to try again!");
                    }
                }
                #region Check if textView is an editable code file
                var IsEditableCodeFile = /*IsCSharpFile &&*/ textView.Roles.Contains("editable") && projectTracker != null; //TODO: We need a stronger check to see if it is a editable code file
                #endregion
                if (IsEditableCodeFile)
                {
                    textView.GotAggregateFocus += NewFocus;
                    var textViewTracker         = TextViewTracker.GetOrCreateTextViewTracker(textView, projectTracker, vsTextProperties);
                    //if (VSServiceProvider.Current.VSOptionsPage != null && (VSServiceProvider.Current.VSOptionsPage.InheritanceOnMethods || VSServiceProvider.Current.VSOptionsPage.InheritanceOnProperties)) {
                    //  //var inheritanceAdornmentManager = AdornmentManager.GetOrCreateAdornmentManager(textView, "InheritanceAdornments", outliningManager, VSServiceProvider.Current.Logger);
                    //  //var inheritanceTracker = InheritanceTracker.GetOrCreateAdornmentTracker(textViewTracker);
                    //}
                    //var quickInfoTracker = QuickInfoTracker.GetOrCreateQuickInfoTracker(textViewTracker); //Disabled for now, unfinished
                }
                #region Check if textView is a metadata file
                var IsMetadataFile = !IsEditableCodeFile && fileName.Contains('$'); //TODO: We need a strong check to see if it is a metadata file
                #endregion
                if (IsMetadataFile)
                {
                    if (lastFocus == null || !lastFocus.Properties.ContainsProperty(typeof(ProjectTracker)))
                    {
                        VSServiceProvider.Current.Logger.WriteToLog("Couldn't find project for metadata file.");
                    }
                    else
                    {
                        var outliningManager = OutliningManagerService.GetOutliningManager(textView);
                        if (outliningManager == null)
                        {
                            VSServiceProvider.Current.Logger.WriteToLog("Couldn't get outlining manager for current view.");
                            return;
                        }
                        projectTracker = lastFocus.Properties.GetProperty <ProjectTracker>(typeof(ProjectTracker));
                        textView.Properties.AddProperty(typeof(ProjectTracker), projectTracker);
                        textView.GotAggregateFocus += NewFocus;
                        if (VSServiceProvider.Current.VSOptionsPage != null && VSServiceProvider.Current.VSOptionsPage.Metadata)
                        {
                            var metadataAdornmentManager = AdornmentManager.GetOrCreateAdornmentManager(textView, "MetadataAdornments", outliningManager, VSServiceProvider.Current.Logger);
                            var metadataTracker          = MetadataTracker.GetOrCreateMetadataTracker(textView, projectTracker, vsTextProperties);
                        }
                    }
                }
            }, "TextViewCreated");
        }
        private void ExpandSpan(ITextView textView, SnapshotSpan snapshotSpan)
        {
            var outliningManager = outliningManagerService.GetOutliningManager(textView);

            outliningManager?.ExpandAll(snapshotSpan, _ => true);
        }