Skip to content

Commit

Permalink
Add warning message if max. number of results is hit during a search
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaquay committed Nov 16, 2016
1 parent 0773bf0 commit a21a076
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/Core/Linq/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,21 @@ public static void ForAll<TSource>(this IEnumerable<TSource> source, Action<int,
}
}

public static IEnumerable<T> ConcatSingle<T>(this IEnumerable<T> source, T item) {
return source.Concat(Single(item));
}

public static IEnumerable<T> ConcatSingle<T>(this IEnumerable<T> source, T item, Func<bool> filter) {
if (filter())
return source.ConcatSingle(item);
else
return source;
}

public static IEnumerable<T> Single<T>(T item) {
return Enumerable.Repeat(item, 1);
}

public static ReadOnlyCollection<TSource> ToReadOnlyCollection<TSource>(this IEnumerable<TSource> source) {
var coll = source as ReadOnlyCollection<TSource>;
if (coll != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ private List<TreeViewItemViewModel> CreateSearchFilePathsResult(
FilePathSearchInfo searchInfo,
DirectoryEntry fileResults,
string description,
string additionalWarning,
bool expandAll) {

Action<FileSystemEntryViewModel> setLineColumn = entry => {
Expand All @@ -377,23 +378,27 @@ private List<TreeViewItemViewModel> CreateSearchFilePathsResult(
};

var rootNode = new RootTreeViewItemViewModel(StandarImageSourceFactory);
var result =
new List<TreeViewItemViewModel> {
new TextItemViewModel(StandarImageSourceFactory, rootNode, description)
}
var result = Enumerable
.Empty<TreeViewItemViewModel>()
.ConcatSingle(new TextItemViewModel(StandarImageSourceFactory, rootNode, description))
.ConcatSingle(new TextWarningItemViewModel(StandarImageSourceFactory, rootNode, additionalWarning), () => !string.IsNullOrEmpty(additionalWarning))
.Concat(fileResults.Entries.Select(x => FileSystemEntryViewModel.Create(this, rootNode, x, setLineColumn)))
.ToList();
result.ForAll(rootNode.AddChild);
TreeViewItemViewModel.ExpandNodes(result, expandAll);
return result;
}

private List<TreeViewItemViewModel> CreateSearchCodeResultViewModel(DirectoryEntry searchResults, string description, bool expandAll) {
private List<TreeViewItemViewModel> CreateSearchCodeResultViewModel(
DirectoryEntry searchResults,
string description,
string additionalWarning,
bool expandAll) {
var rootNode = new RootTreeViewItemViewModel(StandarImageSourceFactory);
var result =
new List<TreeViewItemViewModel> {
new TextItemViewModel(StandarImageSourceFactory, rootNode, description)
}
var result = Enumerable
.Empty<TreeViewItemViewModel>()
.ConcatSingle(new TextItemViewModel(StandarImageSourceFactory, rootNode, description))
.ConcatSingle(new TextWarningItemViewModel(StandarImageSourceFactory, rootNode, additionalWarning), () => !string.IsNullOrEmpty(additionalWarning))
.Concat(searchResults.Entries.Select(x => FileSystemEntryViewModel.Create(this, rootNode, x, _ => { })))
.ToList();
result.ForAll(rootNode.AddChild);
Expand Down Expand Up @@ -632,14 +637,15 @@ private FilePathSearchInfo PreprocessFilePathSearchPattern(string searchPattern)

private void SearchFilesPaths(string searchPattern, bool immediate) {
var searchInfo = PreprocessFilePathSearchPattern(searchPattern);
var maxResults = GlobalSettings.SearchFilePathsMaxResults;
SearchWorker(new SearchWorkerParams {
OperationName = OperationsIds.SearchFilePaths,
HintText = "Searching for matching file paths...",
Delay = TimeSpan.FromMilliseconds(immediate ? 0 : GlobalSettings.AutoSearchDelayMsec),
TypedRequest = new SearchFilePathsRequest {
SearchParams = new SearchParams {
SearchString = searchInfo.SearchPattern,
MaxResults = GlobalSettings.SearchFilePathsMaxResults,
MaxResults = maxResults,
MatchCase = false, //ViewModel.MatchCase,
MatchWholeWord = false, //ViewModel.MatchWholeWord,
IncludeSymLinks = ViewModel.IncludeSymLinks,
Expand All @@ -665,14 +671,16 @@ private void SearchFilesPaths(string searchPattern, bool immediate) {
if (searchInfo.ColumnNumber >= 0) {
msg += ", Column " + (searchInfo.ColumnNumber + 1);
}
var viewModel = CreateSearchFilePathsResult(searchInfo, response.SearchResult, msg, true);
var limitMsg = CreateMaxResultsHitMessage(response.HitCount, maxResults);
var viewModel = CreateSearchFilePathsResult(searchInfo, response.SearchResult, msg, limitMsg, true);
_searchResultDocumentChangeTracker.Disable();
ViewModel.SetSearchFilePathsResult(viewModel);
}
});
}

private void SearchCode(string searchPattern, string filePathPattern, bool immediate) {
var maxResults = GlobalSettings.SearchCodeMaxResults;
SearchWorker(new SearchWorkerParams {
OperationName = OperationsIds.SearchCode,
HintText = "Searching for matching text in files...",
Expand All @@ -681,7 +689,7 @@ private void SearchCode(string searchPattern, string filePathPattern, bool immed
SearchParams = new SearchParams {
SearchString = searchPattern,
FilePathPattern = filePathPattern,
MaxResults = GlobalSettings.SearchCodeMaxResults,
MaxResults = maxResults,
MatchCase = ViewModel.MatchCase,
MatchWholeWord = ViewModel.MatchWholeWord,
IncludeSymLinks = ViewModel.IncludeSymLinks,
Expand Down Expand Up @@ -713,14 +721,26 @@ private void SearchCode(string searchPattern, string filePathPattern, bool immed
if (!string.IsNullOrEmpty(filePathPattern)) {
msg += string.Format(", File Paths: \"{0}\"", filePathPattern);
}
var limitMsg = CreateMaxResultsHitMessage(response.HitCount, maxResults);
bool expandAll = response.HitCount < HardCodedSettings.SearchCodeExpandMaxResults;
var result = CreateSearchCodeResultViewModel(response.SearchResults, msg, expandAll);
var result = CreateSearchCodeResultViewModel(response.SearchResults, msg, limitMsg, expandAll);
ViewModel.SetSearchCodeResult(result);
_searchResultDocumentChangeTracker.Enable(response.SearchResults);
}
});
}

private string CreateMaxResultsHitMessage(long hitCount, long maxResults) {
if (hitCount >= maxResults) {
return string.Format(
"Maximum number of results ({0:n0}) hit - some results omitted. " +
"Use Tools-> Options -> VsChromium -> General to increase the limit, " +
"or change your query to exclude more results.",
maxResults);
}
return "";
}

enum Direction {
Next,
Previous
Expand Down

0 comments on commit a21a076

Please sign in to comment.