diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 5bcbf1c1..5c71e051 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -125,13 +125,13 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) { case CXCursor_ObjCClassRef: return lsCompletionItemKind::Reference; - // return lsCompletionItemKind::Property; - // return lsCompletionItemKind::Unit; - // return lsCompletionItemKind::Value; - // return lsCompletionItemKind::Keyword; - // return lsCompletionItemKind::Snippet; - // return lsCompletionItemKind::Color; - // return lsCompletionItemKind::File; + // return lsCompletionItemKind::Property; + // return lsCompletionItemKind::Unit; + // return lsCompletionItemKind::Value; + // return lsCompletionItemKind::Keyword; + // return lsCompletionItemKind::Snippet; + // return lsCompletionItemKind::Color; + // return lsCompletionItemKind::File; case CXCursor_NotImplemented: return lsCompletionItemKind::Text; @@ -389,7 +389,8 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { if (!session->tu) continue; - WorkingFilesSnapshot snapshot = completion_manager->working_files_->AsSnapshot(); + WorkingFilesSnapshot snapshot = + completion_manager->working_files_->AsSnapshot(); std::vector unsaved = snapshot.AsUnsavedFiles(); // Emit code completion data. @@ -450,9 +451,9 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { ls_completion_item.documentation = ToString( clang_getCompletionBriefComment(result.CompletionString)); - ls_completion_item.priority_ = - GetCompletionPriority(result.CompletionString, result.CursorKind, - ls_completion_item.label); + ls_completion_item.priority_ = GetCompletionPriority( + result.CompletionString, result.CursorKind, + ls_completion_item.label); ls_result.push_back(ls_completion_item); } diff --git a/src/clang_translation_unit.cc b/src/clang_translation_unit.cc index b9745eba..eaa41577 100644 --- a/src/clang_translation_unit.cc +++ b/src/clang_translation_unit.cc @@ -19,8 +19,8 @@ void EmitDiagnostics(std::string path, CXTranslationUnit tu) { std::string output = "Fatal errors while trying to parse " + path + "\n"; output += - "Args: " + StringJoinMap( - args, [](const char* arg) { return std::string(arg); }) + + "Args: " + + StringJoinMap(args, [](const char* arg) { return std::string(arg); }) + "\n"; size_t num_diagnostics = clang_getNumDiagnostics(tu); diff --git a/src/clang_utils.h b/src/clang_utils.h index 9932d2eb..0b1e792e 100644 --- a/src/clang_utils.h +++ b/src/clang_utils.h @@ -25,6 +25,6 @@ std::string ToString(CXCursorKind cursor_kind); // Converts Clang formatting replacement operations into LSP text edits. #if USE_CLANG_CXX std::vector ConvertClangReplacementsIntoTextEdits( - llvm::StringRef document, - const std::vector& clang_replacements); + llvm::StringRef document, + const std::vector& clang_replacements); #endif diff --git a/src/command_line.cc b/src/command_line.cc index a53aca57..70a7e1ec 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -30,8 +30,8 @@ #include "working_files.h" #include -#include #include +#include #include #include diff --git a/src/config.h b/src/config.h index 84c0f61c..6fb0198f 100644 --- a/src/config.h +++ b/src/config.h @@ -138,8 +138,7 @@ MAKE_REFLECT_STRUCT(Config, enableComments, - dumpAST - ); + dumpAST); // Expected client version. We show an error if this doesn't match. constexpr const int kExpectedClientVersion = 3; diff --git a/src/indexer.cc b/src/indexer.cc index 32332e1d..480ad5b1 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -106,7 +106,6 @@ ClangSymbolKind GetSymbolKind(CXIdxEntityKind kind) { } } - // Caches all instances of constructors, regardless if they are indexed or not. // The constructor may have a make_unique call associated with it that we need // to export. If we do not capture the parameter type description for the @@ -339,7 +338,8 @@ std::string GetDocumentContentInRange(CXTranslationUnit cx_tu, for (unsigned i = 0; i < num_tokens; ++i) { // Add whitespace between the previous token and this one. - Range token_range = ResolveCXSourceRange(clang_getTokenExtent(cx_tu, tokens[i])); + Range token_range = + ResolveCXSourceRange(clang_getTokenExtent(cx_tu, tokens[i])); if (previous_token_range) { // Insert newlines. int16_t line_delta = @@ -419,9 +419,9 @@ void SetVarDetail(IndexVar* var, def.comments = cursor.get_comments(); std::string qualified_name = - semanticContainer - ? param->ns.QualifiedName(semanticContainer, def.short_name) - : def.short_name; + semanticContainer + ? param->ns.QualifiedName(semanticContainer, def.short_name) + : def.short_name; if (semanticContainer && semanticContainer->cursor.kind == CXCursor_EnumDecl) def.detailed_name = std::move(qualified_name); else { @@ -463,8 +463,7 @@ void OnIndexReference_Function(IndexFile* db, AddFuncRef(&caller->def.callees, IndexFuncRef(called->id, loc, is_implicit)); - AddFuncRef(&called->callers, - IndexFuncRef(caller->id, loc, is_implicit)); + AddFuncRef(&called->callers, IndexFuncRef(caller->id, loc, is_implicit)); } else { AddFuncRef(&called->callers, IndexFuncRef(loc, is_implicit)); } @@ -594,8 +593,8 @@ void OnIndexDiagnostic(CXClientData client_data, unsigned int line, column; clang_getSpellingLocation(diag_loc, &file, &line, &column, nullptr); // Skip empty diagnostic. - if(!line && !column) - continue; + if (!line && !column) + continue; IndexFile* db = ConsumeFile(param, file); if (!db) continue; @@ -1036,7 +1035,8 @@ ClangCursor::VisitResult VisitMacroDefinitionAndExpansions(ClangCursor cursor, var_def->def.kind = ClangSymbolKind::Macro; var_def->def.comments = cursor.get_comments(); var_def->def.definition_spelling = decl_loc_spelling; - var_def->def.definition_extent = ResolveCXSourceRange(cx_extent, nullptr); + var_def->def.definition_extent = + ResolveCXSourceRange(cx_extent, nullptr); } break; @@ -1312,9 +1312,9 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { // We don't need to assign declaring type multiple times if this variable // has already been seen. if (!decl->isRedeclaration) { - //optional var_type = + // optional var_type = // ResolveToDeclarationType(db, decl_cursor); - //if (var_type.has_value()) { + // if (var_type.has_value()) { // // Don't treat enum definition variables as instantiations. // bool is_enum_member = // decl->semanticContainer && @@ -1597,7 +1597,8 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { decl->lexicalContainer); optional parent_type_id = ResolveToDeclarationType(db, base_class->cursor); - // type_def ptr could be invalidated by ResolveToDeclarationType and TemplateVisitor. + // type_def ptr could be invalidated by ResolveToDeclarationType and + // TemplateVisitor. type = db->Resolve(type_id); if (parent_type_id) { IndexType* parent_type_def = db->Resolve(parent_type_id.value()); @@ -1675,7 +1676,8 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { // definition, We use cursor extent (larger than spelling range) `e.x`. It // would be better if we could restrict the ranges to `.x` or just `x`. // Nevertheless, larger ranges are less specific, and should do no harm - // because they will be overriden by more specific variable references `e`. + // because they will be overriden by more specific variable references + // `e`. Range loc = ref->cursor.kind == CXCursor_MemberRefExpr && ref_cursor.get_spelling().empty() ? ref_cursor.get_extent() @@ -1750,17 +1752,17 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { !CursorSpellingContainsString(ref->cursor, param->tu->cx_tu, called->def.short_name))); - // Extents have larger ranges and thus less specific, and will be overriden - // by other functions if exist. + // Extents have larger ranges and thus less specific, and will be + // overriden by other functions if exist. // - // Members of non-concrete template types do not have useful spelling ranges. - // See the comment above for the CXIdxEntity_Field case. + // Members of non-concrete template types do not have useful spelling + // ranges. See the comment above for the CXIdxEntity_Field case. if (is_implicit || (ref->cursor.kind == CXCursor_MemberRefExpr && ref_cursor.get_spelling().empty())) loc = ref_cursor.get_extent(); - OnIndexReference_Function(db, loc, ref->container->cursor, - called_id, called, is_implicit); + OnIndexReference_Function(db, loc, 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) { @@ -1800,8 +1802,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { param->ctors.TryFindConstructorUsr(ctor_type_usr, call_type_desc); if (ctor_usr) { IndexFunc* ctor = db->Resolve(db->ToFuncId(*ctor_usr)); - AddFuncRef(&ctor->callers, - IndexFuncRef(loc, true /*is_implicit*/)); + AddFuncRef(&ctor->callers, IndexFuncRef(loc, true /*is_implicit*/)); } } } @@ -1837,21 +1838,26 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { // Foo f; // } // - UniqueAdd(referenced->uses, ClangCursor(ref->cursor).get_spelling_range()); + UniqueAdd(referenced->uses, + ClangCursor(ref->cursor).get_spelling_range()); break; } default: - std::cerr << "!! Unhandled indexEntityReference: " << cursor.ToString() - << " at " << ClangCursor(ref->cursor).get_spelling_range().start.ToString() - << std::endl; + std::cerr + << "!! Unhandled indexEntityReference: " << cursor.ToString() + << " at " + << ClangCursor(ref->cursor).get_spelling_range().start.ToString() + << std::endl; std::cerr << " ref->referencedEntity->kind = " << ref->referencedEntity->kind << std::endl; if (ref->parentEntity) std::cerr << " ref->parentEntity->kind = " << ref->parentEntity->kind << std::endl; - std::cerr << " ref->loc = " - << ClangCursor(ref->cursor).get_spelling_range().start.ToString() << std::endl; + std::cerr + << " ref->loc = " + << ClangCursor(ref->cursor).get_spelling_range().start.ToString() + << std::endl; std::cerr << " ref->kind = " << ref->kind << std::endl; if (ref->parentEntity) std::cerr << " parentEntity = " @@ -2003,7 +2009,7 @@ std::vector> ParseWithTu( std::unordered_map inc_to_line; // TODO if (param.primary_file) - for (auto &inc : param.primary_file->includes) + for (auto& inc : param.primary_file->includes) inc_to_line[inc.resolved_path] = inc.line; auto result = param.file_consumer->TakeLocalState(); @@ -2080,12 +2086,14 @@ void ClangSanityCheck() { void* reserved) -> CXIdxClientFile { return nullptr; }; - callback.ppIncludedFile = []( - CXClientData client_data, - const CXIdxIncludedFileInfo* file) -> CXIdxClientFile { return nullptr; }; - callback.importedASTFile = []( - CXClientData client_data, - const CXIdxImportedASTFileInfo*) -> CXIdxClientASTFile { + callback.ppIncludedFile = + [](CXClientData client_data, + const CXIdxIncludedFileInfo* file) -> CXIdxClientFile { + return nullptr; + }; + callback.importedASTFile = + [](CXClientData client_data, + const CXIdxImportedASTFileInfo*) -> CXIdxClientASTFile { return nullptr; }; callback.startedTranslationUnit = [](CXClientData client_data, diff --git a/src/indexer.h b/src/indexer.h index d5fea6f7..7731d043 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -112,7 +112,8 @@ enum class ClangSymbolKind : uint8_t { Parameter = 25, Using, }; -MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind, std::underlying_type::type); +MAKE_REFLECT_TYPE_PROXY(ClangSymbolKind, + std::underlying_type::type); struct IndexFuncRef { // NOTE: id can be -1 if the function call is not coming from a function. diff --git a/src/language_server_api.h b/src/language_server_api.h index e1563969..06d0c6d7 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -458,7 +458,6 @@ enum class lsDocumentHighlightKind { }; MAKE_REFLECT_TYPE_PROXY(lsDocumentHighlightKind, int); - struct lsFormattingOptions { // Size of a tab in spaces. int tabSize; diff --git a/src/match.cc b/src/match.cc index 62fb7c5e..94499b67 100644 --- a/src/match.cc +++ b/src/match.cc @@ -1,7 +1,7 @@ #include "match.h" -#include "queue_manager.h" #include "language_server_api.h" +#include "queue_manager.h" #include #include @@ -22,11 +22,10 @@ optional Matcher::Create(const std::string& search) { Matcher m; m.regex_string = search; m.regex = std::regex( - search, - std::regex_constants::ECMAScript | std::regex_constants::icase | - std::regex_constants::optimize + search, std::regex_constants::ECMAScript | std::regex_constants::icase | + std::regex_constants::optimize // std::regex_constants::nosubs - ); + ); return m; } catch (std::exception e) { Out_ShowLogMessage out; diff --git a/src/message_handler.cc b/src/message_handler.cc index 06392358..cc035691 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -21,7 +21,7 @@ struct ScanLineEvent { return !(pos == other.pos) ? pos < other.pos : other.end_pos < end_pos; } }; -} +} // namespace MessageHandler::MessageHandler() { // Dynamically allocate |message_handlers|, otherwise there will be static @@ -35,7 +35,7 @@ MessageHandler::MessageHandler() { std::vector* MessageHandler::message_handlers = nullptr; bool FindFileOrFail(QueryDatabase* db, - const Project *project, + const Project* project, optional id, const std::string& absolute_path, QueryFile** out_query_file, @@ -143,14 +143,14 @@ void EmitSemanticHighlighting(QueryDatabase* db, auto concise_name = detailed_name.substr(0, detailed_name.find('<')); if (sym.loc.range.start.line <= working_file->index_lines.size()) { std::string& line = - working_file->index_lines[sym.loc.range.start.line - 1]; + working_file->index_lines[sym.loc.range.start.line - 1]; auto pos = line.find(concise_name); sym.loc.range.end.line = sym.loc.range.start.line; if (pos == std::string::npos) sym.loc.range.end.column = sym.loc.range.start.column; else sym.loc.range.end.column = - sym.loc.range.start.column + concise_name.size(); + sym.loc.range.start.column + concise_name.size(); } break; } @@ -209,8 +209,8 @@ void EmitSemanticHighlighting(QueryDatabase* db, for (auto& entry : grouped_symbols) { Out_CqueryPublishSemanticHighlighting::Symbol& symbol = entry.second; for (auto& loc : symbol.ranges) { - // For ranges sharing the same start point, the one with leftmost end point - // comes first. + // For ranges sharing the same start point, the one with leftmost end + // point comes first. events.push_back({loc.start, loc.end, id, &symbol}); // For ranges sharing the same end point, their relative order does not // matter, therefore we arbitrarily assign loc.end to them. We use @@ -231,9 +231,11 @@ void EmitSemanticHighlighting(QueryDatabase* db, // the ealier. The order of [a0, b) [a1, b) does not matter. // The order of [a, b) [b, c) does not as long as we do not emit empty // ranges. - // Attribute range [events[i-1].pos, events[i].pos) to events[top-1].symbol . + // Attribute range [events[i-1].pos, events[i].pos) to events[top-1].symbol + // . if (top && !(events[i - 1].pos == events[i].pos)) - events[top - 1].symbol->ranges.emplace_back(events[i - 1].pos, events[i].pos); + events[top - 1].symbol->ranges.emplace_back(events[i - 1].pos, + events[i].pos); if (events[i].id >= 0) events[top++] = events[i]; else diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index f0ff3d4b..611d5ec6 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -178,8 +178,7 @@ struct InitializeHandler : BaseMessageHandler { Timer time; // Open up / load the project. - project->Load(config, - config->extraClangArguments, + project->Load(config, config->extraClangArguments, config->compilationDatabaseDirectory, project_path, config->resourceDirectory); time.ResetAndPrint("[perf] Loaded compilation entries (" + diff --git a/src/messages/shutdown.cc b/src/messages/shutdown.cc index f5b0096e..cb6c85f1 100644 --- a/src/messages/shutdown.cc +++ b/src/messages/shutdown.cc @@ -8,9 +8,8 @@ struct Ipc_Shutdown : public IpcMessage { MAKE_REFLECT_EMPTY_STRUCT(Ipc_Shutdown); REGISTER_IPC_MESSAGE(Ipc_Shutdown); -struct Out_Shutdown - : public lsOutMessage { - lsRequestId id; // defaults to std::monostate (null) +struct Out_Shutdown : public lsOutMessage { + lsRequestId id; // defaults to std::monostate (null) std::monostate result; // null }; MAKE_REFLECT_STRUCT(Out_Shutdown, jsonrpc, id, result); diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index 8531f90c..e1eca3ae 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -249,7 +249,8 @@ struct WorkspaceSymbolHandler : BaseMessageHandler { longest = std::max(longest, int(db->short_names[i].size())); std::vector score(longest); // score for each position - std::vector dp(longest); // dp[i]: maximum value by aligning pattern to str[0..i] + std::vector dp( + longest); // dp[i]: maximum value by aligning pattern to str[0..i] std::vector> permutation(result_indices.size()); for (int i = 0; i < int(result_indices.size()); i++) { permutation[i] = { @@ -260,15 +261,14 @@ struct WorkspaceSymbolHandler : BaseMessageHandler { std::greater>()); 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.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; QueueManager::WriteStdout(IpcId::WorkspaceSymbol, out); diff --git a/src/platform_posix.cc b/src/platform_posix.cc index c5c9ca49..85b5cb78 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -7,10 +7,10 @@ #include #if defined(__FreeBSD__) -# include -# include +#include +#include #elif defined(__OpenBSD__) -# include +#include #endif #include @@ -130,7 +130,10 @@ std::string GetExecutablePath() { return result; #elif defined(__FreeBSD__) static const int name[] = { - CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1, + CTL_KERN, + KERN_PROC, + KERN_PROC_PATHNAME, + -1, }; char path[MAXPATHLEN]; size_t len = sizeof(path); @@ -139,7 +142,7 @@ std::string GetExecutablePath() { return std::string(path); #else char buffer[PATH_MAX] = {0}; - if(-1 == readlink("/proc/self/exe", buffer, PATH_MAX)) + if (-1 == readlink("/proc/self/exe", buffer, PATH_MAX)) return ""; return buffer; #endif diff --git a/src/platform_win.cc b/src/platform_win.cc index b61aa0fe..b1d03da8 100644 --- a/src/platform_win.cc +++ b/src/platform_win.cc @@ -147,7 +147,6 @@ bool RunObjectiveCIndexTests() { } // TODO Wait for debugger to attach -void TraceMe() { -} +void TraceMe() {} #endif diff --git a/src/project.cc b/src/project.cc index 0fd0c6fa..173efeac 100644 --- a/src/project.cc +++ b/src/project.cc @@ -95,7 +95,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( Config* init_opts, ProjectConfig* config, const CompileCommandsEntry& entry) { - auto cleanup_maybe_relative_path = [&](const std::string& path) { // TODO/FIXME: Normalization will fail for paths that do not exist. Should // it return an optional? @@ -246,14 +245,16 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( // Using -fparse-all-comments enables documententation in the indexer and in // code completion. - if (init_opts->enableComments > 1 && !AnyStartsWith(result.args, "-fparse-all-comments")) { + if (init_opts->enableComments > 1 && + !AnyStartsWith(result.args, "-fparse-all-comments")) { result.args.push_back("-fparse-all-comments"); } return result; } -std::vector LoadFromDirectoryListing(Config* init_opts, ProjectConfig* config) { +std::vector LoadFromDirectoryListing(Config* init_opts, + ProjectConfig* config) { std::vector result; std::vector args; @@ -281,7 +282,8 @@ std::vector LoadFromDirectoryListing(Config* init_opts, ProjectC e.file = file; e.args = args; e.args.push_back(e.file); - result.push_back(GetCompilationEntryFromCompileCommandEntry(init_opts, config, e)); + result.push_back( + GetCompilationEntryFromCompileCommandEntry(init_opts, config, e)); } } @@ -351,7 +353,8 @@ std::vector LoadCompilationEntriesFromDirectory( absolute_filename = directory + "/" + relative_filename; entry.file = NormalizePathWithTestOptOut(absolute_filename); - result.push_back(GetCompilationEntryFromCompileCommandEntry(init_opts, config, entry)); + result.push_back( + GetCompilationEntryFromCompileCommandEntry(init_opts, config, entry)); our_time.Pause(); } @@ -416,8 +419,8 @@ void Project::Load(Config* init_opts, config.extra_flags = extra_flags; config.project_dir = root_directory; config.resource_dir = resource_directory; - entries = - LoadCompilationEntriesFromDirectory(init_opts, &config, opt_compilation_db_dir); + entries = LoadCompilationEntriesFromDirectory(init_opts, &config, + opt_compilation_db_dir); // Cleanup / postprocess include directories. quote_include_directories.assign(config.quote_dirs.begin(), @@ -545,12 +548,13 @@ TEST_SUITE("Project") { // FIXME: Fix this test. TEST_CASE("Path in args") { - CheckFlags("/home/user", "/home/user/foo/bar.c", - /* raw */ {"cc", "-O0", "foo/bar.c"}, - /* expected */ - {"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11", - "-O0", "&/home/user/foo/bar.c", "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option"}); + CheckFlags( + "/home/user", "/home/user/foo/bar.c", + /* raw */ {"cc", "-O0", "foo/bar.c"}, + /* expected */ + {"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11", "-O0", + "&/home/user/foo/bar.c", "-resource-dir=/w/resource_dir/", + "-Wno-unknown-warning-option"}); } TEST_CASE("Implied binary") { @@ -907,7 +911,8 @@ TEST_SUITE("Project") { "debian_jessie_amd64-sysroot", "-fno-exceptions", "-fvisibility-inlines-hidden", - "&/w/c/s/out/Release/../../ash/login/ui/lock_screen_sanity_unittest.cc", + "&/w/c/s/out/Release/../../ash/login/ui/" + "lock_screen_sanity_unittest.cc", "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"}); } diff --git a/src/query.cc b/src/query.cc index 6e797554..d0c7a911 100644 --- a/src/query.cc +++ b/src/query.cc @@ -233,8 +233,8 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) { for (const IndexFuncRef& caller : func.callers) { // Make ranges of implicit function calls larger (spanning one more column // to the left/right). This is hacky but useful. e.g. - // textDocument/definition on the space/semicolon in `A a;` or `return 42;` - // will take you to the constructor. + // textDocument/definition on the space/semicolon in `A a;` or `return + // 42;` will take you to the constructor. Range range = caller.loc; if (caller.is_implicit) { if (range.start.column > 1) diff --git a/src/query_utils.cc b/src/query_utils.cc index 29f8e52e..00888958 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -503,16 +503,17 @@ 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 in front of orders. - return static_cast(a.idx.kind) > static_cast(b.idx.kind); - }); + if (a_size != b_size) + return a_size < b_size; + // operator> orders Var/Func in front of orders. + return static_cast(a.idx.kind) > + static_cast(b.idx.kind); + }); return symbols; } diff --git a/src/serializer.cc b/src/serializer.cc index 5d254cc7..bc95fc54 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -226,7 +226,6 @@ void Reflect(Writer& visitor, SerializeFormat& value) { } std::string Serialize(SerializeFormat format, IndexFile& file) { - switch (format) { case SerializeFormat::Json: { rapidjson::StringBuffer output; @@ -261,8 +260,8 @@ std::unique_ptr Deserialize(SerializeFormat format, if (reader.HasParseError()) return nullptr; - // Do not deserialize a document with a bad version. Doing so could cause a - // crash because the file format may have changed. + // Do not deserialize a document with a bad version. Doing so could cause + // a crash because the file format may have changed. if (expected_version) { auto actual_version = reader.FindMember("version"); if (actual_version == reader.MemberEnd() || @@ -291,7 +290,8 @@ std::unique_ptr Deserialize(SerializeFormat format, if (file->version != expected_version) return nullptr; } catch (msgpack::unpack_error& ex) { - LOG_S(ERROR) << "msgpack::unpack_err for '" << path << "' " << ex.what(); + LOG_S(ERROR) << "msgpack::unpack_err for '" << path << "' " + << ex.what(); return nullptr; } break; diff --git a/src/serializer.h b/src/serializer.h index 2f1d1359..893225f3 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -15,12 +15,12 @@ class Reader { virtual ~Reader() {} virtual SerializeFormat Format() const = 0; - //virtual bool IsBool() = 0; + // virtual bool IsBool() = 0; virtual bool IsNull() = 0; virtual bool IsArray() = 0; virtual bool IsInt() = 0; - //virtual bool IsInt64() = 0; - //virtual bool IsUint64() = 0; + // virtual bool IsInt64() = 0; + // virtual bool IsUint64() = 0; virtual bool IsString() = 0; virtual void GetNull() = 0; @@ -60,12 +60,12 @@ class Writer { struct IndexFile; -#define REFLECT_MEMBER_START() \ - if (!ReflectMemberStart(visitor, value)) \ - return -#define REFLECT_MEMBER_START1(value) \ - if (!ReflectMemberStart(visitor, value)) \ - return +#define REFLECT_MEMBER_START() \ + if (!ReflectMemberStart(visitor, value)) \ + return +#define REFLECT_MEMBER_START1(value) \ + if (!ReflectMemberStart(visitor, value)) \ + return #define REFLECT_MEMBER_END() ReflectMemberEnd(visitor, value); #define REFLECT_MEMBER_END1(value) ReflectMemberEnd(visitor, value); #define REFLECT_MEMBER(name) ReflectMember(visitor, #name, value.name) @@ -106,11 +106,11 @@ struct IndexFile; // Reflects the struct so it is serialized as an array instead of an object. // This currently only supports writers. -#define MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY(type, ...) \ - inline void Reflect(Writer& visitor, type& value) { \ - visitor.StartArray(NUM_VA_ARGS(__VA_ARGS__)); \ - MACRO_MAP(_MAPPABLE_REFLECT_ARRAY, __VA_ARGS__) \ - visitor.EndArray(); \ +#define MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY(type, ...) \ + inline void Reflect(Writer& visitor, type& value) { \ + visitor.StartArray(NUM_VA_ARGS(__VA_ARGS__)); \ + MACRO_MAP(_MAPPABLE_REFLECT_ARRAY, __VA_ARGS__) \ + visitor.EndArray(); \ } // API: @@ -265,7 +265,6 @@ void ReflectMember(Writer& visitor, const char* name, std::string& value); // Reader: - inline void DefaultReflectMemberStart(Reader& visitor) {} template bool ReflectMemberStart(Reader& visitor, T& value) { diff --git a/src/serializers/json.h b/src/serializers/json.h index c304a322..1ec51f05 100644 --- a/src/serializers/json.h +++ b/src/serializers/json.h @@ -12,12 +12,12 @@ class JsonReader : public Reader { JsonReader(rapidjson::GenericValue>* m) : m_(m) {} SerializeFormat Format() const override { return SerializeFormat::Json; } - //bool IsBool() override { return m_->IsBool(); } + // bool IsBool() override { return m_->IsBool(); } bool IsNull() override { return m_->IsNull(); } bool IsArray() override { return m_->IsArray(); } bool IsInt() override { return m_->IsInt(); } - //bool IsInt64() override { return m_->IsInt64(); } - //bool IsUint64() override { return m_->IsUint64(); } + // bool IsInt64() override { return m_->IsInt64(); } + // bool IsUint64() override { return m_->IsUint64(); } bool IsString() override { return m_->IsString(); } void GetNull() override {} @@ -43,7 +43,8 @@ class JsonReader : public Reader { void DoMember(const char* name, std::function fn) override { if (m_->GetType() != rapidjson::Type::kObjectType) - return; // FIXME: signal an error that object was not deserialized correctly? + return; // FIXME: signal an error that object was not deserialized + // correctly? auto it = m_->FindMember(name); if (it != m_->MemberEnd()) { diff --git a/src/serializers/msgpack.h b/src/serializers/msgpack.h index e0ed84a1..f9704508 100644 --- a/src/serializers/msgpack.h +++ b/src/serializers/msgpack.h @@ -17,7 +17,9 @@ class MessagePackReader : public Reader { public: MessagePackReader(msgpack::unpacker* pk) : pk_(pk) { pk->next(oh_); } - SerializeFormat Format() const override { return SerializeFormat::MessagePack; } + SerializeFormat Format() const override { + return SerializeFormat::MessagePack; + } bool IsNull() override { return oh_.get().is_nil(); } bool IsArray() override { return oh_.get().type == msgpack::type::ARRAY; } @@ -36,9 +38,7 @@ class MessagePackReader : public Reader { std::string GetString() override { return Get(); } bool HasMember(const char* x) override { return true; } - std::unique_ptr operator[](const char* x) override { - return {}; - } + std::unique_ptr operator[](const char* x) override { return {}; } void IterArray(std::function fn) override { size_t n = Get(); @@ -56,7 +56,9 @@ class MessagePackWriter : public Writer { public: MessagePackWriter(msgpack::packer* m) : m_(m) {} - SerializeFormat Format() const override { return SerializeFormat::MessagePack; } + SerializeFormat Format() const override { + return SerializeFormat::MessagePack; + } void Null() override { m_->pack_nil(); } void Bool(bool x) override { m_->pack(x); } @@ -66,7 +68,9 @@ class MessagePackWriter : public Writer { void Double(double x) override { m_->pack(x); } void String(const char* x) override { m_->pack(x); } // TODO Remove std::string - void String(const char* x, size_t len) override { m_->pack(std::string(x, len)); } + void String(const char* x, size_t len) override { + m_->pack(std::string(x, len)); + } void StartArray(size_t n) override { m_->pack(n); } void EndArray() override {} void StartObject() override {} diff --git a/src/test.cc b/src/test.cc index 77ba947c..4041135e 100644 --- a/src/test.cc +++ b/src/test.cc @@ -240,7 +240,7 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) { std::cout << std::endl; if (enable_update) { std::cout - << "[Enter to continue - type u to update test, a to update all]"; + << "[Enter to continue - type u to update test, a to update all]"; char c = 'u'; if (!update_all) { c = (char)std::cin.get(); diff --git a/src/threaded_queue.h b/src/threaded_queue.h index cb776aff..94bf4c71 100644 --- a/src/threaded_queue.h +++ b/src/threaded_queue.h @@ -27,7 +27,7 @@ struct index_sequence {}; template struct make_index_sequence { - using type = typename make_index_sequence::type; + using type = typename make_index_sequence::type; }; template @@ -35,7 +35,7 @@ struct make_index_sequence<0, Is...> { using type = index_sequence; }; -} +} // namespace // std::lock accepts two or more arguments. We define an overload for one // argument. @@ -44,16 +44,12 @@ template void lock(Lockable& l) { l.lock(); } -} +} // namespace std template struct MultiQueueLock { - MultiQueueLock(Queue... lockable) : tuple_{lockable...} { - lock(); - } - ~MultiQueueLock() { - unlock(); - } + MultiQueueLock(Queue... lockable) : tuple_{lockable...} { lock(); } + ~MultiQueueLock() { unlock(); } void lock() { lock_impl(typename make_index_sequence::type{}); } diff --git a/src/type_printer.cc b/src/type_printer.cc index 0690870b..c5aac634 100644 --- a/src/type_printer.cc +++ b/src/type_printer.cc @@ -75,8 +75,7 @@ std::string GetFunctionSignature(IndexFile* db, // Second pass: insert argument names before each comma and closing paren. int i = function_name_offset; - std::string type_desc_with_names(type_desc.begin(), - type_desc.begin() + i); + std::string type_desc_with_names(type_desc.begin(), type_desc.begin() + i); type_desc_with_names.append(function_name); for (auto& arg : args) { if (arg.first < 0) { diff --git a/src/utils.cc b/src/utils.cc index fab6d8a3..641cde46 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -149,7 +149,7 @@ static void GetFilesInFolderHelper( const std::function& handler) { std::queue> q; q.push(make_pair(folder, output_prefix)); - while(!q.empty()) { + while (!q.empty()) { tinydir_dir dir; if (tinydir_open(&dir, q.front().first.c_str()) == -1) { LOG_S(WARNING) << "Unable to open directory " << folder;