Do not sort workspace symbols in vscode.

vscode assumes the order does not change.
This commit is contained in:
Jacob Dufault 2018-01-07 13:08:18 -08:00
parent 09d9d5eedc
commit 74c75ad0d1
2 changed files with 30 additions and 16 deletions

View File

@ -27,6 +27,10 @@ struct Config {
// Maximum workspace search results. // Maximum workspace search results.
int maxWorkspaceSearchResults = 500; 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 // Force a certain number of indexer threads. If less than 1 a default value
// should be used. // should be used.
@ -100,6 +104,8 @@ MAKE_REFLECT_STRUCT(Config,
logSkippedPathsForIndex, logSkippedPathsForIndex,
maxWorkspaceSearchResults, maxWorkspaceSearchResults,
sortWorkspaceSearchResults,
indexerCount, indexerCount,
enableIndexing, enableIndexing,
enableCacheWrite, enableCacheWrite,

View File

@ -242,24 +242,32 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
} }
} }
// Sort results with a fuzzy matching algorithm. if (config->sortWorkspaceSearchResults) {
int longest = 0; // Sort results with a fuzzy matching algorithm.
for (int i : result_indices) int longest = 0;
longest = std::max(longest, int(db->short_names[i].size())); for (int i : result_indices)
longest = std::max(longest, int(db->short_names[i].size()));
std::vector<int> score(longest), // score for each position std::vector<int> score(longest); // score for each position
dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i] std::vector<int> dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i]
std::vector<std::pair<int, int>> permutation(result_indices.size()); std::vector<std::pair<int, int>> permutation(result_indices.size());
for (int i = 0; i < int(result_indices.size()); i++) { for (int i = 0; i < int(result_indices.size()); i++) {
permutation[i] = { permutation[i] = {
FuzzyEvaluate(query, db->short_names[result_indices[i]], score, dp), FuzzyEvaluate(query, db->short_names[result_indices[i]], score, dp),
i}; i};
}
std::sort(permutation.begin(), permutation.end(),
std::greater<std::pair<int, int>>());
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(), else {
std::greater<std::pair<int, int>>()); out.result.reserve(unsorted_results.size());
out.result.reserve(result_indices.size()); for (const auto& entry : unsorted_results)
for (int i = 0; i < int(result_indices.size()); i++) out.result.push_back(std::move(entry));
out.result.push_back(std::move(unsorted_results[permutation[i].second])); }
LOG_S(INFO) << "[querydb] Found " << out.result.size() LOG_S(INFO) << "[querydb] Found " << out.result.size()
<< " results for query " << query; << " results for query " << query;