mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 03:55:49 +00:00
Do not sort workspace symbols in vscode.
vscode assumes the order does not change.
This commit is contained in:
parent
09d9d5eedc
commit
74c75ad0d1
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user