From 74c75ad0d1fd76f42bc64c26d420d069f0f6bdd1 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 7 Jan 2018 13:08:18 -0800 Subject: [PATCH] Do not sort workspace symbols in vscode. vscode assumes the order does not change. --- src/config.h | 6 +++++ src/messages/workspace_symbol.cc | 40 +++++++++++++++++++------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/config.h b/src/config.h index f5e593e4..e0ccf2a1 100644 --- a/src/config.h +++ b/src/config.h @@ -27,6 +27,10 @@ struct Config { // Maximum workspace search results. int maxWorkspaceSearchResults = 500; + // If true, workspace search results will be dynamically rescored/reordered + // as the search progresses. Some clients do their own ordering and assume + // that the results stay sorted in the same order as the search progresses. + bool sortWorkspaceSearchResults = true; // Force a certain number of indexer threads. If less than 1 a default value // should be used. @@ -100,6 +104,8 @@ MAKE_REFLECT_STRUCT(Config, logSkippedPathsForIndex, maxWorkspaceSearchResults, + sortWorkspaceSearchResults, + indexerCount, enableIndexing, enableCacheWrite, diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index dfa622e8..8531f90c 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -242,24 +242,32 @@ struct WorkspaceSymbolHandler : BaseMessageHandler { } } - // Sort results with a fuzzy matching algorithm. - int longest = 0; - for (int i : result_indices) - longest = std::max(longest, int(db->short_names[i].size())); + if (config->sortWorkspaceSearchResults) { + // Sort results with a fuzzy matching algorithm. + int longest = 0; + for (int i : result_indices) + longest = std::max(longest, int(db->short_names[i].size())); - std::vector score(longest), // score for each position - dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i] - std::vector> permutation(result_indices.size()); - for (int i = 0; i < int(result_indices.size()); i++) { - permutation[i] = { - FuzzyEvaluate(query, db->short_names[result_indices[i]], score, dp), - i}; + std::vector score(longest); // score for each position + std::vector dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i] + std::vector> permutation(result_indices.size()); + for (int i = 0; i < int(result_indices.size()); i++) { + permutation[i] = { + FuzzyEvaluate(query, db->short_names[result_indices[i]], score, dp), + i}; + } + std::sort(permutation.begin(), permutation.end(), + std::greater>()); + out.result.reserve(result_indices.size()); + for (int i = 0; i < int(result_indices.size()); i++) + out.result.push_back(std::move(unsorted_results[permutation[i].second])); } - std::sort(permutation.begin(), permutation.end(), - std::greater>()); - out.result.reserve(result_indices.size()); - for (int i = 0; i < int(result_indices.size()); i++) - out.result.push_back(std::move(unsorted_results[permutation[i].second])); + else { + out.result.reserve(unsorted_results.size()); + for (const auto& entry : unsorted_results) + out.result.push_back(std::move(entry)); + } + LOG_S(INFO) << "[querydb] Found " << out.result.size() << " results for query " << query;