public WithoutReferencesFindUsagesContext(
     StreamingFindUsagesPresenter presenter,
     IFindAllReferencesWindow findReferencesWindow,
     ImmutableArray <AbstractFindUsagesCustomColumnDefinition> customColumns)
     : base(presenter, findReferencesWindow, customColumns)
 {
 }
Example #2
0
            public TableDataSourceFindUsagesContext(
                StreamingFindUsagesPresenter presenter,
                IFindAllReferencesWindow findReferencesWindow,
                bool alwaysIncludeDeclarations)
            {
                presenter.AssertIsForeground();

                Presenter = presenter;
                _alwaysIncludeDeclarations = alwaysIncludeDeclarations;
                _findReferencesWindow      = findReferencesWindow;
                _tableControl = (IWpfTableControl2)findReferencesWindow.TableControl;
                _tableControl.GroupingsChanged += OnTableControlGroupingsChanged;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += OnFindReferencesWindowClosed;

                DetermineCurrentGroupingByDefinitionState();

                // Remove any existing sources in the window.
                foreach (var source in findReferencesWindow.Manager.Sources.ToArray())
                {
                    findReferencesWindow.Manager.RemoveSource(source);
                }

                // And add ourselves as the source of results for the window.
                findReferencesWindow.Manager.AddSource(this);

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);
            }
Example #3
0
            protected AbstractTableDataSourceFindUsagesContext(
                StreamingFindUsagesPresenter presenter,
                IFindAllReferencesWindow findReferencesWindow,
                ImmutableArray <ITableColumnDefinition> customColumns,
                bool includeContainingTypeAndMemberColumns,
                bool includeKindColumn)
            {
                presenter.AssertIsForeground();

                Presenter                      = presenter;
                _findReferencesWindow          = findReferencesWindow;
                TableControl                   = (IWpfTableControl2)findReferencesWindow.TableControl;
                TableControl.GroupingsChanged += OnTableControlGroupingsChanged;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += OnFindReferencesWindowClosed;

                DetermineCurrentGroupingByDefinitionState();

                Debug.Assert(_findReferencesWindow.Manager.Sources.Count == 0);

                // Add ourselves as the source of results for the window.
                // Additionally, add applicable custom columns to display custom reference information
                _findReferencesWindow.Manager.AddSource(
                    this,
                    SelectCustomColumnsToInclude(customColumns, includeContainingTypeAndMemberColumns, includeKindColumn));

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);
            }
        private void SetDefinitionGroupingPriority(IFindAllReferencesWindow window, int priority)
        {
            this.AssertIsForeground();

            var newColumns = ArrayBuilder <ColumnState> .GetInstance();

            var tableControl = (IWpfTableControl2)window.TableControl;

            foreach (var columnState in window.TableControl.ColumnStates)
            {
                var columnState2 = columnState as ColumnState2;
                if (columnState?.Name == StandardTableColumnDefinitions2.Definition)
                {
                    newColumns.Add(new ColumnState2(
                                       columnState2.Name,
                                       isVisible: false,
                                       width: columnState2.Width,
                                       sortPriority: columnState2.SortPriority,
                                       descendingSort: columnState2.DescendingSort,
                                       groupingPriority: priority));
                }
                else
                {
                    newColumns.Add(columnState);
                }
            }

            tableControl.SetColumnStates(newColumns);
            newColumns.Free();
        }
        private void StoreCurrentGroupingPriority(IFindAllReferencesWindow window)
        {
            var definitionColumn = window.GetDefinitionColumn();

            _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
                                                                              .WithChangedOption(FindUsagesOptions.DefinitionGroupingPriority, definitionColumn.GroupingPriority)));
        }
            public TableDataSourceFindReferencesContext(
                 StreamingFindReferencesPresenter presenter,
                 IFindAllReferencesWindow findReferencesWindow)
            {
                presenter.AssertIsForeground();

                Presenter = presenter;
                _findReferencesWindow = findReferencesWindow;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += (s, e) => CancelSearch();

                // Remove any existing sources in the window.  
                foreach (var source in findReferencesWindow.Manager.Sources.ToArray())
                {
                    findReferencesWindow.Manager.RemoveSource(source);
                }

                // And add ourselves as the source of results for the window.
                findReferencesWindow.Manager.AddSource(this);

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);
            }
            public TableDataSourceFindReferencesContext(
                StreamingFindReferencesPresenter presenter,
                IFindAllReferencesWindow findReferencesWindow)
            {
                presenter.AssertIsForeground();

                Presenter             = presenter;
                _findReferencesWindow = findReferencesWindow;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += (s, e) => CancelSearch();

                // Remove any existing sources in the window.
                foreach (var source in findReferencesWindow.Manager.Sources.ToArray())
                {
                    findReferencesWindow.Manager.RemoveSource(source);
                }

                // And add ourselves as the source of results for the window.
                findReferencesWindow.Manager.AddSource(this);

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);
            }
            public TableDataSourceFindUsagesContext(
                 StreamingFindUsagesPresenter presenter,
                 IFindAllReferencesWindow findReferencesWindow,
                 bool alwaysIncludeDeclarations)
            {
                presenter.AssertIsForeground();

                Presenter = presenter;
                _alwaysIncludeDeclarations = alwaysIncludeDeclarations;
                _findReferencesWindow = findReferencesWindow;
                _tableControl = (IWpfTableControl2)findReferencesWindow.TableControl;
                _tableControl.GroupingsChanged += OnTableControlGroupingsChanged;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += OnFindReferencesWindowClosed;

                DetermineCurrentGroupingByDefinitionState();

                // Remove any existing sources in the window.  
                foreach (var source in findReferencesWindow.Manager.Sources.ToArray())
                {
                    findReferencesWindow.Manager.RemoveSource(source);
                }

                // And add ourselves as the source of results for the window.
                findReferencesWindow.Manager.AddSource(this);

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);
            }
        private void SetDefinitionGroupingPriority(IFindAllReferencesWindow window, int priority)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var newColumns   = new List <ColumnState> ();
            var tableControl = (IWpfTableControl2)window.TableControl;

            foreach (var columnState in window.TableControl.ColumnStates)
            {
                var columnState2 = columnState as ColumnState2;
                if (columnState?.Name == StandardTableColumnDefinitions2.Definition)
                {
                    newColumns.Add(new ColumnState2(
                                       columnState2.Name,
                                       isVisible: false,
                                       width: columnState2.Width,
                                       sortPriority: columnState2.SortPriority,
                                       descendingSort: columnState2.DescendingSort,
                                       groupingPriority: priority));
                }
                else
                {
                    newColumns.Add(columnState);
                }
            }

            tableControl.SetColumnStates(newColumns);
        }
Example #10
0
            protected AbstractTableDataSourceFindUsagesContext(
                StreamingFindUsagesPresenter presenter,
                IFindAllReferencesWindow findReferencesWindow)
            {
                presenter.AssertIsForeground();

                Presenter                      = presenter;
                _findReferencesWindow          = findReferencesWindow;
                TableControl                   = (IWpfTableControl2)findReferencesWindow.TableControl;
                TableControl.GroupingsChanged += OnTableControlGroupingsChanged;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += OnFindReferencesWindowClosed;

                DetermineCurrentGroupingByDefinitionState();

                Debug.Assert(_findReferencesWindow.Manager.Sources.Count == 0);

                // And add ourselves as the source of results for the window.
                _findReferencesWindow.Manager.AddSource(this);

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);
            }
 private FindUsagesContext StartSearchWithoutReferences(IFindAllReferencesWindow window)
 {
     // If we're not showing references, then disable grouping by definition, as that will
     // just lead to a poor experience.  i.e. we'll have the definition entry buckets,
     // with the same items showing underneath them.
     SetDefinitionGroupingPriority(window, 0);
     return(new WithoutReferencesFindUsagesContext(this, window));
 }
Example #12
0
        protected TableDataSource(string name, IFindAllReferencesWindow referencesWindow)
        {
            _referencesWindow = referencesWindow;
            DisplayName = name;
            Identifier = string.Format("{0}_{1}", name, typeof(T).FullName);
            _entries = new ConcurrentBag<T>();

            referencesWindow.Manager.AddSource(this);
        }
Example #13
0
 public WithoutReferencesFindUsagesContext(
     StreamingFindUsagesPresenter presenter,
     IFindAllReferencesWindow findReferencesWindow,
     ImmutableArray <ITableColumnDefinition> customColumns,
     bool includeContainingTypeAndMemberColumns,
     bool includeKindColumn)
     : base(presenter, findReferencesWindow, customColumns, includeContainingTypeAndMemberColumns, includeKindColumn)
 {
 }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == _vSStd97CmdIDGuid && nCmdID == (uint)VSConstants.VSStd97CmdID.GotoDefn)
            {
                TextView.TextBuffer.Properties.TryGetProperty <ITextDocument>(typeof(ITextDocument), out ITextDocument textDoc);

                if (PackageCompletionSource.IsInRangeForPackageCompletion(TextView.TextSnapshot, TextView.Caret.Position.BufferPosition.Position, out Span targetSpan, out string packageName, out string packageVersion, out string completionType))
                {
                    if (PackageExistsOnNuGet(packageName, packageVersion, out string url))
                    {
                        System.Diagnostics.Process.Start(url);
                        return(VSConstants.S_OK);
                    }
                }

                IWorkspace        workspace   = _workspaceManager.GetWorkspace(textDoc.FilePath);
                List <Definition> definitions = workspace.ResolveDefinition(textDoc.FilePath, TextView.TextSnapshot.GetText(), TextView.Caret.Position.BufferPosition.Position);

                if (definitions.Count == 1)
                {
                    DTE dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE;
                    dte.MainWindow.Activate();

                    using (var state = new NewDocumentStateScope(Microsoft.VisualStudio.Shell.Interop.__VSNEWDOCUMENTSTATE.NDS_Provisional, Guid.Parse(ProjectFileToolsPackage.PackageGuidString)))
                    {
                        EnvDTE.Window w = dte.ItemOperations.OpenFile(definitions[0].File, EnvDTE.Constants.vsViewKindTextView);

                        if (definitions[0].Line.HasValue)
                        {
                            ((EnvDTE.TextSelection)dte.ActiveDocument.Selection).GotoLine(definitions[0].Line.Value, true);
                        }
                    }

                    return(VSConstants.S_OK);
                }

                else if (definitions.Count > 1)
                {
                    IFindAllReferencesService farService = (IFindAllReferencesService)Package.GetGlobalService(typeof(SVsFindAllReferences));
                    FarDataSource             dataSource = new FarDataSource(1);
                    dataSource.Snapshots[0] = new FarDataSnapshot(definitions);

                    IFindAllReferencesWindow farWindow   = farService.StartSearch(definitions[0].Type);
                    ITableManager            _farManager = farWindow.Manager;
                    _farManager.AddSource(dataSource);

                    dataSource.Sink.IsStable = false;
                    dataSource.Sink.AddSnapshot(dataSource.Snapshots[0]);
                    dataSource.Sink.IsStable = true;

                    return(VSConstants.S_OK);
                }
            }

            return(Next?.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut) ?? (int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED);
        }
        private TableDataSourceFindUsagesContext StartSearchWithoutReferences(IFindAllReferencesWindow window, string referenceName, bool showUsage)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // If we're not showing references, then disable grouping by definition, as that will
            // just lead to a poor experience.  i.e. we'll have the definition entry buckets,
            // with the same items showing underneath them.
            SetDefinitionGroupingPriority(window, 0);
            return(new TableDataSourceFindUsagesContext(this, window, referenceName, showUsage? _customColumns : ImmutableArray <AbstractFindUsagesCustomColumnDefinition> .Empty));
        }
 public WithReferencesFindUsagesContext(
     StreamingFindUsagesPresenter presenter,
     IFindAllReferencesWindow findReferencesWindow,
     ImmutableArray <ITableColumnDefinition> customColumns,
     IGlobalOptionService globalOptions,
     bool includeContainingTypeAndMemberColumns,
     bool includeKindColumn,
     IThreadingContext threadingContext)
     : base(presenter, findReferencesWindow, customColumns, globalOptions, includeContainingTypeAndMemberColumns, includeKindColumn, threadingContext)
 {
 }
Example #17
0
        /// <summary>
        /// Resets the "Find All References" window and loads the specified collection.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        internal void Load(IProducerConsumerCollection <IEnumerable <SearchResult> > collection, CancellationToken cancellationToken)
        {
            var service = (IFindAllReferencesService)ServiceProvider.GetService(typeof(SVsFindAllReferences));

            //start a new search that doesn't actually search anything.
            window = service.StartSearch("");

            //the table that will take the search results and add them to the window
            var source = new SearchResultTableDataSource(collection, cancellationToken);

            //add the table as a source for the window
            window.Manager.AddSource(source);
        }
Example #18
0
        private static int ShowInFar(string title, List <Definition> definitions)
        {
            IFindAllReferencesService farService = ServiceUtil.GetService <SVsFindAllReferences, IFindAllReferencesService>();
            FarDataSource             dataSource = new FarDataSource(1);

            dataSource.Snapshots[0] = new FarDataSnapshot(definitions);

            IFindAllReferencesWindow farWindow   = farService.StartSearch(title);
            ITableManager            _farManager = farWindow.Manager;

            _farManager.AddSource(dataSource);

            dataSource.Sink.IsStable = false;
            dataSource.Sink.AddSnapshot(dataSource.Snapshots[0]);
            dataSource.Sink.IsStable = true;

            return(VSConstants.S_OK);
        }
            protected AbstractTableDataSourceFindUsagesContext(
                StreamingFindUsagesPresenter presenter,
                IFindAllReferencesWindow findReferencesWindow,
                ImmutableArray <ITableColumnDefinition> customColumns,
                bool includeContainingTypeAndMemberColumns,
                bool includeKindColumn)
            {
                presenter.AssertIsForeground();

                Presenter                      = presenter;
                _findReferencesWindow          = findReferencesWindow;
                TableControl                   = (IWpfTableControl2)findReferencesWindow.TableControl;
                TableControl.GroupingsChanged += OnTableControlGroupingsChanged;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += OnFindReferencesWindowClosed;

                DetermineCurrentGroupingByDefinitionState();

                Debug.Assert(_findReferencesWindow.Manager.Sources.Count == 0);

                // Add ourselves as the source of results for the window.
                // Additionally, add applicable custom columns to display custom reference information
                _findReferencesWindow.Manager.AddSource(
                    this,
                    SelectCustomColumnsToInclude(customColumns, includeContainingTypeAndMemberColumns, includeKindColumn));

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);

                // https://devdiv.visualstudio.com/web/wi.aspx?pcguid=011b8bdf-6d56-4f87-be0d-0092136884d9&id=359162
                // VS actually responds to each SetProgess call by queuing a UI task to do the
                // progress bar update.  This can made FindReferences feel extremely slow when
                // thousands of SetProgress calls are made.
                //
                // To ensure a reasonable experience, we instead add the progress into a queue and
                // only update the UI a few times a second so as to not overload it.
                _progressQueue = new AsyncBatchingWorkQueue <(int current, int maximum)>(
                    TimeSpan.FromMilliseconds(250),
                    this.UpdateTableProgressAsync,
                    this.CancellationToken);
            }
        private AbstractTableDataSourceFindUsagesContext StartSearchWithReferences(IFindAllReferencesWindow window, int desiredGroupingPriority, bool includeContainingTypeAndMemberColumns, bool includeKindColumn)
        {
            // Ensure that the window's definition-grouping reflects what the user wants.
            // i.e. we may have disabled this column for a previous GoToImplementation call.
            // We want to still show the column as long as the user has not disabled it themselves.
            var definitionColumn = window.GetDefinitionColumn();

            if (definitionColumn.GroupingPriority != desiredGroupingPriority)
            {
                SetDefinitionGroupingPriority(window, desiredGroupingPriority);
            }

            // If the user changes the grouping, then store their current preference.
            var tableControl = (IWpfTableControl2)window.TableControl;

            tableControl.GroupingsChanged += (s, e) => StoreCurrentGroupingPriority(window);

            return(new WithReferencesFindUsagesContext(this, window, _customColumns, includeContainingTypeAndMemberColumns, includeKindColumn));
        }
Example #21
0
            protected AbstractTableDataSourceFindUsagesContext(
                StreamingFindUsagesPresenter presenter,
                IFindAllReferencesWindow findReferencesWindow,
                ImmutableArray <AbstractCustomColumnDefinition> customColumns,
                bool includeContainingTypeAndMemberColumns,
                bool includeKindColumn)
            {
                presenter.AssertIsForeground();

                Presenter                      = presenter;
                _findReferencesWindow          = findReferencesWindow;
                TableControl                   = (IWpfTableControl2)findReferencesWindow.TableControl;
                TableControl.GroupingsChanged += OnTableControlGroupingsChanged;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += OnFindReferencesWindowClosed;

                DetermineCurrentGroupingByDefinitionState();

                Debug.Assert(_findReferencesWindow.Manager.Sources.Count == 0);

                // Add ourselves as the source of results for the window.
                // Additionally, add applicable custom columns to display custom reference information
                _findReferencesWindow.Manager.AddSource(
                    this,
                    SelectCustomColumnsToInclude(customColumns, includeContainingTypeAndMemberColumns, includeKindColumn).ToReadOnlyCollection());

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);

                // Initialize custom column states at start of the FAR query.
                _customColumnTitleToStatesMap = GetInitialCustomColumnStates(findReferencesWindow.TableControl.ColumnStates, customColumns);

                // Now update the custom columns' state/visibility in the FAR window.
                // Note that the visibility of the custom column(s) can change only at two possible places:
                //  1. FAR query start, i.e. below invocation to SetColumnStates and/or
                //  2. First reference result which has a non-default custom column value
                //     (UpdateCustomColumnVisibility method below).
                // Also note that the TableControl.SetColumnStates is not dependent on order of the input column states.
                TableControl.SetColumnStates(_customColumnTitleToStatesMap.Values);
            }
Example #22
0
            public TableDataSourceFindUsagesContext(
                StreamingFindUsagesPresenter presenter,
                IFindAllReferencesWindow findReferencesWindow,
                string referenceName,
                ImmutableArray <AbstractFindUsagesCustomColumnDefinition> customColumns)
            {
                Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

                ReferenceName         = referenceName;
                Presenter             = presenter;
                _findReferencesWindow = findReferencesWindow;
                TableControl          = (IWpfTableControl2)findReferencesWindow.TableControl;

                // If the window is closed, cancel any work we're doing.
                _findReferencesWindow.Closed += OnFindReferencesWindowClosed;

                Debug.Assert(_findReferencesWindow.Manager.Sources.Count == 0);

                // And add ourselves as the source of results for the window.
                // Additionally, add custom columns to display custom reference information.
                _findReferencesWindow.Manager.AddSource(this, customColumns.Select(c => c.Name).ToArray());

                // After adding us as the source, the manager should immediately call into us to
                // tell us what the data sink is.
                Debug.Assert(_tableDataSink != null);

                // Initialize custom column states at start of the FAR query.
                _customColumnTitleToStatesMap = GetInitialCustomColumnStates(findReferencesWindow.TableControl.ColumnStates, customColumns);

                // Now update the custom columns' state/visibility in the FAR window.
                // Note that the visibility of the custom column(s) can change only at two possible places:
                //  1. FAR query start, i.e. below invocation to SetColumnStates and/or
                //  2. First reference result which has a non-default custom column value
                //     (UpdateCustomColumnVisibility method below).
                // Also note that the TableControl.SetColumnStates is not dependent on order of the input column states.
                TableControl.SetColumnStates(_customColumnTitleToStatesMap.Values);
            }
 public WithoutReferencesFindUsagesContext(
     StreamingFindUsagesPresenter presenter,
     IFindAllReferencesWindow findReferencesWindow)
     : base(presenter, findReferencesWindow)
 {
 }
 public static ColumnState2 GetDefinitionColumn(this IFindAllReferencesWindow window)
 {
     return(window.TableControl.ColumnStates.FirstOrDefault(
                s => s.Name == StandardTableColumnDefinitions2.Definition) as ColumnState2);
 }
 private AbstractTableDataSourceFindUsagesContext StartSearchWithoutReferences(IFindAllReferencesWindow window, bool includeContainingTypeAndMemberColumns, bool includeKindColumn)
 {
     // If we're not showing references, then disable grouping by definition, as that will
     // just lead to a poor experience.  i.e. we'll have the definition entry buckets,
     // with the same items showing underneath them.
     SetDefinitionGroupingPriority(window, 0);
     return(new WithoutReferencesFindUsagesContext(this, window, _customColumns, includeContainingTypeAndMemberColumns, includeKindColumn));
 }
        private void StoreCurrentGroupingPriority(IFindAllReferencesWindow window)
        {
            var definitionColumn = window.GetDefinitionColumn();

            MSBuildOptions.DefinitionGroupingPriority = definitionColumn.GroupingPriority;
        }
Example #27
0
        public ResourceSearchResultsDataSource(Document document, ISymbol designerPropertySymbol, IFindAllReferencesWindow referencesWindow)
            : base(referencesWindow.Title, referencesWindow)
        {
            _document = document;
            _designerPropertySymbol = designerPropertySymbol;

            GroupByFields(StandardTableKeyNames.ProjectName);
        }