Example #1
0
        private static bool Match(string columnValue, IVsSearchToken searchToken)
        {
#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
            return
                (columnValue != null &&
                 columnValue.IndexOf(searchToken.ParsedTokenText, StringComparison.OrdinalIgnoreCase) >= 0);

#pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
        }
            private bool AtLeastOneColumnOrDetailsContentMatches(
                ITableEntryHandle entry,
                IVsSearchToken searchToken,
                string[] cachedColumnValues
                )
            {
                // Check details content for any matches
                if (cachedColumnValues[0] == null)
                {
                    cachedColumnValues[0] = GetDetailsContentAsString(entry);
                }

                var detailsContent = cachedColumnValues[0];

                if (detailsContent != null && Match(detailsContent, searchToken))
                {
                    // Found match in details content
                    return(true);
                }

                if (_visibleColumns is null)
                {
                    return(false);
                }

                // Check each column for any matches
                for (var i = 0; i < _visibleColumns.Count; i++)
                {
                    if (cachedColumnValues[i + 1] == null)
                    {
                        cachedColumnValues[i + 1] = GetColumnValueAsString(
                            entry,
                            _visibleColumns[i]
                            );
                    }

                    var columnValue = cachedColumnValues[i + 1];

                    if (columnValue != null && Match(columnValue, searchToken))
                    {
                        // Found match in this column
                        return(true);
                    }
                }

                // No match found in this entry
                return(false);
            }
Example #3
0
        protected override void OnStartSearch()
        {
            // Start search operation here. This is already running in a threadpool task.
            // NOTE: you must return results in approx. 200ms or else your results are not shown.

            const int MaxTokens = 25;
            var       tokens    = new IVsSearchToken[MaxTokens];

            this.SearchQuery.GetTokens(MaxTokens, tokens);

            var nonNullTokens = tokens
                                .Where(t => t != null)
                                .Select(str => str.ParsedTokenText.ToLowerInvariant());

            if (this.SearchQuery.GetTokens(MaxTokens, tokens) > 0)
            {
                var searchResults = new List <Tuple <int, IExtensionDataItemView> >();

                foreach (var item in this.searchProvider.CachedItems)
                {
                    ScoreItem(searchResults, item, nonNullTokens);

                    // Cap search results at 20.
                    if (this.SearchResults >= MaxSearchResults ||
                        (this.TaskStatus == Microsoft.VisualStudio.VSConstants.VsSearchTaskStatus.Stopped))
                    {
                        break;
                    }
                }

                // Order results by score.
                var orderedResults = searchResults
                                     .OrderByDescending(result => result.Item1)
                                     .Select(result => result.Item2)
                                     .Select(result => new SearchResult(this.searchProvider, result));

                // Report all results.
                this.SearchCallback.ReportResults(
                    this,
                    (this.SearchResults = (uint)searchResults.Count),
                    orderedResults.ToArray());
            }

            this.SearchCallback.ReportComplete(this, this.SearchResults);
        }
Example #4
0
        protected override void OnStartSearch()
        {
            // Get the tokens count in the query
            uint tokenCount = this.SearchQuery.GetTokens(0, null);

            // Get the tokens
            IVsSearchToken[] tokens = new IVsSearchToken[tokenCount];
            this.SearchQuery.GetTokens(tokenCount, tokens);

            for (int itemIndex = 0; itemIndex < this.searchableItems.Count; itemIndex++)
            {
                var item = this.searchableItems[itemIndex];

                // Check if the search was canceled
                if (this.TaskStatus == VSConstants.VsSearchTaskStatus.Stopped)
                {
                    // The completion was already notified by the base.OnStopSearch, there is nothing else to do
                    return;
                }

                // Check if the item matches the current query
                if (Matches(item, tokens))
                {
                    // Create and report new result
                    IVsSearchProviderCallback providerCallback = (IVsSearchProviderCallback)this.SearchCallback;
                    providerCallback.ReportResult(this, new VSSearchResult(item, this.provider));

                    // Keep track of how many results we have found, and the base class will use this number when calling the callback to report completion
                    this.SearchResults++;
                }

                // Since we know how many items we have, we can report progress
                this.SearchCallback.ReportProgress(this, (uint)(itemIndex + 1), (uint)this.searchableItems.Count);
            }

            // Now call the base class - it will set the task status to complete and will callback to report search complete
            base.OnStartSearch();
        }
Example #5
0
        /// <summary>
        /// Override to start the search
        /// </summary>
        protected override void OnStartSearch()
        {
            // Get the tokens count in the query
            uint tokenCount = this.SearchQuery.GetTokens(0, null);


            IVsSearchToken[] tokens = new IVsSearchToken[tokenCount];
            this.SearchQuery.GetTokens(tokenCount, tokens);

            //for (int itemIndex = 0; itemIndex < this.SearchableItems.Length; itemIndex++)
            //{
            //	SearchableItem item = this.SearchableItems[itemIndex];

            //	// Check if the search was canceled
            //	if (this.TaskStatus == VSConstants.VsSearchTaskStatus.Stopped)
            //	{
            //		// The completion was already notified by the base.OnStopSearch, there is nothing else to do
            //		return;
            //	}

            //	// Check if the item matches the current query
            //	if (Matches(item, tokens))
            //	{
            //		// Create and report new result
            //		IVsSearchProviderCallback providerCallback = (IVsSearchProviderCallback)this.SearchCallback;
            //		providerCallback.ReportResult(this, new SearchItemResult(item, this.searchProvider));

            //		// Keep track of how many results we have found, and the base class will use this number when calling the callback to report completion
            //		this.SearchResults++;
            //	}

            //	// Since we know how many items we have, we can report progress
            //	this.SearchCallback.ReportProgress(this, (uint)(itemIndex + 1), (uint)this.SearchableItems.Length);
            //}

            // Now call the base class - it will set the task status to complete and will callback to report search complete
            base.OnStartSearch();
        }
 public uint GetTokens(uint dwMaxTokens, IVsSearchToken[] rgpSearchTokens)
 {
     return 0;
 }
 private static bool Match(string columnValue, IVsSearchToken searchToken) =>
 (columnValue is not null) &&
Example #8
0
        /// <summary>
        /// Checks whether an item matches the search query
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        bool Matches(VSSearchableItem item, IVsSearchToken[] tokens)
        {
            foreach (IVsSearchToken token in tokens)
            {
                bool tokenMatches = false;

                // We'll search description and name
                if (item.Name.IndexOf(token.ParsedTokenText, StringComparison.CurrentCultureIgnoreCase) != -1)
                    tokenMatches = true;

                if (item.Description != null && item.Description.IndexOf(token.ParsedTokenText, StringComparison.CurrentCultureIgnoreCase) != -1)
                    tokenMatches = true;

                if (!tokenMatches)
                    return false;
            }

            return true;
        }
 private static bool Match(string columnValue, IVsSearchToken searchToken)
 => (columnValue is not null) && (columnValue.IndexOf(searchToken.ParsedTokenText, StringComparison.OrdinalIgnoreCase) >= 0);
Example #10
0
        private bool AtLeastOneColumnOrDetailsContentMatches(ITableEntryHandle entry, IVsSearchToken searchToken, string[] cachedColumnValues)
        {
            if (cachedColumnValues[0] == null)
            {
                cachedColumnValues[0] = GetDetailsContentAsString(entry);
            }

            var detailsContent = cachedColumnValues[0];

            if (detailsContent != null && Match(detailsContent, searchToken))
            {
                return(true);
            }

            for (var i = 0; i < _visibleColumns.Count; i++)
            {
                if (cachedColumnValues[i + 1] == null)
                {
                    cachedColumnValues[i + 1] = GetColumnValueAsString(entry, _visibleColumns[i]);
                }

                var columnValue = cachedColumnValues[i + 1];
                System.Diagnostics.Debug.Assert(columnValue != null);

                if (columnValue != null && Match(columnValue, searchToken))
                {
                    // Found match in this column
                    return(true);
                }
            }

            // No match found in this entry
            return(false);
        }
 public uint GetTokens(uint dwMaxTokens, IVsSearchToken[] rgpSearchTokens)
 {
     throw new NotImplementedException();
 }