mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-21 16:09:40 +00:00
Raise maxWorkspaceSearchResults to 500 and sort results even if the max number has been reached
This commit is contained in:
parent
b52ec9070c
commit
cdcf75ac84
@ -24,7 +24,7 @@ struct Config {
|
|||||||
bool logSkippedPathsForIndex = false;
|
bool logSkippedPathsForIndex = false;
|
||||||
|
|
||||||
// Maximum workspace search results.
|
// Maximum workspace search results.
|
||||||
int maxWorkspaceSearchResults = 200;
|
int maxWorkspaceSearchResults = 500;
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -104,7 +104,26 @@ struct NamespaceHelper {
|
|||||||
std::string name = namespaces[i].get_spelling();
|
std::string name = namespaces[i].get_spelling();
|
||||||
// Empty name indicates unnamed namespace, anonymous struct, anonymous
|
// Empty name indicates unnamed namespace, anonymous struct, anonymous
|
||||||
// union, ...
|
// union, ...
|
||||||
qualifier += name.empty() ? "(anon)" : name;
|
if (name.size())
|
||||||
|
qualifier += name;
|
||||||
|
else
|
||||||
|
switch (namespaces[i].get_kind()) {
|
||||||
|
case CXCursor_ClassDecl:
|
||||||
|
qualifier += "(anon class)";
|
||||||
|
break;
|
||||||
|
case CXCursor_EnumDecl:
|
||||||
|
qualifier += "(anon enum)";
|
||||||
|
break;
|
||||||
|
case CXCursor_StructDecl:
|
||||||
|
qualifier += "(anon struct)";
|
||||||
|
break;
|
||||||
|
case CXCursor_UnionDecl:
|
||||||
|
qualifier += "(anon union)";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qualifier += "(anon)";
|
||||||
|
break;
|
||||||
|
}
|
||||||
qualifier += "::";
|
qualifier += "::";
|
||||||
container_cursor_to_qualified_name[namespaces[i]] = qualifier;
|
container_cursor_to_qualified_name[namespaces[i]] = qualifier;
|
||||||
}
|
}
|
||||||
|
@ -160,13 +160,10 @@ int FuzzyEvaluate(const std::string& pattern,
|
|||||||
pfirst = pstart = false;
|
pfirst = pstart = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enumerate the end position of the match in str.
|
// Enumerate the end position of the match in str. Each removed trailing
|
||||||
|
// character has a penulty of kGapScore.
|
||||||
lefts = kMinScore;
|
lefts = kMinScore;
|
||||||
for (int i = 0; i < int(str.size()); i++)
|
for (int i = 0; i < int(str.size()); i++)
|
||||||
// For function types, db->detailed_names may have trailing characters for
|
|
||||||
// parameters. We do not want to penalize them.
|
|
||||||
// If we use `short_name` instead of `detailed_name` for fuzzy matching, the
|
|
||||||
// penulty kGapScore can be used.
|
|
||||||
lefts = std::max(lefts + kGapScore, dp[i]);
|
lefts = std::max(lefts + kGapScore, dp[i]);
|
||||||
return lefts;
|
return lefts;
|
||||||
}
|
}
|
||||||
@ -227,27 +224,24 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort results with a fuzzy matching algorithm.
|
// Sort results with a fuzzy matching algorithm.
|
||||||
if (unsorted_results.size() < config->maxWorkspaceSearchResults) {
|
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]
|
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,
|
FuzzyEvaluate(query, db->short_names[result_indices[i]], score,
|
||||||
dp),
|
dp),
|
||||||
i};
|
i};
|
||||||
}
|
}
|
||||||
std::sort(permutation.begin(), permutation.end(),
|
std::sort(permutation.begin(), permutation.end(),
|
||||||
std::greater<std::pair<int, int>>());
|
std::greater<std::pair<int, int>>());
|
||||||
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 = std::move(unsorted_results);
|
|
||||||
|
|
||||||
LOG_S(INFO) << "[querydb] Found " << out.result.size()
|
LOG_S(INFO) << "[querydb] Found " << out.result.size()
|
||||||
<< " results for query " << query;
|
<< " results for query " << query;
|
||||||
|
Loading…
Reference in New Issue
Block a user