Esempio n. 1
0
        public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
        {
            return(Task.Run(delegate {
                try {
                    if (pattern.HasLineNumber)
                    {
                        return;
                    }
                    CommandTargetRoute route = new CommandTargetRoute(MainToolbar.LastCommandTarget);
                    var matcher = StringMatcher.GetMatcher(pattern.Pattern, false);

                    foreach (var cmdTuple in allCommands)
                    {
                        token.ThrowIfCancellationRequested();
                        var cmd = cmdTuple.Item1;
                        var matchString = cmdTuple.Item2;
                        int rank;

                        if (matcher.CalcMatchRank(matchString, out rank))
                        {
                            searchResultCallback.ReportResult(new CommandResult(cmd, null, route, pattern.Pattern, matchString, rank));
                        }
                    }
                } catch (OperationCanceledException) {
                }
            }));
        }
Esempio n. 2
0
        public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
        {
            if (pattern.HasLineNumber)
            {
                return(Task.CompletedTask);
            }
            var route   = new CommandTargetRoute(IdeApp.CommandService.LastCommandTarget);
            var matcher = StringMatcher.GetMatcher(pattern.Pattern, false);

            foreach (var cmd in GetAllCommands())
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }
                var matchString = cmd.DisplayName;

                if (matcher.CalcMatchRank(matchString, out var rank))
                {
                    if ((cmd as ActionCommand)?.RuntimeAddin == currentRuntimeAddin)
                    {
                        rank += 1;                         // we prefer commands comming from the addin
                    }
                    searchResultCallback.ReportResult(new CommandResult(cmd, null, route, pattern.Pattern, matchString, rank));
                }
            }
            return(Task.CompletedTask);
        }
		public override Task GetResults (ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
		{
			if (IsProjectSelected ()) {
				searchResultCallback.ReportResult (new SearchPackageSearchResult (pattern));
			}
			return SpecializedTasks.EmptyTask;
		}
Esempio n. 4
0
 public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
 {
     return(Task.Run(delegate {
         var files = AllFiles.ToList();
         var matcher = StringMatcher.GetMatcher(pattern.Pattern, false);
         var savedMatches = new Dictionary <string, MatchResult> ();
         foreach (ProjectFile file in files)
         {
             if (token.IsCancellationRequested)
             {
                 break;
             }
             int rank;
             string matchString = System.IO.Path.GetFileName(file.FilePath);
             if (MatchName(savedMatches, matcher, matchString, out rank))
             {
                 searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, matchString, rank, file, true));
             }
             matchString = FileSearchResult.GetRelProjectPath(file);
             if (MatchName(savedMatches, matcher, matchString, out rank))
             {
                 searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, matchString, rank, file, true));
             }
         }
     }, token));
 }
 public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
 {
     if (IdeApp.ProjectOperations.CurrentSelectedSolution != null)
     {
         searchResultCallback.ReportResult(new SearchInSolutionSearchResult(pattern));
     }
     return(SpecializedTasks.EmptyTask);
 }
Esempio n. 6
0
 public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
 {
     if (IsProjectSelected())
     {
         searchResultCallback.ReportResult(new SearchPackageSearchResult(pattern));
     }
     return(Task.CompletedTask);
 }
Esempio n. 7
0
        public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
        {
            return(Task.Run(async delegate {
                List <Tuple <string, string, ProjectFile> > files;
                //This lock is here in case user quickly types 5 letters which triggers 5 threads
                //we don't want to use all CPU doing same thing, instead 1st one will create cache, others will wait here
                //and then all will use cached version...
                bool locked = false;
                try {
                    locked = await allFilesLock.WaitAsync(System.Threading.Timeout.Infinite, token).ConfigureAwait(false);
                    files = allFilesCache = allFilesCache ?? GenerateAllFiles();
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                } finally {
                    if (locked)
                    {
                        allFilesLock.Release();
                    }
                }

                var matcher = StringMatcher.GetMatcher(pattern.Pattern, false);
                var savedMatches = new Dictionary <string, MatchResult> (files.Count * 2);
                foreach (var file in files)
                {
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                    int rank1;
                    int rank2;
                    var match1 = MatchName(savedMatches, matcher, file.Item1, out rank1);
                    var match2 = MatchName(savedMatches, matcher, file.Item2, out rank2);
                    if (match1 && match2)
                    {
                        if (rank1 > rank2 || (rank1 == rank2 && String.CompareOrdinal(file.Item1, file.Item2) > 0))
                        {
                            searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item1, rank1, file.Item3));
                        }
                        else
                        {
                            searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item2, rank2, file.Item3));
                        }
                    }
                    else if (match1)
                    {
                        searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item1, rank1, file.Item3));
                    }
                    else if (match2)
                    {
                        searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item2, rank2, file.Item3));
                    }
                }
            }, token));
        }
 public override Task GetResults(
     ISearchResultCallback searchResultCallback,
     SearchPopupSearchPattern pattern,
     CancellationToken token)
 {
     if (pattern.Tag == null || IsValidTag(pattern.Tag))
     {
         searchResultCallback.ReportResult(new PortableClassLibrarySearchResult());
     }
     return(Task.FromResult(1));
 }
Esempio n. 9
0
        public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern searchPattern, CancellationToken token)
        {
            return(Task.Run(async delegate {
                if (searchPattern.Tag != null && !(typeTags.Contains(searchPattern.Tag) || memberTags.Contains(searchPattern.Tag)) || searchPattern.HasLineNumber)
                {
                    return;
                }
                try {
                    if (SymbolInfoTask == null)
                    {
                        SymbolInfoTask = Task.FromResult(default(SymbolCache)).ContinueWith(t => GetSymbolInfos(token));
                    }
                    var cache = await SymbolInfoTask.ConfigureAwait(false);
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    string toMatch = searchPattern.Pattern;
                    var newResult = new WorkerResult();
                    newResult.pattern = searchPattern.Pattern;
                    newResult.Tag = searchPattern.Tag;
                    newResult.matcher = StringMatcher.GetMatcher(toMatch, false);
                    newResult.FullSearch = toMatch.IndexOf('.') > 0;

                    var oldLastResult = lastResult;
                    if (newResult.FullSearch && oldLastResult != null && !oldLastResult.FullSearch)
                    {
                        oldLastResult = new WorkerResult();
                    }

                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    IReadOnlyList <DeclaredSymbolInfo> allTypes = null;
                    if (!IsSameFilterStart(oldLastResult, newResult))
                    {
                        allTypes = cache.GetAllTypes(searchPattern.Tag, token);
                    }

//					var now = DateTime.Now;
                    AllResults(searchResultCallback, newResult, allTypes ?? lastResult.filteredSymbols, token);
                    //newResult.results.SortUpToN (new DataItemComparer (token), resultsCount);
                    lastResult = newResult;
                    //					Console.WriteLine ((now - DateTime.Now).TotalMilliseconds);
                } catch {
                    token.ThrowIfCancellationRequested();
                    throw;
                }
            }, token));
        }
        public override Task GetResults(
            ISearchResultCallback searchResultCallback,
            SearchPopupSearchPattern pattern,
            CancellationToken token)
        {
            var activeDocument = IdeApp.Workbench.ActiveDocument;

            if (activeDocument != null)
            {
                return(GetResults(activeDocument, searchResultCallback, pattern, token));
            }
            return(Task.CompletedTask);
        }
        Task GetResults(
            Document activeDocument,
            ISearchResultCallback searchResultCallback,
            SearchPopupSearchPattern pattern,
            CancellationToken token)
        {
            LanguageClientSession session = LanguageClientServices.Workspace.GetSession(activeDocument, false);

            if (session?.IsWorkspaceSymbolProvider == true)
            {
                return(GetResults(session, searchResultCallback, pattern, token));
            }

            return(Task.CompletedTask);
        }
 public override Task GetResults(
     ISearchResultCallback searchResultCallback,
     SearchPopupSearchPattern pattern,
     CancellationToken token)
 {
     if (pattern.Tag == null || IsValidTag(pattern.Tag))
     {
         var command = new InstallPackageCommand(pattern.Pattern);
         var result  = new InstallPackageSearchResult(command);
         if (result.CanBeDisplayed())
         {
             searchResultCallback.ReportResult(result);
         }
     }
     return(Task.FromResult(0));
 }
        async Task GetResults(
            LanguageClientSession session,
            ISearchResultCallback searchResultCallback,
            SearchPopupSearchPattern pattern,
            CancellationToken token)
        {
            SymbolInformation[] results = await session.GetWorkspaceSymbols(pattern.Pattern, token).ConfigureAwait(false);

            if (results != null && results.Length > 0)
            {
                foreach (var result in results)
                {
                    var searchResult = new WorkspaceSymbolSearchResult(pattern.Pattern, result);
                    searchResultCallback.ReportResult(searchResult);
                }
            }
        }
        public override Task GetResults(
            ISearchResultCallback searchResultCallback,
            SearchPopupSearchPattern pattern,
            CancellationToken token)
        {
            if (!CanSearch(pattern.Tag))
            {
                return(Task.FromResult(0));
            }

            return(Task.Factory.StartNew(() => {
                var dataSource = new PaketSearchDataSource(pattern);
                foreach (PaketSearchResult result in dataSource.GetResults())
                {
                    searchResultCallback.ReportResult(result);
                }
            }));
        }
Esempio n. 15
0
 void AllResults(ISearchResultCallback searchResultCallback, WorkerResult newResult, IReadOnlyList <DeclaredSymbolInfo> allTypes, CancellationToken token)
 {
     // Search Types
     newResult.filteredSymbols = new List <DeclaredSymbolInfo> ();
     foreach (var type in allTypes)
     {
         if (token.IsCancellationRequested)
         {
             newResult.filteredSymbols = null;
             return;
         }
         SearchResult curResult = newResult.CheckType(type);
         if (curResult != null)
         {
             newResult.filteredSymbols.Add(type);
             searchResultCallback.ReportResult(curResult);
         }
     }
 }
Esempio n. 16
0
		public override Task GetResults (ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
		{
			return Task.Run (delegate {
				var files = AllFiles.ToList ();
				var matcher = StringMatcher.GetMatcher (pattern.Pattern, false);
				var savedMatches = new Dictionary<string, MatchResult> ();
				foreach (ProjectFile file in files) {
					if (token.IsCancellationRequested)
						break;
					int rank;
					string matchString = System.IO.Path.GetFileName (file.FilePath);
					if (MatchName (savedMatches, matcher, matchString, out rank))
						searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, matchString, rank, file, true));
					matchString = FileSearchResult.GetRelProjectPath (file);
					if (MatchName (savedMatches, matcher, matchString, out rank)) 
						searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, matchString, rank, file, true));
					
				}
 			}, token);
		}
Esempio n. 17
0
		public override Task GetResults (ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
		{
			return Task.Run (delegate {
				try {
					if (pattern.HasLineNumber)
						return;
					CommandTargetRoute route = new CommandTargetRoute (MainToolbar.LastCommandTarget);
					var matcher = StringMatcher.GetMatcher (pattern.Pattern, false);

					foreach (var cmdTuple in allCommands) {
						token.ThrowIfCancellationRequested ();
						var cmd = cmdTuple.Item1;
						var matchString = cmdTuple.Item2;
						int rank;

						if (matcher.CalcMatchRank (matchString, out rank))
							searchResultCallback.ReportResult (new CommandResult (cmd, null, route, pattern.Pattern, matchString, rank));
					}
				} catch (OperationCanceledException) {
				}
			});
		}
        void AllResults(ISearchResultCallback searchResultCallback, WorkerResult lastResult, WorkerResult newResult, IEnumerable <DeclaredSymbolInfo> completeTypeList, CancellationToken token)
        {
            // Search Types
            newResult.filteredSymbols = new List <DeclaredSymbolInfo> ();
            bool startsWithLastFilter = lastResult.pattern != null && newResult.pattern.StartsWith(lastResult.pattern, StringComparison.Ordinal) && lastResult.filteredSymbols != null;
            var  allTypes             = startsWithLastFilter ? lastResult.filteredSymbols : completeTypeList;

            foreach (var type in allTypes)
            {
                if (token.IsCancellationRequested)
                {
                    newResult.filteredSymbols = null;
                    return;
                }
                SearchResult curResult = newResult.CheckType(type);
                if (curResult != null)
                {
                    newResult.filteredSymbols.Add(type);
                    searchResultCallback.ReportResult(curResult);
                }
            }
        }
        public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern searchPattern, CancellationToken token)
        {
            return(Task.Run(async delegate {
                if (searchPattern.Tag != null && !(typeTags.Contains(searchPattern.Tag) || memberTags.Contains(searchPattern.Tag)) || searchPattern.HasLineNumber)
                {
                    return null;
                }
                try {
                    var newResult = new WorkerResult(widget);
                    newResult.pattern = searchPattern.Pattern;
                    newResult.Tag = searchPattern.Tag;
                    List <DeclaredSymbolInfo> allTypes;
                    if (SymbolInfoTask == null)
                    {
                        SymbolInfoTask = Task.FromResult(GetSymbolInfos(token));
                    }
                    var cache = await SymbolInfoTask.ConfigureAwait(false);
                    allTypes = cache.AllTypes;
                    string toMatch = searchPattern.Pattern;
                    newResult.matcher = StringMatcher.GetMatcher(toMatch, false);
                    newResult.FullSearch = toMatch.IndexOf('.') > 0;
                    var oldLastResult = lastResult;
                    if (newResult.FullSearch && oldLastResult != null && !oldLastResult.FullSearch)
                    {
                        oldLastResult = new WorkerResult(widget);
                    }
//					var now = DateTime.Now;

                    AllResults(searchResultCallback, oldLastResult, newResult, allTypes, token);
                    //newResult.results.SortUpToN (new DataItemComparer (token), resultsCount);
                    lastResult = newResult;
//					Console.WriteLine ((now - DateTime.Now).TotalMilliseconds);
                    return (ISearchDataSource)newResult.results;
                } catch {
                    token.ThrowIfCancellationRequested();
                    throw;
                }
            }, token));
        }
Esempio n. 20
0
 public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
 {
     return(Task.Run(delegate {
         var files = allFilesCache = allFilesCache ?? GenerateAllFiles();
         var matcher = StringMatcher.GetMatcher(pattern.Pattern, false);
         var savedMatches = new Dictionary <string, MatchResult> ();
         foreach (var file in files)
         {
             if (token.IsCancellationRequested)
             {
                 break;
             }
             int rank1;
             int rank2;
             var match1 = MatchName(savedMatches, matcher, file.Item1, out rank1);
             var match2 = MatchName(savedMatches, matcher, file.Item2, out rank2);
             if (match1 && match2)
             {
                 if (rank1 > rank2 || (rank1 == rank2 && String.CompareOrdinal(file.Item1, file.Item2) > 0))
                 {
                     searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item1, rank1, file.Item3));
                 }
                 else
                 {
                     searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item2, rank2, file.Item3));
                 }
             }
             else if (match1)
             {
                 searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item1, rank1, file.Item3));
             }
             else if (match2)
             {
                 searchResultCallback.ReportResult(new FileSearchResult(pattern.Pattern, file.Item2, rank2, file.Item3));
             }
         }
     }, token));
 }
        void AllResults(ISearchResultCallback searchResultCallback, WorkerResult lastResult, WorkerResult newResult, IReadOnlyList <DeclaredSymbolInfo> completeTypeList, CancellationToken token)
        {
            if (newResult.isGotoFilePattern)
            {
                return;
            }
            uint x = 0;

            // Search Types
            newResult.filteredSymbols = new List <DeclaredSymbolInfo> ();
            bool startsWithLastFilter = lastResult.pattern != null && newResult.pattern.StartsWith(lastResult.pattern, StringComparison.Ordinal) && lastResult.filteredSymbols != null;
            var  allTypes             = startsWithLastFilter ? lastResult.filteredSymbols : completeTypeList;

            foreach (var type in allTypes)
            {
                if (unchecked (x++) % 100 == 0 && token.IsCancellationRequested)
                {
                    newResult.filteredSymbols = null;
                    return;
                }

                if (type.Kind == DeclaredSymbolInfoKind.Constructor ||
                    type.Kind == DeclaredSymbolInfoKind.Module ||
                    type.Kind == DeclaredSymbolInfoKind.Indexer)
                {
                    continue;
                }

                if (newResult.Tag != null)
                {
                    if ((newResult.Tag == "type" || newResult.Tag == "t") && type.Kind != DeclaredSymbolInfoKind.Class && type.Kind != DeclaredSymbolInfoKind.Struct && type.Kind != DeclaredSymbolInfoKind.Interface && type.Kind != DeclaredSymbolInfoKind.Enum && type.Kind != DeclaredSymbolInfoKind.Delegate)
                    {
                        continue;
                    }

                    if (newResult.Tag == "class" && type.Kind != DeclaredSymbolInfoKind.Class)
                    {
                        continue;
                    }
                    if (newResult.Tag == "struct" && type.Kind != DeclaredSymbolInfoKind.Struct)
                    {
                        continue;
                    }
                    if (newResult.Tag == "interface" && type.Kind != DeclaredSymbolInfoKind.Interface)
                    {
                        continue;
                    }
                    if (newResult.Tag == "enum" && type.Kind != DeclaredSymbolInfoKind.Enum)
                    {
                        continue;
                    }
                    if (newResult.Tag == "delegate" && type.Kind != DeclaredSymbolInfoKind.Delegate)
                    {
                        continue;
                    }

                    if ((newResult.Tag == "member" || newResult.Tag == "m") && type.Kind != DeclaredSymbolInfoKind.Method && type.Kind != DeclaredSymbolInfoKind.Property && type.Kind != DeclaredSymbolInfoKind.Field && type.Kind != DeclaredSymbolInfoKind.Event)
                    {
                        continue;
                    }
                    if (newResult.Tag == "method" && type.Kind != DeclaredSymbolInfoKind.Method)
                    {
                        continue;
                    }
                    if (newResult.Tag == "property" && type.Kind != DeclaredSymbolInfoKind.Property)
                    {
                        continue;
                    }
                    if (newResult.Tag == "field" && type.Kind != DeclaredSymbolInfoKind.Field)
                    {
                        continue;
                    }
                    if (newResult.Tag == "event" && type.Kind != DeclaredSymbolInfoKind.Event)
                    {
                        continue;
                    }
                }
                SearchResult curResult = newResult.CheckType(type);
                if (curResult != null)
                {
                    newResult.filteredSymbols.Add(type);
                    newResult.results.AddResult(curResult);
                    searchResultCallback.ReportResult(curResult);
                }
            }
        }
Esempio n. 22
0
 public abstract Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token);
		void AllResults (ISearchResultCallback searchResultCallback, WorkerResult lastResult, WorkerResult newResult, IReadOnlyList<DeclaredSymbolInfo> completeTypeList, CancellationToken token)
		{
			// Search Types
			newResult.filteredSymbols = new List<DeclaredSymbolInfo> ();
			bool startsWithLastFilter = lastResult.pattern != null && newResult.pattern.StartsWith (lastResult.pattern, StringComparison.Ordinal) && lastResult.filteredSymbols != null;
			var allTypes = startsWithLastFilter ? lastResult.filteredSymbols : completeTypeList;
			foreach (var type in allTypes) {
				if (token.IsCancellationRequested) {
					newResult.filteredSymbols = null;
					return;
				}
				SearchResult curResult = newResult.CheckType (type);
				if (curResult != null) {
					newResult.filteredSymbols.Add (type);
					searchResultCallback.ReportResult (curResult);
				}
			}
		}
		public override Task GetResults (ISearchResultCallback searchResultCallback, SearchPopupSearchPattern searchPattern, CancellationToken token)
		{
			return Task.Run (async delegate {
				if (searchPattern.Tag != null && !(typeTags.Contains (searchPattern.Tag) || memberTags.Contains (searchPattern.Tag)) || searchPattern.HasLineNumber)
					return;
				try {
					if (SymbolInfoTask == null)
						SymbolInfoTask = Task.FromResult (default(SymbolCache)).ContinueWith(t => GetSymbolInfos (token));
					var cache = await SymbolInfoTask.ConfigureAwait (false);
					var allTypes = cache.GetAllTypes (searchPattern.Tag, token);
					if (token.IsCancellationRequested)
						return;
					string toMatch = searchPattern.Pattern;
					var newResult = new WorkerResult ();
					newResult.pattern = searchPattern.Pattern;
					newResult.Tag = searchPattern.Tag;
					newResult.matcher = StringMatcher.GetMatcher (toMatch, false);
					newResult.FullSearch = toMatch.IndexOf ('.') > 0;
					var oldLastResult = lastResult;
					if (newResult.FullSearch && oldLastResult != null && !oldLastResult.FullSearch)
						oldLastResult = new WorkerResult ();
//					var now = DateTime.Now;

					AllResults (searchResultCallback, oldLastResult, newResult, allTypes, token);
					//newResult.results.SortUpToN (new DataItemComparer (token), resultsCount);
					lastResult = newResult;
					//					Console.WriteLine ((now - DateTime.Now).TotalMilliseconds);
				} catch {
					token.ThrowIfCancellationRequested ();
					throw;
				}
			}, token);
		}
		public override Task GetResults (ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
		{
			return Task.Run (delegate {
				List<Tuple<string, string, ProjectFile>> files;
				//This lock is here in case user quickly types 5 letters which triggers 5 threads
				//we don't want to use all CPU doing same thing, instead 1st one will create cache, others will wait here
				//and then all will use cached version...
				lock (allFilesLock) {
					files = allFilesCache = allFilesCache ?? GenerateAllFiles ();
				}
				var matcher = StringMatcher.GetMatcher (pattern.Pattern, false);
				var savedMatches = new Dictionary<string, MatchResult> (files.Count * 2);
				foreach (var file in files) {
					if (token.IsCancellationRequested)
						break;
					int rank1;
					int rank2;
					var match1 = MatchName (savedMatches, matcher, file.Item1, out rank1);
					var match2 = MatchName (savedMatches, matcher, file.Item2, out rank2);
					if (match1 && match2) {
						if (rank1 > rank2 || (rank1 == rank2 && String.CompareOrdinal (file.Item1, file.Item2) > 0)) {
							searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, file.Item1, rank1, file.Item3));
						} else {
							searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, file.Item2, rank2, file.Item3));
						}
					} else if (match1) {
						searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, file.Item1, rank1, file.Item3));
					} else if (match2) {
						searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, file.Item2, rank2, file.Item3));
					}
				}
			}, token);
		}
Esempio n. 26
0
        public override Task GetResults(ISearchResultCallback searchResultCallback, SearchPopupSearchPattern searchPattern, CancellationToken token)
        {
            if (string.IsNullOrEmpty(searchPattern.Pattern))
            {
                return(Task.CompletedTask);
            }

            if (searchPattern.Tag != null && !tags.Contains(searchPattern.Tag) || searchPattern.HasLineNumber)
            {
                return(Task.CompletedTask);
            }

            return(Task.Run(async delegate {
                try {
                    var kinds = GetTagKinds(searchPattern.Tag);
                    // Maybe use language services instead of AbstractNavigateToSearchService
                    var aggregatedResults = await Task.WhenAll(TypeSystemService.AllWorkspaces
                                                               .Select(ws => ws.CurrentSolution)
                                                               .SelectMany(sol => sol.Projects)
                                                               .Select(async proj => {
                        using (proj.Solution.Services.CacheService?.EnableCaching(proj.Id)) {
                            var searchService = TryGetNavigateToSearchService(proj);
                            if (searchService == null)
                            {
                                return ImmutableArray <INavigateToSearchResult> .Empty;
                            }
                            return await searchService.SearchProjectAsync(proj, searchPattern.Pattern, kinds ?? searchService.KindsProvided, token).ConfigureAwait(false);
                        }
                    })
                                                               ).ConfigureAwait(false);

                    foreach (var results in aggregatedResults)
                    {
                        foreach (var result in results)
                        {
                            int laneLength = result.NameMatchSpans.Length;
                            int index = laneLength > 0 ? result.NameMatchSpans [0].Start : -1;

                            int rank = 0;
                            if (result.MatchKind == NavigateToMatchKind.Exact)
                            {
                                rank = int.MaxValue;
                            }
                            else
                            {
                                int patternLength = searchPattern.Pattern.Length;
                                rank = searchPattern.Pattern.Length - result.Name.Length;
                                rank -= index;

                                rank -= laneLength * 100;

                                // Favor matches with less splits. That is, 'abc def' is better than 'ab c def'.
                                int baseRank = (patternLength - laneLength - 1) * 5000;

                                // First matching letter close to the begining is better
                                // The more matched letters the better
                                rank = baseRank - (index + (laneLength - patternLength));

                                // rank up matches which start with a filter substring
                                if (index == 0)
                                {
                                    rank += result.NameMatchSpans [0].Length * 50;
                                }
                            }

                            if (!result.IsCaseSensitive)
                            {
                                rank /= 2;
                            }

                            searchResultCallback.ReportResult(new DeclaredSymbolInfoResult(
                                                                  searchPattern.Pattern,
                                                                  result.Name,
                                                                  rank,
                                                                  result
                                                                  ));
                        }
                    }
                } catch {
                    token.ThrowIfCancellationRequested();
                    throw;
                }
            }, token));
        }
		void AllResults (ISearchResultCallback searchResultCallback, WorkerResult lastResult, WorkerResult newResult, IReadOnlyList<DeclaredSymbolInfo> completeTypeList, CancellationToken token)
		{
			if (newResult.isGotoFilePattern)
				return;
			uint x = 0;
			// Search Types
			newResult.filteredSymbols = new List<DeclaredSymbolInfo> ();
			bool startsWithLastFilter = lastResult.pattern != null && newResult.pattern.StartsWith (lastResult.pattern, StringComparison.Ordinal) && lastResult.filteredSymbols != null;
			var allTypes = startsWithLastFilter ? lastResult.filteredSymbols : completeTypeList;
			foreach (var type in allTypes) {
				if (unchecked(x++) % 100 == 0 && token.IsCancellationRequested) {
					newResult.filteredSymbols = null;
					return;
				}

				if (type.Kind == DeclaredSymbolInfoKind.Constructor ||
				    type.Kind == DeclaredSymbolInfoKind.Module ||
				    type.Kind == DeclaredSymbolInfoKind.Indexer)
					continue;
				
				if (newResult.Tag != null) {
					if ((newResult.Tag == "type" || newResult.Tag == "t") && type.Kind != DeclaredSymbolInfoKind.Class && type.Kind != DeclaredSymbolInfoKind.Struct && type.Kind != DeclaredSymbolInfoKind.Interface && type.Kind != DeclaredSymbolInfoKind.Enum && type.Kind != DeclaredSymbolInfoKind.Delegate)
					    continue;
					
					if (newResult.Tag == "class" && type.Kind != DeclaredSymbolInfoKind.Class)
						continue;
				    if (newResult.Tag == "struct" && type.Kind != DeclaredSymbolInfoKind.Struct)
						continue;
				    if (newResult.Tag == "interface" && type.Kind != DeclaredSymbolInfoKind.Interface)
						continue;
				    if (newResult.Tag == "enum" && type.Kind != DeclaredSymbolInfoKind.Enum)
						continue;
				    if (newResult.Tag == "delegate" && type.Kind != DeclaredSymbolInfoKind.Delegate)
						continue;

					if ((newResult.Tag == "member" || newResult.Tag == "m") && type.Kind != DeclaredSymbolInfoKind.Method && type.Kind != DeclaredSymbolInfoKind.Property && type.Kind != DeclaredSymbolInfoKind.Field && type.Kind != DeclaredSymbolInfoKind.Event)
					    continue;
					if (newResult.Tag == "method" && type.Kind != DeclaredSymbolInfoKind.Method)
						continue;
					if (newResult.Tag == "property" && type.Kind != DeclaredSymbolInfoKind.Property)
						continue;
					if (newResult.Tag == "field" && type.Kind != DeclaredSymbolInfoKind.Field)
						continue;
					if (newResult.Tag == "event" && type.Kind != DeclaredSymbolInfoKind.Event)
						continue;
					
				}
				SearchResult curResult = newResult.CheckType (type);
				if (curResult != null) {
					newResult.filteredSymbols.Add (type);
					newResult.results.AddResult (curResult);
					searchResultCallback.ReportResult (curResult);
				}
			}
		}
Esempio n. 28
0
		public override Task GetResults (ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
		{
			return Task.Run (delegate {
				var files = allFilesCache = allFilesCache ?? GenerateAllFiles ();
				var matcher = StringMatcher.GetMatcher (pattern.Pattern, false);
				var savedMatches = new Dictionary<string, MatchResult> ();
				foreach (var file in files) {
					if (token.IsCancellationRequested)
						break;
					int rank1;
					int rank2;
					var match1 = MatchName (savedMatches, matcher, file.Item1, out rank1);
					var match2 = MatchName (savedMatches, matcher, file.Item2, out rank2);
					if (match1 && match2) {
						if (rank1 > rank2 || (rank1 == rank2 && String.CompareOrdinal (file.Item1, file.Item2) > 0)) {
							searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, file.Item1, rank1, file.Item3));
						} else {
							searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, file.Item2, rank2, file.Item3));
						}
					} else if (match1) {
						searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, file.Item1, rank1, file.Item3));
					} else if (match2) {
						searchResultCallback.ReportResult (new FileSearchResult (pattern.Pattern, file.Item2, rank2, file.Item3));
					}
				}
			}, token);
		}
		public override Task GetResults (ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
		{
			if (IdeApp.ProjectOperations.CurrentSelectedSolution != null)
				searchResultCallback.ReportResult (new SearchInSolutionSearchResult (pattern));
			return SpecializedTasks.EmptyTask;
		}