Skip to content

Commit

Permalink
Format using clang format 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdufault committed Dec 23, 2017
1 parent 1b66a51 commit cfe9348
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 132 deletions.
5 changes: 4 additions & 1 deletion format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

14 changes: 7 additions & 7 deletions src/clang_complete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/clang_cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ struct hash<ClangCursor> {
return clang_hashCursor(x.cx_cursor);
}
};
}
} // namespace std
4 changes: 2 additions & 2 deletions src/clang_translation_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 28 additions & 30 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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<std::string> content = ReadContent(file_name);
if (content)
param->file_contents.emplace(file_name, *content);
Expand Down Expand Up @@ -601,16 +599,16 @@ optional<ClangCursor> 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) {
Expand Down Expand Up @@ -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;

//}

Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -1679,7 +1678,8 @@ optional<int> FileContentsWithOffsets::ToOffset(Position p) const {
return nullopt;
}

optional<std::string> FileContentsWithOffsets::ContentsInRange(Range range) const {
optional<std::string> FileContentsWithOffsets::ContentsInRange(
Range range) const {
optional<int> start_offset = ToOffset(range.start),
end_offset = ToOffset(range.end);
if (start_offset && end_offset && *start_offset < *end_offset)
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions src/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ struct TypeDefDefinitionData {
bool operator==(
const TypeDefDefinitionData<TypeId, FuncId, VarId, Range>& 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 &&
Expand Down Expand Up @@ -270,8 +269,7 @@ struct FuncDefDefinitionData {
const FuncDefDefinitionData<TypeId, FuncId, VarId, FuncRef, Range>& 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 &&
Expand Down Expand Up @@ -387,8 +385,7 @@ struct VarDefDefinitionData {
bool operator==(
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& 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 &&
Expand Down
7 changes: 4 additions & 3 deletions src/match.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ optional<Matcher> 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;
Expand Down
6 changes: 3 additions & 3 deletions src/messages/cquery_call_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ std::vector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(
if (!root_func.def)
return {};

auto format_location =
[&](const lsLocation& location,
optional<QueryTypeId> declaring_type) -> std::string {
auto format_location = [&](
const lsLocation& location,
optional<QueryTypeId> declaring_type) -> std::string {
std::string base;

if (declaring_type) {
Expand Down
8 changes: 4 additions & 4 deletions src/messages/cquery_type_hierarchy_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
// 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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/messages/text_document_code_lens.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@ struct TextDocumentCodeLensHandler

// "Base"
if (func.def->base.size() == 1) {
optional<QueryLocation> base_loc = GetDefinitionSpellingOfSymbol(db, func.def->base[0]);
optional<QueryLocation> base_loc =
GetDefinitionSpellingOfSymbol(db, func.def->base[0]);
if (base_loc) {
optional<lsLocation> ls_base =
GetLsLocation(db, working_files, *base_loc);
GetLsLocation(db, working_files, *base_loc);
if (ls_base) {
optional<lsRange> range =
GetLsRange(common.working_file, ref.loc.range);
GetLsRange(common.working_file, ref.loc.range);
if (range) {
TCodeLens code_lens;
code_lens.range = *range;
Expand All @@ -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;
Expand Down
18 changes: 8 additions & 10 deletions src/messages/text_document_completion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<lsCompletionItem> 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<lsCompletionItem> 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_,
Expand Down
5 changes: 2 additions & 3 deletions src/messages/text_document_definition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ struct Out_TextDocumentDefinition
};
MAKE_REFLECT_STRUCT(Out_TextDocumentDefinition, jsonrpc, id, result);

std::vector<QueryLocation> GetGotoDefinitionTargets(
QueryDatabase* db,
const SymbolIdx& symbol) {
std::vector<QueryLocation> GetGotoDefinitionTargets(QueryDatabase* db,
const SymbolIdx& symbol) {
switch (symbol.kind) {
// Returns GetDeclarationsOfSymbolForGotoDefinition and
// variable type definition.
Expand Down
4 changes: 2 additions & 2 deletions src/messages/text_document_hover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "query_utils.h"

namespace {

std::string GetHoverForSymbol(QueryDatabase* db, const SymbolIdx& symbol) {
switch (symbol.kind) {
case SymbolKind::Type: {
Expand Down Expand Up @@ -60,7 +60,7 @@ struct Out_TextDocumentHover : public lsOutMessage<Out_TextDocumentHover> {
optional<Result> 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);
Expand Down
3 changes: 2 additions & 1 deletion src/messages/workspace_symbol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ void InsertSymbolIntoResult(QueryDatabase* db,
WorkingFiles* working_files,
SymbolIdx symbol,
std::vector<lsSymbolInformation>* result) {
optional<lsSymbolInformation> info = GetSymbolInfo(db, working_files, symbol, false /*use_short_name*/);
optional<lsSymbolInformation> info =
GetSymbolInfo(db, working_files, symbol, false /*use_short_name*/);
if (!info)
return;

Expand Down
Loading

0 comments on commit cfe9348

Please sign in to comment.