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.
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,

View File

@ -242,24 +242,32 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
}
}
// 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<int> score(longest), // score for each position
dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i]
std::vector<std::pair<int, int>> 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<int> score(longest); // score for each position
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());
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<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(),
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]));
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;