From a392301be39a6de976eb31f6a1417797aaae5a23 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Mon, 29 Jan 2018 16:27:43 -0800 Subject: [PATCH] Format --- src/clang_complete.cc | 5 +- src/clang_cursor.cc | 32 +++--- src/clang_symbol_kind.h | 3 +- src/command_line.cc | 8 +- src/import_pipeline.cc | 4 +- src/indexer.cc | 103 +++++++++++--------- src/ipc.h | 4 +- src/language_server_api.cc | 9 +- src/lex_utils.cc | 3 +- src/message_handler.h | 2 +- src/messages/cquery_call_tree.cc | 3 +- src/messages/cquery_derived.cc | 2 +- src/messages/cquery_freshen_index.cc | 8 +- src/messages/cquery_member_hierarchy.cc | 17 +--- src/messages/initialize.cc | 29 +++--- src/messages/text_document_code_lens.cc | 10 +- src/messages/text_document_completion.cc | 10 +- src/messages/text_document_document_link.cc | 7 +- src/project.cc | 10 +- src/query.cc | 13 +-- src/query.h | 2 +- src/query_utils.cc | 56 +++++------ src/queue_manager.h | 2 +- src/serializer.cc | 36 ++++--- src/serializer.h | 24 ++--- src/timer.cc | 4 +- src/utils.cc | 9 +- src/working_files.cc | 68 +++++++------ src/working_files.h | 1 - 29 files changed, 253 insertions(+), 231 deletions(-) diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 8b152b96..a30c137b 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -310,8 +310,8 @@ void TryEnsureDocumentParsed(ClangCompleteManager* manager, args.push_back("-fspell-checking"); } - WorkingFiles::Snapshot snapshot = - session->working_files->AsSnapshot({StripFileType(session->file.filename)}); + WorkingFiles::Snapshot snapshot = session->working_files->AsSnapshot( + {StripFileType(session->file.filename)}); std::vector unsaved = snapshot.AsUnsavedFiles(); LOG_S(INFO) << "Creating completion session with arguments " @@ -408,7 +408,6 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { std::vector unsaved = snapshot.AsUnsavedFiles(); timer.ResetAndPrint("[complete] Creating WorkingFile snapshot"); - // Emit code completion data. if (request->position) { // Language server is 0-based, clang is 1-based. diff --git a/src/clang_cursor.cc b/src/clang_cursor.cc index 3d52ff95..aa5e965c 100644 --- a/src/clang_cursor.cc +++ b/src/clang_cursor.cc @@ -61,22 +61,22 @@ ClangType ClangType::strip_qualifiers() const { CXType cx = cx_type; while (1) { switch (cx.kind) { - default: - break; - case CXType_ConstantArray: - case CXType_DependentSizedArray: - case CXType_IncompleteArray: - case CXType_VariableArray: - cx = clang_getElementType(cx); - continue; - case CXType_BlockPointer: - case CXType_LValueReference: - case CXType_MemberPointer: - case CXType_ObjCObjectPointer: - case CXType_Pointer: - case CXType_RValueReference: - cx = clang_getPointeeType(cx); - continue; + default: + break; + case CXType_ConstantArray: + case CXType_DependentSizedArray: + case CXType_IncompleteArray: + case CXType_VariableArray: + cx = clang_getElementType(cx); + continue; + case CXType_BlockPointer: + case CXType_LValueReference: + case CXType_MemberPointer: + case CXType_ObjCObjectPointer: + case CXType_Pointer: + case CXType_RValueReference: + cx = clang_getPointeeType(cx); + continue; } break; } diff --git a/src/clang_symbol_kind.h b/src/clang_symbol_kind.h index 5f962ff9..eb3df27a 100644 --- a/src/clang_symbol_kind.h +++ b/src/clang_symbol_kind.h @@ -63,8 +63,7 @@ enum class StorageClass : uint8_t { Auto, Register }; -MAKE_REFLECT_TYPE_PROXY(StorageClass, - std::underlying_type::type); +MAKE_REFLECT_TYPE_PROXY(StorageClass, std::underlying_type::type); enum class SymbolRole : uint8_t { Declaration = 1 << 0, diff --git a/src/command_line.cc b/src/command_line.cc index 2c19bac3..bf5a4429 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -492,15 +492,15 @@ int main(int argc, char** argv) { if (language_server) { if (HasOption(options, "--init")) { - // We check syntax error here but override client-side initializationOptions - // in messages/initialize.cc + // We check syntax error here but override client-side + // initializationOptions in messages/initialize.cc g_init_options = options["--init"]; rapidjson::Document reader; rapidjson::ParseResult ok = reader.Parse(g_init_options.c_str()); if (!ok) { std::cerr << "Failed to parse --init as JSON: " - << rapidjson::GetParseError_En(ok.Code()) << " (" << ok.Offset() - << ")\n"; + << rapidjson::GetParseError_En(ok.Code()) << " (" + << ok.Offset() << ")\n"; return 1; } JsonReader json_reader{&reader}; diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 5e79ba44..ff1f549f 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -530,8 +530,8 @@ void IndexWithTuFromCodeCompletion( PerformanceImportFile perf; ClangIndex index; - auto indexes = ParseWithTu( - file_consumer_shared, &perf, tu, &index, path, args, file_contents); + auto indexes = ParseWithTu(file_consumer_shared, &perf, tu, &index, path, + args, file_contents); if (!indexes) return; diff --git a/src/indexer.cc b/src/indexer.cc index 45b737a4..47833949 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -523,7 +523,7 @@ void SetVarDetail(IndexVar* var, optional extent_end = fc.ToOffset(cursor.get_extent().end); if (extent_end && *spell_end < *extent_end) def.hover = def.detailed_name + - fc.content.substr(*spell_end, *extent_end - *spell_end); + fc.content.substr(*spell_end, *extent_end - *spell_end); } } @@ -838,10 +838,10 @@ void VisitDeclForTypeUsageVisitorHandler(ClangCursor cursor, // For |A a| where there is a specialization for |A|, // the |referenced_usr| below resolves to the primary template and // attributes the use to the primary template instead of the specialization. - // |toplevel_type| is retrieved |clang_getCursorType| which can be a specialization. - // If its name is the same as the primary template's, we assume the use - // should be attributed to the specialization. - // This heuristic fails when a member class bears the same name with its container. + // |toplevel_type| is retrieved |clang_getCursorType| which can be a + // specialization. If its name is the same as the primary template's, we + // assume the use should be attributed to the specialization. This heuristic + // fails when a member class bears the same name with its container. // // template // struct C { struct C {}; }; @@ -859,7 +859,9 @@ void VisitDeclForTypeUsageVisitorHandler(ClangCursor cursor, } std::string referenced_usr = - cursor.get_referenced().template_specialization_to_template_definition().get_usr(); + cursor.get_referenced() + .template_specialization_to_template_definition() + .get_usr(); // TODO: things in STL cause this to be empty. Figure out why and document it. if (referenced_usr == "") return; @@ -1188,7 +1190,8 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor, case CXCursor_DeclRefExpr: { ClangCursor ref_cursor = clang_getCursorReferenced(cursor.cx_cursor); if (ref_cursor.get_kind() == CXCursor_NonTypeTemplateParameter) { - IndexVar* ref_index = db->Resolve(db->ToVarId(ref_cursor.get_usr_hash())); + IndexVar* ref_index = + db->Resolve(db->ToVarId(ref_cursor.get_usr_hash())); if (ref_index->def.short_name.empty()) { ref_index->def.definition_spelling = ref_cursor.get_spelling_range(); ref_index->def.definition_extent = ref_cursor.get_extent(); @@ -1234,7 +1237,8 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor, case CXCursor_TemplateRef: { ClangCursor ref_cursor = clang_getCursorReferenced(cursor.cx_cursor); if (ref_cursor.get_kind() == CXCursor_TemplateTemplateParameter) { - IndexType* ref_index = db->Resolve(db->ToTypeId(ref_cursor.get_usr_hash())); + IndexType* ref_index = + db->Resolve(db->ToTypeId(ref_cursor.get_usr_hash())); // TODO It seems difficult to get references to template template // parameters. // CXCursor_TemplateTemplateParameter can be visited by visiting @@ -1253,7 +1257,8 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor, case CXCursor_TypeRef: { ClangCursor ref_cursor = clang_getCursorReferenced(cursor.cx_cursor); if (ref_cursor.get_kind() == CXCursor_TemplateTypeParameter) { - IndexType* ref_index = db->Resolve(db->ToTypeId(ref_cursor.get_usr_hash())); + IndexType* ref_index = + db->Resolve(db->ToTypeId(ref_cursor.get_usr_hash())); // TODO It seems difficult to get a FunctionTemplate's template // parameters. // CXCursor_TemplateTypeParameter can be visited by visiting @@ -1451,7 +1456,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { if (decl->isDefinition && decl->semanticContainer) { if (IsFunctionCallContext(decl->semanticContainer->cursor.kind)) { IndexFuncId parent_func_id = - db->ToFuncId(decl->semanticContainer->cursor); + db->ToFuncId(decl->semanticContainer->cursor); var->def.parent_kind = SymbolKind::Func; var->def.parent_id = size_t(parent_func_id); } else if (IsTypeDefinition(decl->semanticContainer)) { @@ -1689,7 +1694,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { ClangType enum_type = clang_getEnumDeclIntegerType(decl->cursor); if (!enum_type.is_fundamental()) { IndexType* int_type = - db->Resolve(db->ToTypeId(enum_type.get_usr_hash())); + db->Resolve(db->ToTypeId(enum_type.get_usr_hash())); int_type->uses.push_back(decl_spell); // type is invalidated. type = db->Resolve(type_id); @@ -1699,42 +1704,44 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { UniqueAdd(type->uses, decl_spell); switch (decl->entityInfo->templateKind) { - default: - break; - case CXIdxEntity_TemplateSpecialization: - case CXIdxEntity_TemplatePartialSpecialization: { - // TODO Use a different dimension - ClangCursor origin_cursor = - decl_cursor.template_specialization_to_template_definition(); - IndexTypeId origin_id = db->ToTypeId(origin_cursor.get_usr_hash()); - IndexType* origin = db->Resolve(origin_id); - // |type| may be invalidated. - type = db->Resolve(type_id); - // template class function; // not visited by OnIndexDeclaration - // template<> class function {}; // current cursor - if (origin->def.short_name.empty()) { - SetTypeName(origin, origin_cursor, nullptr, - type->def.short_name.c_str(), ns); - origin->def.kind = type->def.kind; + default: + break; + case CXIdxEntity_TemplateSpecialization: + case CXIdxEntity_TemplatePartialSpecialization: { + // TODO Use a different dimension + ClangCursor origin_cursor = + decl_cursor.template_specialization_to_template_definition(); + IndexTypeId origin_id = db->ToTypeId(origin_cursor.get_usr_hash()); + IndexType* origin = db->Resolve(origin_id); + // |type| may be invalidated. + type = db->Resolve(type_id); + // template class function; // not visited by + // OnIndexDeclaration template<> class function {}; // current + // cursor + if (origin->def.short_name.empty()) { + SetTypeName(origin, origin_cursor, nullptr, + type->def.short_name.c_str(), ns); + origin->def.kind = type->def.kind; + } + // TODO The name may be assigned in |ResolveToDeclarationType| but + // |definition_spelling| is nullopt. + if (!origin->def.definition_spelling) { + origin->def.definition_spelling = + origin_cursor.get_spelling_range(); + origin->def.definition_extent = origin_cursor.get_extent(); + } + origin->derived.push_back(type_id); + type->def.parents.push_back(origin_id); } - // TODO The name may be assigned in |ResolveToDeclarationType| but - // |definition_spelling| is nullopt. - if (!origin->def.definition_spelling) { - origin->def.definition_spelling = origin_cursor.get_spelling_range(); - origin->def.definition_extent = origin_cursor.get_extent(); + // fallthrough + case CXIdxEntity_Template: { + TemplateVisitorData data; + data.db = db; + data.container = decl_cursor; + data.param = param; + decl_cursor.VisitChildren(&TemplateVisitor, &data); + break; } - origin->derived.push_back(type_id); - type->def.parents.push_back(origin_id); - } - // fallthrough - case CXIdxEntity_Template: { - TemplateVisitorData data; - data.db = db; - data.container = decl_cursor; - data.param = param; - decl_cursor.VisitChildren(&TemplateVisitor, &data); - break; - } } // type_def->alias_of @@ -1978,7 +1985,8 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { case CXIdxEntity_CXXClass: { ClangCursor ref_cursor = ref->referencedEntity->cursor; ref_cursor = ref_cursor.template_specialization_to_template_definition(); - IndexType* ref_type = db->Resolve(db->ToTypeId(ref_cursor.get_usr_hash())); + IndexType* ref_type = + db->Resolve(db->ToTypeId(ref_cursor.get_usr_hash())); // The following will generate two TypeRefs to Foo, both located at the // same spot (line 3, column 3). One of the parents will be set to @@ -1994,8 +2002,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { // Foo f; // } // - UniqueAdd(ref_type->uses, - ClangCursor(ref->cursor).get_spelling_range()); + UniqueAdd(ref_type->uses, ClangCursor(ref->cursor).get_spelling_range()); break; } diff --git a/src/ipc.h b/src/ipc.h index 400e1b4b..91e20957 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -90,9 +90,7 @@ struct RequestMessage : public BaseIpcMessage { lsRequestId id; RequestMessage() : BaseIpcMessage(T::kIpcId) {} - lsRequestId GetRequestId() override { - return id; - } + lsRequestId GetRequestId() override { return id; } }; // NotificationMessage does not have |id|. diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 44179bc6..b4d07a40 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -109,9 +109,9 @@ TEST_SUITE("FindIncludeLine") { optional ReadCharFromStdinBlocking() { // We do not use std::cin because it does not read bytes once stuck in - // cin.bad(). We can call cin.clear() but C++ iostream has other annoyance like - // std::{cin,cout} is tied by default, which causes undesired cout flush for - // cin operations. + // cin.bad(). We can call cin.clear() but C++ iostream has other annoyance + // like std::{cin,cout} is tied by default, which causes undesired cout flush + // for cin operations. int c = getchar(); if (c >= 0) return c; @@ -168,7 +168,8 @@ optional MessageRegistry::Parse( // *message is partially deserialized but some field (e.g. |id|) are likely // available. return std::string("Fail to parse '") + method + "' " + - static_cast(visitor).GetPath() + ", expected " + e.what(); + static_cast(visitor).GetPath() + ", expected " + + e.what(); } } diff --git a/src/lex_utils.cc b/src/lex_utils.cc index 29e6292a..0f5bd63d 100644 --- a/src/lex_utils.cc +++ b/src/lex_utils.cc @@ -16,7 +16,8 @@ int GetOffsetForPosition(lsPosition position, const std::string& content) { for (; position.character > 0 && i < content.size(); position.character--) if (uint8_t(content[i++]) >= 128) { // Skip 0b10xxxxxx - while (i < content.size() && uint8_t(content[i]) >= 128 && uint8_t(content[i]) < 192) + while (i < content.size() && uint8_t(content[i]) >= 128 && + uint8_t(content[i]) < 192) i++; } return int(i); diff --git a/src/message_handler.h b/src/message_handler.h index 493389b2..7278420c 100644 --- a/src/message_handler.h +++ b/src/message_handler.h @@ -25,7 +25,7 @@ struct WorkingFile; struct WorkingFiles; struct Out_CqueryPublishSemanticHighlighting - : public lsOutMessage { + : public lsOutMessage { struct Symbol { int stableId = 0; SymbolKind parentKind; diff --git a/src/messages/cquery_call_tree.cc b/src/messages/cquery_call_tree.cc index 8f0bdb9a..06b245c2 100644 --- a/src/messages/cquery_call_tree.cc +++ b/src/messages/cquery_call_tree.cc @@ -14,7 +14,8 @@ struct Ipc_CqueryCallTreeInitial MAKE_REFLECT_STRUCT(Ipc_CqueryCallTreeInitial, id, params); REGISTER_IPC_MESSAGE(Ipc_CqueryCallTreeInitial); -struct Ipc_CqueryCallTreeExpand : public RequestMessage { +struct Ipc_CqueryCallTreeExpand + : public RequestMessage { const static IpcId kIpcId = IpcId::CqueryCallTreeExpand; struct Params { std::string usr; diff --git a/src/messages/cquery_derived.cc b/src/messages/cquery_derived.cc index 05557934..5019ab15 100644 --- a/src/messages/cquery_derived.cc +++ b/src/messages/cquery_derived.cc @@ -24,7 +24,7 @@ struct CqueryDerivedHandler : BaseMessageHandler { Out_LocationList out; out.id = request->id; std::vector refs = - FindSymbolsAtLocation(working_file, file, request->params.position); + FindSymbolsAtLocation(working_file, file, request->params.position); // A template definition may be a use of its primary template. // We want to get the definition instead of the use. // Order by |Definition| DESC, range size ASC. diff --git a/src/messages/cquery_freshen_index.cc b/src/messages/cquery_freshen_index.cc index a75334a4..4469fa4f 100644 --- a/src/messages/cquery_freshen_index.cc +++ b/src/messages/cquery_freshen_index.cc @@ -12,7 +12,8 @@ #include namespace { -struct Ipc_CqueryFreshenIndex : public NotificationMessage { +struct Ipc_CqueryFreshenIndex + : public NotificationMessage { const static IpcId kIpcId = IpcId::CqueryFreshenIndex; struct Params { bool dependencies = true; @@ -21,7 +22,10 @@ struct Ipc_CqueryFreshenIndex : public NotificationMessage result; }; -MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy::Entry, - name, - type_id, - location); +MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy::Entry, name, type_id, location); MAKE_REFLECT_STRUCT(Out_CqueryMemberHierarchy, jsonrpc, id, result); -std::vector BuildInitial( - QueryDatabase* db, - WorkingFiles* working_files, - QueryTypeId root) { +std::vector +BuildInitial(QueryDatabase* db, WorkingFiles* working_files, QueryTypeId root) { QueryType& root_type = db->types[root.id]; if (!root_type.def || !root_type.def->definition_spelling) return {}; @@ -59,9 +54,7 @@ std::vector BuildInitial( } std::vector -ExpandNode(QueryDatabase* db, - WorkingFiles* working_files, - QueryTypeId root) { +ExpandNode(QueryDatabase* db, WorkingFiles* working_files, QueryTypeId root) { QueryType& root_type = db->types[root.id]; if (!root_type.def) return {}; @@ -99,7 +92,7 @@ struct CqueryMemberHierarchyInitialHandler out.id = request->id; for (const SymbolRef& ref : - FindSymbolsAtLocation(working_file, file, request->params.position)) { + FindSymbolsAtLocation(working_file, file, request->params.position)) { if (ref.idx.kind == SymbolKind::Type) { out.result = BuildInitial(db, working_files, QueryTypeId(ref.idx.idx)); break; diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 80984e18..1be67519 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -421,7 +421,7 @@ void Reflect(Reader& reader, lsInitializeParams::lsTrace& value) { value = lsInitializeParams::lsTrace::Verbose; } -#if 0 // unused +#if 0 // unused void Reflect(Writer& writer, lsInitializeParams::lsTrace& value) { switch (value) { case lsInitializeParams::lsTrace::Off: @@ -610,20 +610,19 @@ struct InitializeHandler : BaseMessageHandler { auto* queue = QueueManager::instance(); time.Reset(); - project->ForAllFilteredFiles( - config, [&](int i, const Project::Entry& entry) { - optional content = ReadContent(entry.filename); - if (!content) { - LOG_S(ERROR) << "When loading project, canont read file " - << entry.filename; - return; - } - bool is_interactive = - working_files->GetFileByFilename(entry.filename) != nullptr; - queue->index_request.Enqueue( - Index_Request(entry.filename, entry.args, is_interactive, - *content, request->id)); - }); + project->ForAllFilteredFiles(config, [&](int i, + const Project::Entry& entry) { + optional content = ReadContent(entry.filename); + if (!content) { + LOG_S(ERROR) << "When loading project, canont read file " + << entry.filename; + return; + } + bool is_interactive = + working_files->GetFileByFilename(entry.filename) != nullptr; + queue->index_request.Enqueue(Index_Request( + entry.filename, entry.args, is_interactive, *content, request->id)); + }); // We need to support multiple concurrent index processes. time.ResetAndPrint("[perf] Dispatched initial index requests"); diff --git a/src/messages/text_document_code_lens.cc b/src/messages/text_document_code_lens.cc index c8f9617e..106ff5ec 100644 --- a/src/messages/text_document_code_lens.cc +++ b/src/messages/text_document_code_lens.cc @@ -173,11 +173,13 @@ struct TextDocumentCodeLensHandler int16_t offset = 0; - // For functions, the outline will report a location that is using the extent since that is better for outline. This tries to convert the extent location to the spelling location. + // For functions, the outline will report a location that is using the + // extent since that is better for outline. This tries to convert the + // extent location to the spelling location. auto try_ensure_spelling = [&](SymbolRef sym) { - optional def = GetDefinitionSpellingOfSymbol(db, sym.idx); - if (!def || - def->path != sym.loc.path || + optional def = + GetDefinitionSpellingOfSymbol(db, sym.idx); + if (!def || def->path != sym.loc.path || def->range.start.line != sym.loc.range.start.line) { return sym.loc; } diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index a91e1d58..681d4b54 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -316,9 +316,8 @@ struct TextDocumentCompletionHandler : MessageHandler { // results Only do this when trigger is not manual or context doesn't // exist (for Atom support). if (existing_completion.empty() && is_global_completion && - (request->params.context && - request->params.context->triggerKind != - lsCompletionTriggerKind::Invoked)) { + (request->params.context && request->params.context->triggerKind != + lsCompletionTriggerKind::Invoked)) { LOG_S(INFO) << "Existing completion is empty, no completion results " "will be returned"; Out_TextDocumentComplete out; @@ -336,9 +335,8 @@ struct TextDocumentCompletionHandler : MessageHandler { out.result.items = results; // Emit completion results. - FilterAndSortCompletionResponse( - &out, existing_completion, - config->completion.filterAndSort); + FilterAndSortCompletionResponse(&out, existing_completion, + config->completion.filterAndSort); QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out); // Cache completion results. diff --git a/src/messages/text_document_document_link.cc b/src/messages/text_document_document_link.cc index 2d6d2e55..b68bfbcc 100644 --- a/src/messages/text_document_document_link.cc +++ b/src/messages/text_document_document_link.cc @@ -15,8 +15,7 @@ struct Ipc_TextDocumentDocumentLink }; Params params; }; -MAKE_REFLECT_STRUCT(Ipc_TextDocumentDocumentLink::Params, - textDocument); +MAKE_REFLECT_STRUCT(Ipc_TextDocumentDocumentLink::Params, textDocument); MAKE_REFLECT_STRUCT(Ipc_TextDocumentDocumentLink, id, params); REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentLink); @@ -58,8 +57,8 @@ struct TextDocumentDocumentLinkHandler return; } for (const IndexInclude& include : file->def->includes) { - optional buffer_line = - working_file->GetBufferPosFromIndexPos(include.line, nullptr, false); + optional buffer_line = working_file->GetBufferPosFromIndexPos( + include.line, nullptr, false); if (!buffer_line) continue; diff --git a/src/project.cc b/src/project.cc index b0af2178..4809364e 100644 --- a/src/project.cc +++ b/src/project.cc @@ -571,8 +571,8 @@ TEST_SUITE("Project") { /* raw */ {"clang.exe"}, /* expected */ {"clang.exe", "-working-directory", "/dir/", "-xc++", "-std=c++14", - "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option", - "-fparse-all-comments"}); + "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option", + "-fparse-all-comments"}); CheckFlags( /* raw */ {"goma", "clang"}, @@ -974,8 +974,7 @@ TEST_SUITE("Project") { "lock_screen_sanity_unittest.cc", "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option", - "-fparse-all-comments" - }); + "-fparse-all-comments"}); } // Checks flag parsing for an example chromium file. @@ -1300,8 +1299,7 @@ TEST_SUITE("Project") { "&/w/c/s/out/Release/../../apps/app_lifetime_monitor.cc", "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option", - "-fparse-all-comments" - }); + "-fparse-all-comments"}); } TEST_CASE("Directory extraction") { diff --git a/src/query.cc b/src/query.cc index 467f7782..b20a3adf 100644 --- a/src/query.cc +++ b/src/query.cc @@ -243,7 +243,8 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) { if (func.def.definition_extent.has_value()) add_outline(id_map.ToSymbol(func.id), func.def.definition_extent.value()); for (const IndexFunc::Declaration& decl : func.declarations) { - add_all_symbols(id_map.ToSymbol(func.id), SymbolRole::Declaration, decl.spelling); + add_all_symbols(id_map.ToSymbol(func.id), SymbolRole::Declaration, + decl.spelling); add_outline(id_map.ToSymbol(func.id), decl.spelling); } for (const IndexFuncRef& caller : func.callers) { @@ -321,8 +322,8 @@ inline optional GetQueryTypeIdFromUsr(QueryDatabase* query_db, } inline optional GetQueryFuncIdFromUsr(QueryDatabase* query_db, - Usr usr, - bool create_if_missing) { + Usr usr, + bool create_if_missing) { auto it = query_db->usr_to_func.find(usr); if (it != query_db->usr_to_func.end()) return QueryFuncId(it->second.id); @@ -336,8 +337,8 @@ inline optional GetQueryFuncIdFromUsr(QueryDatabase* query_db, } inline optional GetQueryVarIdFromUsr(QueryDatabase* query_db, - Usr usr, - bool create_if_missing) { + Usr usr, + bool create_if_missing) { auto it = query_db->usr_to_var.find(usr); if (it != query_db->usr_to_var.end()) return QueryVarId(it->second.id); @@ -809,7 +810,7 @@ void QueryDatabase::ApplyIndexUpdate(IndexUpdate* update) { } for (const std::string& filename : update->files_removed) - files[usr_to_file[filename].id].def = nullopt; + files[usr_to_file[filename].id].def = nullopt; ImportOrUpdate(update->files_def_update); RemoveUsrs(SymbolKind::Type, update->types_removed); diff --git a/src/query.h b/src/query.h index cd1ec1f7..6c29892a 100644 --- a/src/query.h +++ b/src/query.h @@ -119,7 +119,7 @@ struct QueryFuncRef { bool operator!=(const QueryFuncRef& that) const { return !(*this == that); } bool operator<(const QueryFuncRef& that) const { if (id_ != that.id_) - return id_ < that.id_; + return id_ < that.id_; if (loc != that.loc) return loc < that.loc; return is_implicit < that.is_implicit; diff --git a/src/query_utils.cc b/src/query_utils.cc index 883919ca..44eabaad 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -209,8 +209,7 @@ std::vector GetUsesOfSymbol(QueryDatabase* db, if (include_decl) { if (var.def && var.def->definition_spelling) ret.push_back(*var.def->definition_spelling); - ret.insert(ret.end(), var.declarations.begin(), - var.declarations.end()); + ret.insert(ret.end(), var.declarations.begin(), var.declarations.end()); } return ret; } @@ -326,7 +325,8 @@ optional GetLsPosition(WorkingFile* working_file, return lsPosition(position.line, position.column); int column = position.column; - optional start = working_file->GetBufferPosFromIndexPos(position.line, &column, false); + optional start = + working_file->GetBufferPosFromIndexPos(position.line, &column, false); if (!start) return nullopt; @@ -335,16 +335,15 @@ optional GetLsPosition(WorkingFile* working_file, optional GetLsRange(WorkingFile* working_file, const Range& location) { if (!working_file) { - return lsRange( - lsPosition(location.start.line, location.start.column), - lsPosition(location.end.line, location.end.column)); + return lsRange(lsPosition(location.start.line, location.start.column), + lsPosition(location.end.line, location.end.column)); } int start_column = location.start.column, end_column = location.end.column; - optional start = - working_file->GetBufferPosFromIndexPos(location.start.line, &start_column, false); - optional end = - working_file->GetBufferPosFromIndexPos(location.end.line, &end_column, true); + optional start = working_file->GetBufferPosFromIndexPos( + location.start.line, &start_column, false); + optional end = working_file->GetBufferPosFromIndexPos(location.end.line, + &end_column, true); if (!start || !end) return nullopt; @@ -444,12 +443,12 @@ optional GetSymbolInfo(QueryDatabase* db, info.containerName = type.def->detailed_name; // TODO ClangSymbolKind -> lsSymbolKind switch (type.def->kind) { - default: - info.kind = lsSymbolKind::Class; - break; - case ClangSymbolKind::Namespace: - info.kind = lsSymbolKind::Namespace; - break; + default: + info.kind = lsSymbolKind::Class; + break; + case ClangSymbolKind::Namespace: + info.kind = lsSymbolKind::Namespace; + break; } return info; } @@ -523,19 +522,20 @@ std::vector FindSymbolsAtLocation(WorkingFile* working_file, // // Then order functions before other types, which makes goto definition work // better on constructors. - std::sort(symbols.begin(), symbols.end(), [](const SymbolRef& a, - const SymbolRef& b) { - int a_size = ComputeRangeSize(a.loc.range); - int b_size = ComputeRangeSize(b.loc.range); + std::sort(symbols.begin(), symbols.end(), + [](const SymbolRef& a, const SymbolRef& b) { + int a_size = ComputeRangeSize(a.loc.range); + int b_size = ComputeRangeSize(b.loc.range); - if (a_size != b_size) - return a_size < b_size; - // operator> orders Var/Func before Type. - int t = static_cast(a.idx.kind) - static_cast(b.idx.kind); - if (t) - return t > 0; - return a.idx.idx < b.idx.idx; - }); + if (a_size != b_size) + return a_size < b_size; + // operator> orders Var/Func before Type. + int t = + static_cast(a.idx.kind) - static_cast(b.idx.kind); + if (t) + return t > 0; + return a.idx.idx < b.idx.idx; + }); return symbols; } diff --git a/src/queue_manager.h b/src/queue_manager.h index a387ed94..0eaeffeb 100644 --- a/src/queue_manager.h +++ b/src/queue_manager.h @@ -26,7 +26,7 @@ struct Index_Request { const std::vector& args, bool is_interactive, const std::string& contents, - lsRequestId id={}); + lsRequestId id = {}); }; struct Index_DoIdMap { diff --git a/src/serializer.cc b/src/serializer.cc index f66625ee..7841bb7d 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -17,7 +17,8 @@ bool gTestOutputMode = false; //// Elementary types void Reflect(Reader& visitor, uint8_t& value) { - if (!visitor.IsInt()) throw std::invalid_argument("uint8_t"); + if (!visitor.IsInt()) + throw std::invalid_argument("uint8_t"); value = (uint8_t)visitor.GetInt(); } void Reflect(Writer& visitor, uint8_t& value) { @@ -25,7 +26,8 @@ void Reflect(Writer& visitor, uint8_t& value) { } void Reflect(Reader& visitor, int16_t& value) { - if (!visitor.IsInt()) throw std::invalid_argument("int16_t"); + if (!visitor.IsInt()) + throw std::invalid_argument("int16_t"); value = (int16_t)visitor.GetInt(); } void Reflect(Writer& visitor, int16_t& value) { @@ -33,7 +35,8 @@ void Reflect(Writer& visitor, int16_t& value) { } void Reflect(Reader& visitor, int& value) { - if (!visitor.IsInt()) throw std::invalid_argument("int"); + if (!visitor.IsInt()) + throw std::invalid_argument("int"); value = visitor.GetInt(); } void Reflect(Writer& visitor, int& value) { @@ -41,7 +44,8 @@ void Reflect(Writer& visitor, int& value) { } void Reflect(Reader& visitor, unsigned& value) { - if (!visitor.IsInt()) throw std::invalid_argument("unsigned"); + if (!visitor.IsInt()) + throw std::invalid_argument("unsigned"); value = visitor.GetUint32(); } void Reflect(Writer& visitor, unsigned& value) { @@ -49,7 +53,8 @@ void Reflect(Writer& visitor, unsigned& value) { } void Reflect(Reader& visitor, long& value) { - if (!visitor.IsInt64()) throw std::invalid_argument("long"); + if (!visitor.IsInt64()) + throw std::invalid_argument("long"); value = long(visitor.GetInt64()); } void Reflect(Writer& visitor, long& value) { @@ -57,7 +62,8 @@ void Reflect(Writer& visitor, long& value) { } void Reflect(Reader& visitor, unsigned long& value) { - if (!visitor.IsUint64()) throw std::invalid_argument("unsigned long"); + if (!visitor.IsUint64()) + throw std::invalid_argument("unsigned long"); value = (unsigned long)visitor.GetUint64(); } void Reflect(Writer& visitor, unsigned long& value) { @@ -65,7 +71,8 @@ void Reflect(Writer& visitor, unsigned long& value) { } void Reflect(Reader& visitor, long long& value) { - if (!visitor.IsInt64()) throw std::invalid_argument("long long"); + if (!visitor.IsInt64()) + throw std::invalid_argument("long long"); value = visitor.GetInt64(); } void Reflect(Writer& visitor, long long& value) { @@ -73,7 +80,8 @@ void Reflect(Writer& visitor, long long& value) { } void Reflect(Reader& visitor, unsigned long long& value) { - if (!visitor.IsUint64()) throw std::invalid_argument("unsigned long long"); + if (!visitor.IsUint64()) + throw std::invalid_argument("unsigned long long"); value = visitor.GetUint64(); } void Reflect(Writer& visitor, unsigned long long& value) { @@ -81,7 +89,8 @@ void Reflect(Writer& visitor, unsigned long long& value) { } void Reflect(Reader& visitor, double& value) { - if (!visitor.IsDouble()) throw std::invalid_argument("double"); + if (!visitor.IsDouble()) + throw std::invalid_argument("double"); value = visitor.GetDouble(); } void Reflect(Writer& visitor, double& value) { @@ -89,7 +98,8 @@ void Reflect(Writer& visitor, double& value) { } void Reflect(Reader& visitor, bool& value) { - if (!visitor.IsBool()) throw std::invalid_argument("bool"); + if (!visitor.IsBool()) + throw std::invalid_argument("bool"); value = visitor.GetBool(); } void Reflect(Writer& visitor, bool& value) { @@ -98,7 +108,8 @@ void Reflect(Writer& visitor, bool& value) { // std::string void Reflect(Reader& visitor, std::string& value) { - if (!visitor.IsString()) throw std::invalid_argument("std::string"); + if (!visitor.IsString()) + throw std::invalid_argument("std::string"); value = visitor.GetString(); } void Reflect(Writer& visitor, std::string& value) { @@ -314,8 +325,7 @@ std::unique_ptr Deserialize(SerializeFormat format, Reflect(json_reader, *file); } catch (std::invalid_argument& e) { LOG_S(INFO) << "'" << path << "': failed to deserialize " - << json_reader.GetPath() << "." - << e.what(); + << json_reader.GetPath() << "." << e.what(); return nullptr; } break; diff --git a/src/serializer.h b/src/serializer.h index 75650dc4..d81e4f18 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -79,15 +79,15 @@ struct IndexFile; #define REFLECT_MEMBER2(name, value) ReflectMember(visitor, name, value) // TODO Make it inline because this macro can be used in header files. -#define MAKE_REFLECT_TYPE_PROXY(type, as_type) \ - ATTRIBUTE_UNUSED inline void Reflect(Reader& visitor, type& value) { \ - as_type value0; \ - ::Reflect(visitor, value0); \ - value = static_cast(value0); \ - } \ - ATTRIBUTE_UNUSED inline void Reflect(Writer& visitor, type& value) { \ - auto value0 = static_cast(value); \ - ::Reflect(visitor, value0); \ +#define MAKE_REFLECT_TYPE_PROXY(type, as_type) \ + ATTRIBUTE_UNUSED inline void Reflect(Reader& visitor, type& value) { \ + as_type value0; \ + ::Reflect(visitor, value0); \ + value = static_cast(value0); \ + } \ + ATTRIBUTE_UNUSED inline void Reflect(Writer& visitor, type& value) { \ + auto value0 = static_cast(value); \ + ::Reflect(visitor, value0); \ } #define _MAPPABLE_REFLECT_MEMBER(name) REFLECT_MEMBER(name); @@ -229,7 +229,7 @@ struct disjunction : std::conditional>::type {}; template struct disjunction : B0 {}; -} +} // namespace // Helper struct to reflect std::variant template @@ -255,8 +255,8 @@ struct ReflectVariant { // Based on tag dispatch, call different ReflectTag helper. if (visitor.IsNull()) ReflectTag(visitor, value); - // It is possible that IsInt64() && IsInt(). We don't call ReflectTag if - // int is not in Ts... + // It is possible that IsInt64() && IsInt(). We don't call ReflectTag + // if int is not in Ts... else if (disjunction...>::value && visitor.IsInt()) ReflectTag(visitor, value); else if (visitor.IsInt64()) diff --git a/src/timer.cc b/src/timer.cc index d0dfd9d0..c8d3a277 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -56,9 +56,9 @@ void Timer::Resume() { start_ = Clock::now(); } -ScopedPerfTimer::ScopedPerfTimer(const std::string& message) : message_(message) {} +ScopedPerfTimer::ScopedPerfTimer(const std::string& message) + : message_(message) {} ScopedPerfTimer::~ScopedPerfTimer() { timer_.ResetAndPrint(message_); } - diff --git a/src/utils.cc b/src/utils.cc index 7ed618f1..430c2bcc 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -3,9 +3,9 @@ #include "platform.h" #include +#include #include #include -#include #include #include @@ -110,9 +110,10 @@ bool EndsWithAny(const std::string& value, bool FindAnyPartial(const std::string& value, const std::vector& values) { - return std::any_of( - std::begin(values), std::end(values), - [&value](const std::string& v) { return value.find(v) != std::string::npos; }); + return std::any_of(std::begin(values), std::end(values), + [&value](const std::string& v) { + return value.find(v) != std::string::npos; + }); } std::string GetBaseName(const std::string& path) { diff --git a/src/working_files.cc b/src/working_files.cc index c21df53a..c3d634ad 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -45,28 +45,32 @@ lsPosition GetPositionForOffset(const std::string& content, int offset) { int MyersDiff(const char* a, int la, const char* b, int lb, int threshold) { assert(threshold <= kMaxDiff); static int v_static[kMaxDiff + 2]; - const char *ea = a + la, *eb = b + lb; - // Strip prefix - for (; a < ea && b < eb && *a == *b; a++, b++) {} - // Strip suffix - for (; a < ea && b < eb && ea[-1] == eb[-1]; ea--, eb--) {} - la = int(ea - a); - lb = int(eb - b); + const char *ea = a + la, *eb = b + lb; + // Strip prefix + for (; a < ea && b < eb && *a == *b; a++, b++) { + } + // Strip suffix + for (; a < ea && b < eb && ea[-1] == eb[-1]; ea--, eb--) { + } + la = int(ea - a); + lb = int(eb - b); - int* v = v_static + lb; - v[1] = 0; - for (int di = 0; di <= threshold; di++) { - int low = -di + 2 * std::max(0, di - lb), high = di - 2 * std::max(0, di - la); - for (int i = low; i <= high; i += 2) { - int x = i == -di || (i != di && v[i-1] < v[i+1]) ? v[i+1] : v[i-1] + 1, + int* v = v_static + lb; + v[1] = 0; + for (int di = 0; di <= threshold; di++) { + int low = -di + 2 * std::max(0, di - lb), + high = di - 2 * std::max(0, di - la); + for (int i = low; i <= high; i += 2) { + int x = i == -di || (i != di && v[i - 1] < v[i + 1]) ? v[i + 1] + : v[i - 1] + 1, y = x - i; - while (x < la && y < lb && a[x] == b[y]) - x++, y++; - v[i] = x; - if (x == la && y == lb) + while (x < la && y < lb && a[x] == b[y]) + x++, y++; + v[i] = x; + if (x == la && y == lb) return di; - } - } + } + } return threshold + 1; } @@ -156,8 +160,10 @@ optional FindMatchingLine(const std::vector& index_lines, // Find the nearest two confident lines above and below. int up = line, down = line; - while (--up >= 0 && index_to_buffer[up] < 0) {} - while (++down < int(index_to_buffer.size()) && index_to_buffer[down] < 0) {} + while (--up >= 0 && index_to_buffer[up] < 0) { + } + while (++down < int(index_to_buffer.size()) && index_to_buffer[down] < 0) { + } up = up < 0 ? 0 : index_to_buffer[up]; down = down >= int(index_to_buffer.size()) ? int(buffer_lines.size()) - 1 : index_to_buffer[down]; @@ -231,7 +237,8 @@ void WorkingFile::ComputeLineMapping() { std::vector buffer_hashes(buffer_lines.size()); index_to_buffer.resize(index_lines.size()); buffer_to_index.resize(buffer_lines.size()); - hash_to_unique.reserve(std::max(index_to_buffer.size(), buffer_to_index.size())); + hash_to_unique.reserve( + std::max(index_to_buffer.size(), buffer_to_index.size())); // For index line i, set index_to_buffer[i] to -1 if line i is duplicated. int i = 0; @@ -268,8 +275,8 @@ void WorkingFile::ComputeLineMapping() { buffer_hashes[i++] = h; } - // If index line i is the identical to buffer line j, and they are both unique, - // align them by pointing from_index[i] to j. + // If index line i is the identical to buffer line j, and they are both + // unique, align them by pointing from_index[i] to j. i = 0; for (auto h : index_hashes) { if (index_to_buffer[i] >= 0) { @@ -290,7 +297,7 @@ void WorkingFile::ComputeLineMapping() { index_hashes[i + 1] == buffer_hashes[j + 1]) index_to_buffer[i + 1] = j + 1; } - for (i = (int)index_hashes.size(); --i > 0; ) { + for (i = (int)index_hashes.size(); --i > 0;) { int j = index_to_buffer[i]; if (0 < j && index_hashes[i - 1] == buffer_hashes[j - 1]) index_to_buffer[i - 1] = j - 1; @@ -303,7 +310,9 @@ void WorkingFile::ComputeLineMapping() { buffer_to_index[index_to_buffer[i]] = i; } -optional WorkingFile::GetBufferPosFromIndexPos(int line, int* column, bool is_end) { +optional WorkingFile::GetBufferPosFromIndexPos(int line, + int* column, + bool is_end) { // The implementation is simple but works pretty well for most cases. We // lookup the line contents in the indexed file contents, and try to find the // most similar line in the current buffer file. @@ -330,7 +339,9 @@ optional WorkingFile::GetBufferPosFromIndexPos(int line, int* column, bool buffer_lines, is_end); } -optional WorkingFile::GetIndexPosFromBufferPos(int line, int* column, bool is_end) { +optional WorkingFile::GetIndexPosFromBufferPos(int line, + int* column, + bool is_end) { // See GetBufferLineFromIndexLine for additional comments. if (line < 0 || line >= (int)buffer_lines.size()) return nullopt; @@ -494,7 +505,8 @@ void WorkingFiles::OnChange(const lsTextDocumentDidChangeParams& change) { GetOffsetForPosition(diff.range->start, file->buffer_content); // Ignore TextDocumentContentChangeEvent.rangeLength which causes trouble // when UTF-16 surrogate pairs are used. - int end_offset = GetOffsetForPosition(diff.range->end, file->buffer_content); + int end_offset = + 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); diff --git a/src/working_files.h b/src/working_files.h index b1554e3f..84855b9f 100644 --- a/src/working_files.h +++ b/src/working_files.h @@ -87,7 +87,6 @@ struct WorkingFiles { std::vector files; }; - // // :: IMPORTANT :: All methods in this class are guarded by a single lock. //