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,13 +242,14 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
} }
} }
if (config->sortWorkspaceSearchResults) {
// Sort results with a fuzzy matching algorithm. // Sort results with a fuzzy matching algorithm.
int longest = 0; int longest = 0;
for (int i : result_indices) for (int i : result_indices)
longest = std::max(longest, int(db->short_names[i].size())); 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] = {
@ -260,6 +261,13 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
out.result.reserve(result_indices.size()); out.result.reserve(result_indices.size());
for (int i = 0; i < int(result_indices.size()); i++) for (int i = 0; i < int(result_indices.size()); i++)
out.result.push_back(std::move(unsorted_results[permutation[i].second])); 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() LOG_S(INFO) << "[querydb] Found " << out.result.size()
<< " results for query " << query; << " results for query " << query;