mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
Format code
This commit is contained in:
parent
a84c863e5e
commit
b8e7a5bcb3
@ -198,15 +198,18 @@ optional<std::string> ClangCursor::get_comments() const {
|
||||
|
||||
// Get associated comment text.
|
||||
CXString cx_raw = clang_Cursor_getRawCommentText(cx_cursor);
|
||||
// The first line starts with a comment marker, but the rest needs un-indenting.
|
||||
// The first line starts with a comment marker, but the rest needs
|
||||
// un-indenting.
|
||||
std::string unindented;
|
||||
for (const char* p = clang_getCString(cx_raw); *p; ) {
|
||||
for (const char* p = clang_getCString(cx_raw); *p;) {
|
||||
auto skip = start_column - 1;
|
||||
for (; skip > 0 && (*p == ' ' || *p == '\t'); p++)
|
||||
skip--;
|
||||
const char* q = p;
|
||||
while (*q != '\n' && *q) q++;
|
||||
if (*q) q++;
|
||||
while (*q != '\n' && *q)
|
||||
q++;
|
||||
if (*q)
|
||||
q++;
|
||||
unindented.insert(unindented.end(), p, q);
|
||||
p = q;
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ bool IsFunctionCallContext(CXCursorKind kind) {
|
||||
case CXCursor_ConversionFunction:
|
||||
case CXCursor_FunctionTemplate:
|
||||
case CXCursor_OverloadedDeclRef:
|
||||
// TODO: we need to test lambdas
|
||||
// TODO: we need to test lambdas
|
||||
case CXCursor_LambdaExpr:
|
||||
return true;
|
||||
|
||||
@ -1040,7 +1040,7 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
|
||||
default:
|
||||
if (!IsFunctionCallContext(cursor.get_kind()))
|
||||
cursor.VisitChildren(&TemplateVisitor, data);
|
||||
/* fallthrough */
|
||||
/* fallthrough */
|
||||
// TODO Add other containers not covered by IsFunctionCallContext
|
||||
case CXCursor_ClassTemplate:
|
||||
break;
|
||||
@ -1058,10 +1058,8 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
|
||||
IndexFunc* called = data->db->Resolve(called_id);
|
||||
OnIndexReference_Function(data->db,
|
||||
ResolveSpelling(cursor.cx_cursor),
|
||||
data->container,
|
||||
called_id,
|
||||
called,
|
||||
/*implicit=*/ false);
|
||||
data->container, called_id, called,
|
||||
/*implicit=*/false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1072,7 +1070,7 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
|
||||
return ClangCursor::VisitResult::Continue;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
if (!kIndexStdDeclarations &&
|
||||
@ -1654,11 +1652,8 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
|
||||
!CursorSpellingContainsString(ref->cursor, param->tu->cx_tu,
|
||||
called->def.short_name)));
|
||||
|
||||
OnIndexReference_Function(db, loc_spelling,
|
||||
ref->container->cursor,
|
||||
called_id,
|
||||
called,
|
||||
is_implicit);
|
||||
OnIndexReference_Function(db, loc_spelling, ref->container->cursor,
|
||||
called_id, called, is_implicit);
|
||||
|
||||
// Checks if |str| starts with |start|. Ignores case.
|
||||
auto str_begin = [](const char* start, const char* str) {
|
||||
|
@ -112,7 +112,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
||||
case VarClass::Member:
|
||||
break;
|
||||
default:
|
||||
continue; // applies to for loop
|
||||
continue; // applies to for loop
|
||||
}
|
||||
is_type_member = var->def->declaring_type.has_value();
|
||||
detailed_name = var->def->short_name;
|
||||
|
@ -50,7 +50,7 @@ void FilterCompletionResponse(Out_TextDocumentComplete* complete_response,
|
||||
}
|
||||
#endif
|
||||
|
||||
auto &items = complete_response->result.items;
|
||||
auto& items = complete_response->result.items;
|
||||
|
||||
// If the text doesn't start with underscore,
|
||||
// remove all candidates that start with underscore.
|
||||
@ -58,7 +58,8 @@ void FilterCompletionResponse(Out_TextDocumentComplete* complete_response,
|
||||
items.erase(std::remove_if(items.begin(), items.end(),
|
||||
[](const lsCompletionItem& item) {
|
||||
return item.label[0] == '_';
|
||||
}), items.end());
|
||||
}),
|
||||
items.end());
|
||||
}
|
||||
|
||||
// find the exact text
|
||||
@ -72,7 +73,8 @@ void FilterCompletionResponse(Out_TextDocumentComplete* complete_response,
|
||||
items.erase(std::remove_if(items.begin(), items.end(),
|
||||
[&](const lsCompletionItem& item) {
|
||||
return item.label.find(complete_text) != 0;
|
||||
}), items.end());
|
||||
}),
|
||||
items.end());
|
||||
}
|
||||
|
||||
const size_t kMaxResultSize = 100u;
|
||||
|
@ -57,7 +57,6 @@ struct Out_WorkspaceSymbol : public lsOutMessage<Out_WorkspaceSymbol> {
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(Out_WorkspaceSymbol, jsonrpc, id, result);
|
||||
|
||||
|
||||
///// Fuzzy matching
|
||||
|
||||
// Negative but far from INT_MIN so that intermediate results are hard to
|
||||
@ -83,9 +82,12 @@ constexpr int kCamelScore = kWordStartScore + kGapScore - 1;
|
||||
enum class CharClass { Lower, Upper, Digit, NonWord };
|
||||
|
||||
static CharClass GetCharClass(int c) {
|
||||
if (islower(c)) return CharClass::Lower;
|
||||
if (isupper(c)) return CharClass::Upper;
|
||||
if (isdigit(c)) return CharClass::Digit;
|
||||
if (islower(c))
|
||||
return CharClass::Lower;
|
||||
if (isupper(c))
|
||||
return CharClass::Upper;
|
||||
if (isdigit(c))
|
||||
return CharClass::Digit;
|
||||
return CharClass::NonWord;
|
||||
}
|
||||
|
||||
@ -101,20 +103,27 @@ static int GetScoreFor(CharClass prev, CharClass curr) {
|
||||
}
|
||||
|
||||
/*
|
||||
fuzzyEvaluate implements a global sequence alignment algorithm to find the maximum accumulated score by aligning `pattern` to `str`. It applies when `pattern` is a subsequence of `str`.
|
||||
fuzzyEvaluate implements a global sequence alignment algorithm to find the
|
||||
maximum accumulated score by aligning `pattern` to `str`. It applies when
|
||||
`pattern` is a subsequence of `str`.
|
||||
|
||||
Scoring criteria
|
||||
- Prefer matches at the start of a word, or the start of subwords in CamelCase/camelCase/camel123 words. See kWordStartScore/kCamelScore
|
||||
- Prefer matches at the start of a word, or the start of subwords in
|
||||
CamelCase/camelCase/camel123 words. See kWordStartScore/kCamelScore
|
||||
- Non-word characters matter. See kNonWordScore
|
||||
- The first characters of words of `pattern` receive bonus because they usually have more significance than the rest. See kPatternStartMultiplier
|
||||
- Superfluous characters in `str` will reduce the score (gap penalty). See kGapScore
|
||||
- The first characters of words of `pattern` receive bonus because they usually
|
||||
have more significance than the rest. See kPatternStartMultiplier
|
||||
- Superfluous characters in `str` will reduce the score (gap penalty). See
|
||||
kGapScore
|
||||
- Prefer early occurrence of the first character. See kLeadingGapScore/kGapScore
|
||||
|
||||
The recurrence of the dynamic programming:
|
||||
dp[i][j]: maximum accumulated score by aligning pattern[0..i] to str[0..j]
|
||||
dp[0][j] = leading_gap_penalty(0, j) + score[j]
|
||||
dp[i][j] = max(dp[i-1][j-1] + CONSECUTIVE_SCORE, max(dp[i-1][k] + gap_penalty(k+1, j) + score[j] : k < j))
|
||||
The first dimension can be suppressed since we do not need a matching scheme, which reduces the space complexity from O(N*M) to O(M)
|
||||
dp[i][j] = max(dp[i-1][j-1] + CONSECUTIVE_SCORE, max(dp[i-1][k] +
|
||||
gap_penalty(k+1, j) + score[j] : k < j))
|
||||
The first dimension can be suppressed since we do not need a matching scheme,
|
||||
which reduces the space complexity from O(N*M) to O(M)
|
||||
*/
|
||||
int FuzzyEvaluate(const std::string& pattern,
|
||||
const std::string& str,
|
||||
@ -136,7 +145,7 @@ int FuzzyEvaluate(const std::string& pattern,
|
||||
std::fill_n(dp.begin(), str.size(), kMinScore);
|
||||
|
||||
// Align each character of pattern.
|
||||
for (unsigned char pc: pattern) {
|
||||
for (unsigned char pc : pattern) {
|
||||
if (isspace(pc)) {
|
||||
pstart = true;
|
||||
continue;
|
||||
@ -192,7 +201,8 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
|
||||
if (!inserted_results.insert(db->detailed_names[i]).second)
|
||||
continue;
|
||||
|
||||
if (InsertSymbolIntoResult(db, working_files, db->symbols[i], &unsorted_results)) {
|
||||
if (InsertSymbolIntoResult(db, working_files, db->symbols[i],
|
||||
&unsorted_results)) {
|
||||
result_indices.push_back(i);
|
||||
if (unsorted_results.size() >= config->maxWorkspaceSearchResults)
|
||||
break;
|
||||
@ -204,7 +214,7 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
|
||||
if (unsorted_results.size() < config->maxWorkspaceSearchResults) {
|
||||
std::string query_without_space;
|
||||
query_without_space.reserve(query.size());
|
||||
for (char c: query)
|
||||
for (char c : query)
|
||||
if (!isspace(c))
|
||||
query_without_space += c;
|
||||
|
||||
@ -214,7 +224,8 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
|
||||
if (!inserted_results.insert(db->detailed_names[i]).second)
|
||||
continue;
|
||||
|
||||
if (InsertSymbolIntoResult(db, working_files, db->symbols[i], &unsorted_results)) {
|
||||
if (InsertSymbolIntoResult(db, working_files, db->symbols[i],
|
||||
&unsorted_results)) {
|
||||
result_indices.push_back(i);
|
||||
if (unsorted_results.size() >= config->maxWorkspaceSearchResults)
|
||||
break;
|
||||
@ -225,16 +236,15 @@ struct WorkspaceSymbolHandler : BaseMessageHandler<Ipc_WorkspaceSymbol> {
|
||||
|
||||
// Sort results with a fuzzy matching algorithm.
|
||||
int longest = 0;
|
||||
for (int i: result_indices)
|
||||
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<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),
|
||||
FuzzyEvaluate(query, db->short_names[result_indices[i]], score, dp),
|
||||
i};
|
||||
}
|
||||
std::sort(permutation.begin(), permutation.end(),
|
||||
|
@ -781,7 +781,8 @@ void QueryDatabase::ImportOrUpdate(
|
||||
|
||||
existing.def = def.value;
|
||||
UpdateDetailedNames(&existing.detailed_name_idx, SymbolKind::Type,
|
||||
it->second.id, def.value.short_name, def.value.detailed_name);
|
||||
it->second.id, def.value.short_name,
|
||||
def.value.detailed_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -805,7 +806,8 @@ void QueryDatabase::ImportOrUpdate(
|
||||
|
||||
existing.def = def.value;
|
||||
UpdateDetailedNames(&existing.detailed_name_idx, SymbolKind::Func,
|
||||
it->second.id, def.value.short_name, def.value.detailed_name);
|
||||
it->second.id, def.value.short_name,
|
||||
def.value.detailed_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -830,7 +832,8 @@ void QueryDatabase::ImportOrUpdate(
|
||||
existing.def = def.value;
|
||||
if (!def.value.is_local())
|
||||
UpdateDetailedNames(&existing.detailed_name_idx, SymbolKind::Var,
|
||||
it->second.id, def.value.short_name, def.value.detailed_name);
|
||||
it->second.id, def.value.short_name,
|
||||
def.value.detailed_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,9 +340,9 @@ void WorkingFiles::OnChange(const lsTextDocumentDidChangeParams& change) {
|
||||
diff.rangeLength
|
||||
? start_offset + *diff.rangeLength
|
||||
: GetOffsetForPosition(diff.range->end, file->buffer_content);
|
||||
file->buffer_content.replace(
|
||||
file->buffer_content.begin() + start_offset,
|
||||
file->buffer_content.begin() + end_offset, diff.text);
|
||||
file->buffer_content.replace(file->buffer_content.begin() + start_offset,
|
||||
file->buffer_content.begin() + end_offset,
|
||||
diff.text);
|
||||
file->OnBufferContentUpdated();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user