From cfe9348eec376280ada91b5c3d9bd32d16c6de37 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sat, 23 Dec 2017 08:01:43 -0800 Subject: [PATCH] Format using clang format 4.0.0 --- format.sh | 5 +- src/clang_complete.cc | 14 +++--- src/clang_cursor.h | 2 +- src/clang_translation_unit.cc | 4 +- src/command_line.cc | 3 +- src/indexer.cc | 58 +++++++++++----------- src/indexer.h | 9 ++-- src/match.cc | 7 +-- src/messages/cquery_call_tree.cc | 6 +-- src/messages/cquery_type_hierarchy_tree.cc | 8 +-- src/messages/initialize.cc | 4 +- src/messages/text_document_code_lens.cc | 14 +++--- src/messages/text_document_completion.cc | 18 +++---- src/messages/text_document_definition.cc | 5 +- src/messages/text_document_hover.cc | 4 +- src/messages/workspace_symbol.cc | 3 +- src/platform_posix.cc | 17 ++++--- src/platform_win.cc | 5 +- src/project.cc | 47 ++++++++---------- src/query.h | 3 +- src/query_utils.cc | 30 +++++------ 21 files changed, 134 insertions(+), 132 deletions(-) diff --git a/format.sh b/format.sh index 0d65025b0..329509a75 100755 --- a/format.sh +++ b/format.sh @@ -9,9 +9,12 @@ # ./format.sh # +CLANG_FORMAT=./build/clang+llvm-4.0.0-x86_64-apple-darwin/bin/clang-format +echo "Using CLANG_FORMAT=$CLANG_FORMAT" + FILES=$(find src -name '*.cc' -o -name '*.h' | grep -v '/\.') for FILE in $FILES; do echo "Formatting $FILE" - clang-format -style=Chromium -i $FILE + $CLANG_FORMAT -style=Chromium -i $FILE done diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 5f05c9aaf..99caa9fd5 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -142,13 +142,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; diff --git a/src/clang_cursor.h b/src/clang_cursor.h index cc066aeda..f786519e4 100644 --- a/src/clang_cursor.h +++ b/src/clang_cursor.h @@ -93,4 +93,4 @@ struct hash { return clang_hashCursor(x.cx_cursor); } }; -} +} // namespace std diff --git a/src/clang_translation_unit.cc b/src/clang_translation_unit.cc index ff49a8e43..2edc041d4 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/command_line.cc b/src/command_line.cc index 77955238a..f05a30be7 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -1051,7 +1051,8 @@ int main(int argc, char** argv) { } if (print_help) { - std::cout << R"help(cquery is a low-latency C/C++/Objective-C language server. + std::cout + << R"help(cquery is a low-latency C/C++/Objective-C language server. Command line options: --language-server diff --git a/src/indexer.cc b/src/indexer.cc index da1785329..bdc72370e 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -76,8 +76,7 @@ struct NamespaceHelper { void RegisterQualifiedName(std::string usr, const CXIdxContainerInfo* container, - std::string qualified_name) { - } + std::string qualified_name) {} std::string QualifiedName(const CXIdxContainerInfo* container, std::string unqualified_name) { @@ -100,7 +99,7 @@ struct NamespaceHelper { namespaces.push_back(cursor); cursor = clang_getCursorSemanticParent(cursor.cx_cursor); } - for (size_t i = namespaces.size(); i > 0; ) { + for (size_t i = namespaces.size(); i > 0;) { i--; std::string name = namespaces[i].get_spelling(); // Empty name indicates unnamed namespace, anonymous struct, anonymous @@ -266,8 +265,7 @@ IndexFile* ConsumeFile(IndexParam* param, CXFile file) { // Capture file contents in |param->file_contents| if it was not specified // at the start of indexing. - if (db && - !param->file_contents.count(file_name)) { + if (db && !param->file_contents.count(file_name)) { optional content = ReadContent(file_name); if (content) param->file_contents.emplace(file_name, *content); @@ -601,16 +599,16 @@ optional FindType(ClangCursor cursor) { } bool IsGlobalContainer(const CXIdxContainerInfo* container) { - if (!container) - return false; + if (!container) + return false; - switch (container->cursor.kind) { + switch (container->cursor.kind) { case CXCursor_Namespace: case CXCursor_TranslationUnit: return true; default: return false; - } + } } bool IsTypeDefinition(const CXIdxContainerInfo* container) { @@ -1060,12 +1058,13 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { } bool is_system = clang_Location_isInSystemHeader( - clang_indexLoc_getCXSourceLocation(decl->loc)); + clang_indexLoc_getCXSourceLocation(decl->loc)); var->def.is_global = !is_system && IsGlobalContainer(decl->semanticContainer); var->def.is_member = !is_system && IsTypeDefinition(decl->semanticContainer); - var->def.is_local = !is_system && !var->def.is_global && !var->def.is_member; + var->def.is_local = + !is_system && !var->def.is_global && !var->def.is_member; //} @@ -1207,7 +1206,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { size_t offset = 0; if (type_desc.back() == ')') { size_t balance = 0; - for (offset = type_desc.size(); offset; ) { + for (offset = type_desc.size(); offset;) { offset--; if (type_desc[offset] == ')') balance++; @@ -1296,10 +1295,10 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { type->def.detailed_name = ns->QualifiedName(decl->semanticContainer, type->def.short_name); - // For Typedef/CXXTypeAlias spanning a few lines, display the declaration line, - // with spelling name replaced with qualified name. - // TODO Think how to display multi-line declaration like `typedef struct { ... } foo;` - // https://github.com/jacobdufault/cquery/issues/29 + // For Typedef/CXXTypeAlias spanning a few lines, display the declaration + // line, with spelling name replaced with qualified name. + // TODO Think how to display multi-line declaration like `typedef struct { + // ... } foo;` https://github.com/jacobdufault/cquery/issues/29 if (extent.end.line - extent.start.line < kMaxLinesDisplayTypeAliasDeclarations) { FileContentsWithOffsets& fc = param->file_contents[db->path]; @@ -1468,15 +1467,15 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { // as lambdas cannot be split across files. if (var->def.short_name.empty()) { CXFile referenced_file; - Range spelling = ResolveSpelling(referenced.cx_cursor, &referenced_file); + Range spelling = + ResolveSpelling(referenced.cx_cursor, &referenced_file); if (file == referenced_file) { var->def.definition_spelling = spelling; var->def.definition_extent = ResolveExtent(referenced.cx_cursor); - // TODO Some of the logic here duplicates CXIdxEntity_Variable branch of - // OnIndexDeclaration. - // But there `decl` is of type CXIdxDeclInfo and has more information, - // thus not easy to reuse the code. + // TODO Some of the logic here duplicates CXIdxEntity_Variable branch + // of OnIndexDeclaration. But there `decl` is of type CXIdxDeclInfo + // and has more information, thus not easy to reuse the code. var->def.short_name = referenced.get_spelling(); std::string type_name = ToString( clang_getTypeSpelling(clang_getCursorType(referenced.cx_cursor))); @@ -1679,7 +1678,8 @@ optional FileContentsWithOffsets::ToOffset(Position p) const { return nullopt; } -optional FileContentsWithOffsets::ContentsInRange(Range range) const { +optional FileContentsWithOffsets::ContentsInRange( + Range range) const { optional start_offset = ToOffset(range.start), end_offset = ToOffset(range.end); if (start_offset && end_offset && *start_offset < *end_offset) @@ -1838,14 +1838,12 @@ 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 bcd2b94cb..0c95632c8 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -178,8 +178,7 @@ struct TypeDefDefinitionData { bool operator==( const TypeDefDefinitionData& other) const { return short_name == other.short_name && - detailed_name == other.detailed_name && - hover == other.hover && + detailed_name == other.detailed_name && hover == other.hover && definition_spelling == other.definition_spelling && definition_extent == other.definition_extent && alias_of == other.alias_of && parents == other.parents && @@ -270,8 +269,7 @@ struct FuncDefDefinitionData { const FuncDefDefinitionData& other) const { return short_name == other.short_name && - detailed_name == other.detailed_name && - hover == other.hover && + detailed_name == other.detailed_name && hover == other.hover && definition_spelling == other.definition_spelling && definition_extent == other.definition_extent && declaring_type == other.declaring_type && base == other.base && @@ -387,8 +385,7 @@ struct VarDefDefinitionData { bool operator==( const VarDefDefinitionData& other) const { return short_name == other.short_name && - detailed_name == other.detailed_name && - hover == other.hover && + detailed_name == other.detailed_name && hover == other.hover && declaration == other.declaration && definition_spelling == other.definition_spelling && definition_extent == other.definition_extent && diff --git a/src/match.cc b/src/match.cc index ae762b8ff..dc722d5d5 100644 --- a/src/match.cc +++ b/src/match.cc @@ -22,10 +22,11 @@ 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/messages/cquery_call_tree.cc b/src/messages/cquery_call_tree.cc index 182395576..0eec9ae84 100644 --- a/src/messages/cquery_call_tree.cc +++ b/src/messages/cquery_call_tree.cc @@ -75,9 +75,9 @@ std::vector BuildExpandCallTree( if (!root_func.def) return {}; - auto format_location = - [&](const lsLocation& location, - optional declaring_type) -> std::string { + auto format_location = [&]( + const lsLocation& location, + optional declaring_type) -> std::string { std::string base; if (declaring_type) { diff --git a/src/messages/cquery_type_hierarchy_tree.cc b/src/messages/cquery_type_hierarchy_tree.cc index 03784c72f..2c7910888 100644 --- a/src/messages/cquery_type_hierarchy_tree.cc +++ b/src/messages/cquery_type_hierarchy_tree.cc @@ -113,10 +113,10 @@ BuildParentInheritanceHierarchyForFunc(QueryDatabase* db, Out_CqueryTypeHierarchyTree::TypeEntry parent_entry; parent_entry.name = parent_func.def->detailed_name; if (parent_func.def->definition_spelling) - parent_entry.location = - GetLsLocation(db, working_files, *parent_func.def->definition_spelling); - parent_entry.children = BuildParentInheritanceHierarchyForFunc( - db, working_files, parent_id); + parent_entry.location = GetLsLocation( + db, working_files, *parent_func.def->definition_spelling); + parent_entry.children = + BuildParentInheritanceHierarchyForFunc(db, working_files, parent_id); entries.push_back(parent_entry); } diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index eaa27c402..4110f9d22 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -165,8 +165,8 @@ struct InitializeHandler : BaseMessageHandler { // If the user has not specified how many indexers to run, try to // guess an appropriate value. Default to 80% utilization. const float kDefaultTargetUtilization = 0.8f; - config->indexerCount = (int)( - std::thread::hardware_concurrency() * kDefaultTargetUtilization); + config->indexerCount = (int)(std::thread::hardware_concurrency() * + kDefaultTargetUtilization); if (config->indexerCount <= 0) config->indexerCount = 1; } diff --git a/src/messages/text_document_code_lens.cc b/src/messages/text_document_code_lens.cc index 9876a5cfe..14a914c26 100644 --- a/src/messages/text_document_code_lens.cc +++ b/src/messages/text_document_code_lens.cc @@ -202,13 +202,14 @@ struct TextDocumentCodeLensHandler // "Base" if (func.def->base.size() == 1) { - optional base_loc = GetDefinitionSpellingOfSymbol(db, func.def->base[0]); + optional base_loc = + GetDefinitionSpellingOfSymbol(db, func.def->base[0]); if (base_loc) { optional ls_base = - GetLsLocation(db, working_files, *base_loc); + GetLsLocation(db, working_files, *base_loc); if (ls_base) { optional range = - GetLsRange(common.working_file, ref.loc.range); + GetLsRange(common.working_file, ref.loc.range); if (range) { TCodeLens code_lens; code_lens.range = *range; @@ -223,10 +224,9 @@ struct TextDocumentCodeLensHandler } } } else { - AddCodeLens("base", "base", &common, - ref.loc.OffsetStartColumn(1), - ToQueryLocation(db, func.def->base), nullopt, - false /*force_display*/); + AddCodeLens("base", "base", &common, ref.loc.OffsetStartColumn(1), + ToQueryLocation(db, func.def->base), nullopt, + false /*force_display*/); } break; diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index cae380bd9..bee1c923b 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -194,16 +194,14 @@ struct TextDocumentCompletionHandler : MessageHandler { !global_code_complete_cache->cached_results_.empty(); }); if (is_cache_match) { - ClangCompleteManager::OnComplete freshen_global = - [this](std::vector results, - bool is_cached_result) { - assert(!is_cached_result); - - // note: path is updated in the normal completion handler. - global_code_complete_cache->WithLock([&]() { - global_code_complete_cache->cached_results_ = results; - }); - }; + ClangCompleteManager::OnComplete freshen_global = [this]( + std::vector results, bool is_cached_result) { + assert(!is_cached_result); + + // note: path is updated in the normal completion handler. + global_code_complete_cache->WithLock( + [&]() { global_code_complete_cache->cached_results_ = results; }); + }; global_code_complete_cache->WithLock([&]() { callback(global_code_complete_cache->cached_results_, diff --git a/src/messages/text_document_definition.cc b/src/messages/text_document_definition.cc index 39994de16..99c7621ca 100644 --- a/src/messages/text_document_definition.cc +++ b/src/messages/text_document_definition.cc @@ -24,9 +24,8 @@ struct Out_TextDocumentDefinition }; MAKE_REFLECT_STRUCT(Out_TextDocumentDefinition, jsonrpc, id, result); -std::vector GetGotoDefinitionTargets( - QueryDatabase* db, - const SymbolIdx& symbol) { +std::vector GetGotoDefinitionTargets(QueryDatabase* db, + const SymbolIdx& symbol) { switch (symbol.kind) { // Returns GetDeclarationsOfSymbolForGotoDefinition and // variable type definition. diff --git a/src/messages/text_document_hover.cc b/src/messages/text_document_hover.cc index dfd677e52..5dd82239e 100644 --- a/src/messages/text_document_hover.cc +++ b/src/messages/text_document_hover.cc @@ -2,7 +2,7 @@ #include "query_utils.h" namespace { - + std::string GetHoverForSymbol(QueryDatabase* db, const SymbolIdx& symbol) { switch (symbol.kind) { case SymbolKind::Type: { @@ -60,7 +60,7 @@ struct Out_TextDocumentHover : public lsOutMessage { optional result; }; MAKE_REFLECT_STRUCT(Out_TextDocumentHover::Result, contents, range); -void Reflect(Writer& visitor, Out_TextDocumentHover& value) { +void Reflect(Writer& visitor, Out_TextDocumentHover& value) { REFLECT_MEMBER_START(); REFLECT_MEMBER(jsonrpc); REFLECT_MEMBER(id); diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index 31ef00c46..e20053909 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -11,7 +11,8 @@ void InsertSymbolIntoResult(QueryDatabase* db, WorkingFiles* working_files, SymbolIdx symbol, std::vector* result) { - optional info = GetSymbolInfo(db, working_files, symbol, false /*use_short_name*/); + optional info = + GetSymbolInfo(db, working_files, symbol, false /*use_short_name*/); if (!info) return; diff --git a/src/platform_posix.cc b/src/platform_posix.cc index 00f1d747e..fe6b1e5fa 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -33,11 +33,11 @@ #include #if defined(__FreeBSD__) -# include // MAXPATHLEN -# include // sysctl +#include // MAXPATHLEN +#include // sysctl #elif defined(__linux__) -# include -# include +#include +#include #endif namespace { @@ -211,22 +211,23 @@ std::unique_ptr CreatePlatformSharedMemory( void PlatformInit() {} #ifdef __APPLE__ -extern "C" int _NSGetExecutablePath(char* buf,uint32_t* bufsize); +extern "C" int _NSGetExecutablePath(char* buf, uint32_t* bufsize); #endif -// See https://stackoverflow.com/questions/143174/how-do-i-get-the-directory-that-a-program-is-running-from +// See +// https://stackoverflow.com/questions/143174/how-do-i-get-the-directory-that-a-program-is-running-from std::string GetExecutablePath() { #ifdef __APPLE__ uint32_t size = 0; _NSGetExecutablePath(nullptr, &size); - char *buffer = new char[size]; + char* buffer = new char[size]; _NSGetExecutablePath(buffer, &size); std::string result(buffer); delete[] buffer; 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); diff --git a/src/platform_win.cc b/src/platform_win.cc index 1a0cfb09a..0e7f406ae 100644 --- a/src/platform_win.cc +++ b/src/platform_win.cc @@ -127,7 +127,8 @@ void PlatformInit() { _setmode(_fileno(stdin), O_BINARY); } -// See https://stackoverflow.com/questions/143174/how-do-i-get-the-directory-that-a-program-is-running-from +// See +// https://stackoverflow.com/questions/143174/how-do-i-get-the-directory-that-a-program-is-running-from std::string GetExecutablePath() { char result[MAX_PATH] = {0}; GetModuleFileName(NULL, result, MAX_PATH); @@ -233,6 +234,7 @@ std::vector GetPlatformClangArguments() { // $ clang++ -E -x c++ - -v // + // clang-format off return { "-isystem","C:/Program Files/Microsoft Visual Studio 10.0/VC/include", "-isystem","C:/Program Files/Microsoft Visual Studio 9.0/VC/include", @@ -244,6 +246,7 @@ std::vector GetPlatformClangArguments() { "-isystem","C:/Program Files/LLVM/lib/clang/4.0.0/include", "-fms-extensions", "-fms-compatibility", "-fms-compatibility-version=18", "-fdelayed-template-parsing" }; + // clang-format on } void FreeUnusedMemory() {} diff --git a/src/project.cc b/src/project.cc index 9489abb7c..2b1612a56 100644 --- a/src/project.cc +++ b/src/project.cc @@ -52,15 +52,10 @@ static std::vector kBlacklistMulti = { // Blacklisted flags which are always removed from the command line. static std::vector kBlacklist = { - "-c", - "-MP", - "-MD", - "-MMD", - "--fcolor-diagnostics", + "-c", "-MP", "-MD", "-MMD", "--fcolor-diagnostics", // This strips path-like args but is a bit hacky. - "/", - "..", + "/", "..", }; // Arguments which are followed by a potentially relative path. We need to make @@ -204,7 +199,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( else if (*source_file_type == "c++") result.args.push_back("-std=c++11"); } - } // Add -resource-dir so clang can correctly resolve system includes like @@ -486,19 +480,21 @@ TEST_SUITE("Project") { TEST_CASE("strip meta-compiler invocations") { CheckFlags( /* raw */ {"clang", "-lstdc++", "myfile.cc"}, - /* expected */ {"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11", - "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option"}); - - CheckFlags(/* raw */ {"goma", "clang"}, - /* expected */ {"clang", "-xc++", "-std=c++11", - "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option"}); - - CheckFlags(/* raw */ {"goma", "clang", "--foo"}, - /* expected */ {"clang", "--foo", "-xc++", "-std=c++11", - "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option"}); + /* expected */ + {"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11", + "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"}); + + CheckFlags( + /* raw */ {"goma", "clang"}, + /* expected */ + {"clang", "-xc++", "-std=c++11", "-resource-dir=/w/resource_dir/", + "-Wno-unknown-warning-option"}); + + CheckFlags( + /* raw */ {"goma", "clang", "--foo"}, + /* expected */ + {"clang", "--foo", "-xc++", "-std=c++11", + "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"}); } // FIXME: Fix this test. @@ -512,11 +508,12 @@ TEST_SUITE("Project") { } TEST_CASE("Implied binary") { - CheckFlags("/home/user", "/home/user/foo/bar.cc", + CheckFlags( + "/home/user", "/home/user/foo/bar.cc", /* raw */ {"-DDONT_IGNORE_ME"}, - /* expected */ {"clang++", "-DDONT_IGNORE_ME", "-xc++", "-std=c++11", - "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option"}); + /* expected */ + {"clang++", "-DDONT_IGNORE_ME", "-xc++", "-std=c++11", + "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"}); } // Checks flag parsing for a random chromium file in comparison to what diff --git a/src/query.h b/src/query.h index a175afba8..cd4a99149 100644 --- a/src/query.h +++ b/src/query.h @@ -51,7 +51,8 @@ struct QueryLocation { MAKE_REFLECT_STRUCT(QueryLocation, path, range); MAKE_HASHABLE(QueryLocation, t.path, t.range); -// The order matters. In FindSymbolsAtLocation, we want Var/Func ordered in front of others. +// The order matters. In FindSymbolsAtLocation, we want Var/Func ordered in +// front of others. enum class SymbolKind : int { Invalid, File, Type, Func, Var }; MAKE_REFLECT_TYPE_PROXY(SymbolKind, int); diff --git a/src/query_utils.cc b/src/query_utils.cc index ba74b22e0..337524066 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -425,7 +425,8 @@ optional GetSymbolInfo(QueryDatabase* db, return nullopt; lsSymbolInformation info; - info.name = use_short_name ? type.def->short_name : type.def->detailed_name; + info.name = + use_short_name ? type.def->short_name : type.def->detailed_name; if (type.def->detailed_name != type.def->short_name) info.containerName = type.def->detailed_name; info.kind = lsSymbolKind::Class; @@ -437,7 +438,8 @@ optional GetSymbolInfo(QueryDatabase* db, return nullopt; lsSymbolInformation info; - info.name = use_short_name ? func.def->short_name : func.def->detailed_name; + info.name = + use_short_name ? func.def->short_name : func.def->detailed_name; info.containerName = func.def->detailed_name; info.kind = lsSymbolKind::Function; @@ -537,23 +539,23 @@ std::vector FindSymbolsAtLocation(WorkingFile* working_file, // important for macros which generate code so that we can resolving the // macro argument takes priority over the entire macro body. // - // Order SymbolKind::Var before SymbolKind::Type. Macro calls are treated as Var - // currently. If a macro expands to tokens led by a SymbolKind::Type, the + // Order SymbolKind::Var before SymbolKind::Type. Macro calls are treated as + // Var currently. If a macro expands to tokens led by a SymbolKind::Type, the // macro and the Type have the same range. We want to find the macro // definition instead of the Type definition. // // 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); - - 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); - }); + 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); + }); return symbols; }