mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 18:00:26 +00:00
Format using clang format 4.0.0
This commit is contained in:
parent
4aeb6acf04
commit
fb491e6c6d
@ -142,13 +142,13 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
|
|||||||
case CXCursor_ObjCClassRef:
|
case CXCursor_ObjCClassRef:
|
||||||
return lsCompletionItemKind::Reference;
|
return lsCompletionItemKind::Reference;
|
||||||
|
|
||||||
// return lsCompletionItemKind::Property;
|
// return lsCompletionItemKind::Property;
|
||||||
// return lsCompletionItemKind::Unit;
|
// return lsCompletionItemKind::Unit;
|
||||||
// return lsCompletionItemKind::Value;
|
// return lsCompletionItemKind::Value;
|
||||||
// return lsCompletionItemKind::Keyword;
|
// return lsCompletionItemKind::Keyword;
|
||||||
// return lsCompletionItemKind::Snippet;
|
// return lsCompletionItemKind::Snippet;
|
||||||
// return lsCompletionItemKind::Color;
|
// return lsCompletionItemKind::Color;
|
||||||
// return lsCompletionItemKind::File;
|
// return lsCompletionItemKind::File;
|
||||||
|
|
||||||
case CXCursor_NotImplemented:
|
case CXCursor_NotImplemented:
|
||||||
return lsCompletionItemKind::Text;
|
return lsCompletionItemKind::Text;
|
||||||
|
@ -93,4 +93,4 @@ struct hash<ClangCursor> {
|
|||||||
return clang_hashCursor(x.cx_cursor);
|
return clang_hashCursor(x.cx_cursor);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace std
|
||||||
|
@ -19,8 +19,8 @@ void EmitDiagnostics(std::string path,
|
|||||||
CXTranslationUnit tu) {
|
CXTranslationUnit tu) {
|
||||||
std::string output = "Fatal errors while trying to parse " + path + "\n";
|
std::string output = "Fatal errors while trying to parse " + path + "\n";
|
||||||
output +=
|
output +=
|
||||||
"Args: " +
|
"Args: " + StringJoinMap(
|
||||||
StringJoinMap(args, [](const char* arg) { return std::string(arg); }) +
|
args, [](const char* arg) { return std::string(arg); }) +
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
size_t num_diagnostics = clang_getNumDiagnostics(tu);
|
size_t num_diagnostics = clang_getNumDiagnostics(tu);
|
||||||
|
@ -1051,7 +1051,8 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (print_help) {
|
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:
|
Command line options:
|
||||||
--language-server
|
--language-server
|
||||||
|
@ -76,8 +76,7 @@ struct NamespaceHelper {
|
|||||||
|
|
||||||
void RegisterQualifiedName(std::string usr,
|
void RegisterQualifiedName(std::string usr,
|
||||||
const CXIdxContainerInfo* container,
|
const CXIdxContainerInfo* container,
|
||||||
std::string qualified_name) {
|
std::string qualified_name) {}
|
||||||
}
|
|
||||||
|
|
||||||
std::string QualifiedName(const CXIdxContainerInfo* container,
|
std::string QualifiedName(const CXIdxContainerInfo* container,
|
||||||
std::string unqualified_name) {
|
std::string unqualified_name) {
|
||||||
@ -100,7 +99,7 @@ struct NamespaceHelper {
|
|||||||
namespaces.push_back(cursor);
|
namespaces.push_back(cursor);
|
||||||
cursor = clang_getCursorSemanticParent(cursor.cx_cursor);
|
cursor = clang_getCursorSemanticParent(cursor.cx_cursor);
|
||||||
}
|
}
|
||||||
for (size_t i = namespaces.size(); i > 0; ) {
|
for (size_t i = namespaces.size(); i > 0;) {
|
||||||
i--;
|
i--;
|
||||||
std::string name = namespaces[i].get_spelling();
|
std::string name = namespaces[i].get_spelling();
|
||||||
// Empty name indicates unnamed namespace, anonymous struct, anonymous
|
// 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
|
// Capture file contents in |param->file_contents| if it was not specified
|
||||||
// at the start of indexing.
|
// at the start of indexing.
|
||||||
if (db &&
|
if (db && !param->file_contents.count(file_name)) {
|
||||||
!param->file_contents.count(file_name)) {
|
|
||||||
optional<std::string> content = ReadContent(file_name);
|
optional<std::string> content = ReadContent(file_name);
|
||||||
if (content)
|
if (content)
|
||||||
param->file_contents.emplace(file_name, *content);
|
param->file_contents.emplace(file_name, *content);
|
||||||
@ -601,16 +599,16 @@ optional<ClangCursor> FindType(ClangCursor cursor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsGlobalContainer(const CXIdxContainerInfo* container) {
|
bool IsGlobalContainer(const CXIdxContainerInfo* container) {
|
||||||
if (!container)
|
if (!container)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (container->cursor.kind) {
|
switch (container->cursor.kind) {
|
||||||
case CXCursor_Namespace:
|
case CXCursor_Namespace:
|
||||||
case CXCursor_TranslationUnit:
|
case CXCursor_TranslationUnit:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsTypeDefinition(const CXIdxContainerInfo* container) {
|
bool IsTypeDefinition(const CXIdxContainerInfo* container) {
|
||||||
@ -1060,12 +1058,13 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool is_system = clang_Location_isInSystemHeader(
|
bool is_system = clang_Location_isInSystemHeader(
|
||||||
clang_indexLoc_getCXSourceLocation(decl->loc));
|
clang_indexLoc_getCXSourceLocation(decl->loc));
|
||||||
var->def.is_global =
|
var->def.is_global =
|
||||||
!is_system && IsGlobalContainer(decl->semanticContainer);
|
!is_system && IsGlobalContainer(decl->semanticContainer);
|
||||||
var->def.is_member =
|
var->def.is_member =
|
||||||
!is_system && IsTypeDefinition(decl->semanticContainer);
|
!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;
|
size_t offset = 0;
|
||||||
if (type_desc.back() == ')') {
|
if (type_desc.back() == ')') {
|
||||||
size_t balance = 0;
|
size_t balance = 0;
|
||||||
for (offset = type_desc.size(); offset; ) {
|
for (offset = type_desc.size(); offset;) {
|
||||||
offset--;
|
offset--;
|
||||||
if (type_desc[offset] == ')')
|
if (type_desc[offset] == ')')
|
||||||
balance++;
|
balance++;
|
||||||
@ -1296,10 +1295,10 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
type->def.detailed_name =
|
type->def.detailed_name =
|
||||||
ns->QualifiedName(decl->semanticContainer, type->def.short_name);
|
ns->QualifiedName(decl->semanticContainer, type->def.short_name);
|
||||||
|
|
||||||
// For Typedef/CXXTypeAlias spanning a few lines, display the declaration line,
|
// For Typedef/CXXTypeAlias spanning a few lines, display the declaration
|
||||||
// with spelling name replaced with qualified name.
|
// line, with spelling name replaced with qualified name.
|
||||||
// TODO Think how to display multi-line declaration like `typedef struct { ... } foo;`
|
// TODO Think how to display multi-line declaration like `typedef struct {
|
||||||
// https://github.com/jacobdufault/cquery/issues/29
|
// ... } foo;` https://github.com/jacobdufault/cquery/issues/29
|
||||||
if (extent.end.line - extent.start.line <
|
if (extent.end.line - extent.start.line <
|
||||||
kMaxLinesDisplayTypeAliasDeclarations) {
|
kMaxLinesDisplayTypeAliasDeclarations) {
|
||||||
FileContentsWithOffsets& fc = param->file_contents[db->path];
|
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.
|
// as lambdas cannot be split across files.
|
||||||
if (var->def.short_name.empty()) {
|
if (var->def.short_name.empty()) {
|
||||||
CXFile referenced_file;
|
CXFile referenced_file;
|
||||||
Range spelling = ResolveSpelling(referenced.cx_cursor, &referenced_file);
|
Range spelling =
|
||||||
|
ResolveSpelling(referenced.cx_cursor, &referenced_file);
|
||||||
if (file == referenced_file) {
|
if (file == referenced_file) {
|
||||||
var->def.definition_spelling = spelling;
|
var->def.definition_spelling = spelling;
|
||||||
var->def.definition_extent = ResolveExtent(referenced.cx_cursor);
|
var->def.definition_extent = ResolveExtent(referenced.cx_cursor);
|
||||||
|
|
||||||
// TODO Some of the logic here duplicates CXIdxEntity_Variable branch of
|
// TODO Some of the logic here duplicates CXIdxEntity_Variable branch
|
||||||
// OnIndexDeclaration.
|
// of OnIndexDeclaration. But there `decl` is of type CXIdxDeclInfo
|
||||||
// But there `decl` is of type CXIdxDeclInfo and has more information,
|
// and has more information, thus not easy to reuse the code.
|
||||||
// thus not easy to reuse the code.
|
|
||||||
var->def.short_name = referenced.get_spelling();
|
var->def.short_name = referenced.get_spelling();
|
||||||
std::string type_name = ToString(
|
std::string type_name = ToString(
|
||||||
clang_getTypeSpelling(clang_getCursorType(referenced.cx_cursor)));
|
clang_getTypeSpelling(clang_getCursorType(referenced.cx_cursor)));
|
||||||
@ -1679,7 +1678,8 @@ optional<int> FileContentsWithOffsets::ToOffset(Position p) const {
|
|||||||
return nullopt;
|
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),
|
optional<int> start_offset = ToOffset(range.start),
|
||||||
end_offset = ToOffset(range.end);
|
end_offset = ToOffset(range.end);
|
||||||
if (start_offset && end_offset && *start_offset < *end_offset)
|
if (start_offset && end_offset && *start_offset < *end_offset)
|
||||||
@ -1838,14 +1838,12 @@ void ClangSanityCheck() {
|
|||||||
void* reserved) -> CXIdxClientFile {
|
void* reserved) -> CXIdxClientFile {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
callback.ppIncludedFile =
|
callback.ppIncludedFile = [](
|
||||||
[](CXClientData client_data,
|
CXClientData client_data,
|
||||||
const CXIdxIncludedFileInfo* file) -> CXIdxClientFile {
|
const CXIdxIncludedFileInfo* file) -> CXIdxClientFile { return nullptr; };
|
||||||
return nullptr;
|
callback.importedASTFile = [](
|
||||||
};
|
CXClientData client_data,
|
||||||
callback.importedASTFile =
|
const CXIdxImportedASTFileInfo*) -> CXIdxClientASTFile {
|
||||||
[](CXClientData client_data,
|
|
||||||
const CXIdxImportedASTFileInfo*) -> CXIdxClientASTFile {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
callback.startedTranslationUnit = [](CXClientData client_data,
|
callback.startedTranslationUnit = [](CXClientData client_data,
|
||||||
|
@ -178,8 +178,7 @@ struct TypeDefDefinitionData {
|
|||||||
bool operator==(
|
bool operator==(
|
||||||
const TypeDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
const TypeDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||||
return short_name == other.short_name &&
|
return short_name == other.short_name &&
|
||||||
detailed_name == other.detailed_name &&
|
detailed_name == other.detailed_name && hover == other.hover &&
|
||||||
hover == other.hover &&
|
|
||||||
definition_spelling == other.definition_spelling &&
|
definition_spelling == other.definition_spelling &&
|
||||||
definition_extent == other.definition_extent &&
|
definition_extent == other.definition_extent &&
|
||||||
alias_of == other.alias_of && parents == other.parents &&
|
alias_of == other.alias_of && parents == other.parents &&
|
||||||
@ -270,8 +269,7 @@ struct FuncDefDefinitionData {
|
|||||||
const FuncDefDefinitionData<TypeId, FuncId, VarId, FuncRef, Range>& other)
|
const FuncDefDefinitionData<TypeId, FuncId, VarId, FuncRef, Range>& other)
|
||||||
const {
|
const {
|
||||||
return short_name == other.short_name &&
|
return short_name == other.short_name &&
|
||||||
detailed_name == other.detailed_name &&
|
detailed_name == other.detailed_name && hover == other.hover &&
|
||||||
hover == other.hover &&
|
|
||||||
definition_spelling == other.definition_spelling &&
|
definition_spelling == other.definition_spelling &&
|
||||||
definition_extent == other.definition_extent &&
|
definition_extent == other.definition_extent &&
|
||||||
declaring_type == other.declaring_type && base == other.base &&
|
declaring_type == other.declaring_type && base == other.base &&
|
||||||
@ -387,8 +385,7 @@ struct VarDefDefinitionData {
|
|||||||
bool operator==(
|
bool operator==(
|
||||||
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||||
return short_name == other.short_name &&
|
return short_name == other.short_name &&
|
||||||
detailed_name == other.detailed_name &&
|
detailed_name == other.detailed_name && hover == other.hover &&
|
||||||
hover == other.hover &&
|
|
||||||
declaration == other.declaration &&
|
declaration == other.declaration &&
|
||||||
definition_spelling == other.definition_spelling &&
|
definition_spelling == other.definition_spelling &&
|
||||||
definition_extent == other.definition_extent &&
|
definition_extent == other.definition_extent &&
|
||||||
|
@ -22,10 +22,11 @@ optional<Matcher> Matcher::Create(const std::string& search) {
|
|||||||
Matcher m;
|
Matcher m;
|
||||||
m.regex_string = search;
|
m.regex_string = search;
|
||||||
m.regex = std::regex(
|
m.regex = std::regex(
|
||||||
search, std::regex_constants::ECMAScript | std::regex_constants::icase |
|
search,
|
||||||
std::regex_constants::optimize
|
std::regex_constants::ECMAScript | std::regex_constants::icase |
|
||||||
|
std::regex_constants::optimize
|
||||||
// std::regex_constants::nosubs
|
// std::regex_constants::nosubs
|
||||||
);
|
);
|
||||||
return m;
|
return m;
|
||||||
} catch (std::exception e) {
|
} catch (std::exception e) {
|
||||||
Out_ShowLogMessage out;
|
Out_ShowLogMessage out;
|
||||||
|
@ -75,9 +75,9 @@ std::vector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(
|
|||||||
if (!root_func.def)
|
if (!root_func.def)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto format_location =
|
auto format_location = [&](
|
||||||
[&](const lsLocation& location,
|
const lsLocation& location,
|
||||||
optional<QueryTypeId> declaring_type) -> std::string {
|
optional<QueryTypeId> declaring_type) -> std::string {
|
||||||
std::string base;
|
std::string base;
|
||||||
|
|
||||||
if (declaring_type) {
|
if (declaring_type) {
|
||||||
|
@ -113,10 +113,10 @@ BuildParentInheritanceHierarchyForFunc(QueryDatabase* db,
|
|||||||
Out_CqueryTypeHierarchyTree::TypeEntry parent_entry;
|
Out_CqueryTypeHierarchyTree::TypeEntry parent_entry;
|
||||||
parent_entry.name = parent_func.def->detailed_name;
|
parent_entry.name = parent_func.def->detailed_name;
|
||||||
if (parent_func.def->definition_spelling)
|
if (parent_func.def->definition_spelling)
|
||||||
parent_entry.location =
|
parent_entry.location = GetLsLocation(
|
||||||
GetLsLocation(db, working_files, *parent_func.def->definition_spelling);
|
db, working_files, *parent_func.def->definition_spelling);
|
||||||
parent_entry.children = BuildParentInheritanceHierarchyForFunc(
|
parent_entry.children =
|
||||||
db, working_files, parent_id);
|
BuildParentInheritanceHierarchyForFunc(db, working_files, parent_id);
|
||||||
|
|
||||||
entries.push_back(parent_entry);
|
entries.push_back(parent_entry);
|
||||||
}
|
}
|
||||||
|
@ -165,8 +165,8 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
|
|||||||
// If the user has not specified how many indexers to run, try to
|
// If the user has not specified how many indexers to run, try to
|
||||||
// guess an appropriate value. Default to 80% utilization.
|
// guess an appropriate value. Default to 80% utilization.
|
||||||
const float kDefaultTargetUtilization = 0.8f;
|
const float kDefaultTargetUtilization = 0.8f;
|
||||||
config->indexerCount = (int)(
|
config->indexerCount = (int)(std::thread::hardware_concurrency() *
|
||||||
std::thread::hardware_concurrency() * kDefaultTargetUtilization);
|
kDefaultTargetUtilization);
|
||||||
if (config->indexerCount <= 0)
|
if (config->indexerCount <= 0)
|
||||||
config->indexerCount = 1;
|
config->indexerCount = 1;
|
||||||
}
|
}
|
||||||
|
@ -202,13 +202,14 @@ struct TextDocumentCodeLensHandler
|
|||||||
|
|
||||||
// "Base"
|
// "Base"
|
||||||
if (func.def->base.size() == 1) {
|
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) {
|
if (base_loc) {
|
||||||
optional<lsLocation> ls_base =
|
optional<lsLocation> ls_base =
|
||||||
GetLsLocation(db, working_files, *base_loc);
|
GetLsLocation(db, working_files, *base_loc);
|
||||||
if (ls_base) {
|
if (ls_base) {
|
||||||
optional<lsRange> range =
|
optional<lsRange> range =
|
||||||
GetLsRange(common.working_file, ref.loc.range);
|
GetLsRange(common.working_file, ref.loc.range);
|
||||||
if (range) {
|
if (range) {
|
||||||
TCodeLens code_lens;
|
TCodeLens code_lens;
|
||||||
code_lens.range = *range;
|
code_lens.range = *range;
|
||||||
@ -223,10 +224,9 @@ struct TextDocumentCodeLensHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
AddCodeLens("base", "base", &common,
|
AddCodeLens("base", "base", &common, ref.loc.OffsetStartColumn(1),
|
||||||
ref.loc.OffsetStartColumn(1),
|
ToQueryLocation(db, func.def->base), nullopt,
|
||||||
ToQueryLocation(db, func.def->base), nullopt,
|
false /*force_display*/);
|
||||||
false /*force_display*/);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -194,16 +194,14 @@ struct TextDocumentCompletionHandler : MessageHandler {
|
|||||||
!global_code_complete_cache->cached_results_.empty();
|
!global_code_complete_cache->cached_results_.empty();
|
||||||
});
|
});
|
||||||
if (is_cache_match) {
|
if (is_cache_match) {
|
||||||
ClangCompleteManager::OnComplete freshen_global =
|
ClangCompleteManager::OnComplete freshen_global = [this](
|
||||||
[this](std::vector<lsCompletionItem> results,
|
std::vector<lsCompletionItem> results, bool is_cached_result) {
|
||||||
bool is_cached_result) {
|
assert(!is_cached_result);
|
||||||
assert(!is_cached_result);
|
|
||||||
|
|
||||||
// note: path is updated in the normal completion handler.
|
// note: path is updated in the normal completion handler.
|
||||||
global_code_complete_cache->WithLock([&]() {
|
global_code_complete_cache->WithLock(
|
||||||
global_code_complete_cache->cached_results_ = results;
|
[&]() { global_code_complete_cache->cached_results_ = results; });
|
||||||
});
|
};
|
||||||
};
|
|
||||||
|
|
||||||
global_code_complete_cache->WithLock([&]() {
|
global_code_complete_cache->WithLock([&]() {
|
||||||
callback(global_code_complete_cache->cached_results_,
|
callback(global_code_complete_cache->cached_results_,
|
||||||
|
@ -24,9 +24,8 @@ struct Out_TextDocumentDefinition
|
|||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Out_TextDocumentDefinition, jsonrpc, id, result);
|
MAKE_REFLECT_STRUCT(Out_TextDocumentDefinition, jsonrpc, id, result);
|
||||||
|
|
||||||
std::vector<QueryLocation> GetGotoDefinitionTargets(
|
std::vector<QueryLocation> GetGotoDefinitionTargets(QueryDatabase* db,
|
||||||
QueryDatabase* db,
|
const SymbolIdx& symbol) {
|
||||||
const SymbolIdx& symbol) {
|
|
||||||
switch (symbol.kind) {
|
switch (symbol.kind) {
|
||||||
// Returns GetDeclarationsOfSymbolForGotoDefinition and
|
// Returns GetDeclarationsOfSymbolForGotoDefinition and
|
||||||
// variable type definition.
|
// variable type definition.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "query_utils.h"
|
#include "query_utils.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string GetHoverForSymbol(QueryDatabase* db, const SymbolIdx& symbol) {
|
std::string GetHoverForSymbol(QueryDatabase* db, const SymbolIdx& symbol) {
|
||||||
switch (symbol.kind) {
|
switch (symbol.kind) {
|
||||||
case SymbolKind::Type: {
|
case SymbolKind::Type: {
|
||||||
@ -60,7 +60,7 @@ struct Out_TextDocumentHover : public lsOutMessage<Out_TextDocumentHover> {
|
|||||||
optional<Result> result;
|
optional<Result> result;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Out_TextDocumentHover::Result, contents, range);
|
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_START();
|
||||||
REFLECT_MEMBER(jsonrpc);
|
REFLECT_MEMBER(jsonrpc);
|
||||||
REFLECT_MEMBER(id);
|
REFLECT_MEMBER(id);
|
||||||
|
@ -11,7 +11,8 @@ void InsertSymbolIntoResult(QueryDatabase* db,
|
|||||||
WorkingFiles* working_files,
|
WorkingFiles* working_files,
|
||||||
SymbolIdx symbol,
|
SymbolIdx symbol,
|
||||||
std::vector<lsSymbolInformation>* result) {
|
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)
|
if (!info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -33,11 +33,11 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
# include <sys/param.h> // MAXPATHLEN
|
#include <sys/param.h> // MAXPATHLEN
|
||||||
# include <sys/sysctl.h> // sysctl
|
#include <sys/sysctl.h> // sysctl
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
# include <malloc.h>
|
#include <malloc.h>
|
||||||
# include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -211,22 +211,23 @@ std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
|
|||||||
void PlatformInit() {}
|
void PlatformInit() {}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
extern "C" int _NSGetExecutablePath(char* buf,uint32_t* bufsize);
|
extern "C" int _NSGetExecutablePath(char* buf, uint32_t* bufsize);
|
||||||
#endif
|
#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() {
|
std::string GetExecutablePath() {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
_NSGetExecutablePath(nullptr, &size);
|
_NSGetExecutablePath(nullptr, &size);
|
||||||
char *buffer = new char[size];
|
char* buffer = new char[size];
|
||||||
_NSGetExecutablePath(buffer, &size);
|
_NSGetExecutablePath(buffer, &size);
|
||||||
std::string result(buffer);
|
std::string result(buffer);
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
return result;
|
return result;
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
static const int name[] = {
|
static const int name[] = {
|
||||||
CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1,
|
CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1,
|
||||||
};
|
};
|
||||||
char path[MAXPATHLEN];
|
char path[MAXPATHLEN];
|
||||||
size_t len = sizeof(path);
|
size_t len = sizeof(path);
|
||||||
|
@ -127,7 +127,8 @@ void PlatformInit() {
|
|||||||
_setmode(_fileno(stdin), O_BINARY);
|
_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() {
|
std::string GetExecutablePath() {
|
||||||
char result[MAX_PATH] = {0};
|
char result[MAX_PATH] = {0};
|
||||||
GetModuleFileName(NULL, result, MAX_PATH);
|
GetModuleFileName(NULL, result, MAX_PATH);
|
||||||
@ -233,6 +234,7 @@ std::vector<std::string> GetPlatformClangArguments() {
|
|||||||
// $ clang++ -E -x c++ - -v
|
// $ clang++ -E -x c++ - -v
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
return {
|
return {
|
||||||
"-isystem","C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
|
"-isystem","C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
|
||||||
"-isystem","C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
|
"-isystem","C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
|
||||||
@ -244,6 +246,7 @@ std::vector<std::string> GetPlatformClangArguments() {
|
|||||||
"-isystem","C:/Program Files/LLVM/lib/clang/4.0.0/include",
|
"-isystem","C:/Program Files/LLVM/lib/clang/4.0.0/include",
|
||||||
"-fms-extensions", "-fms-compatibility", "-fms-compatibility-version=18", "-fdelayed-template-parsing"
|
"-fms-extensions", "-fms-compatibility", "-fms-compatibility-version=18", "-fdelayed-template-parsing"
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeUnusedMemory() {}
|
void FreeUnusedMemory() {}
|
||||||
|
@ -52,15 +52,10 @@ static std::vector<std::string> kBlacklistMulti = {
|
|||||||
|
|
||||||
// Blacklisted flags which are always removed from the command line.
|
// Blacklisted flags which are always removed from the command line.
|
||||||
static std::vector<std::string> kBlacklist = {
|
static std::vector<std::string> kBlacklist = {
|
||||||
"-c",
|
"-c", "-MP", "-MD", "-MMD", "--fcolor-diagnostics",
|
||||||
"-MP",
|
|
||||||
"-MD",
|
|
||||||
"-MMD",
|
|
||||||
"--fcolor-diagnostics",
|
|
||||||
|
|
||||||
// This strips path-like args but is a bit hacky.
|
// This strips path-like args but is a bit hacky.
|
||||||
"/",
|
"/", "..",
|
||||||
"..",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Arguments which are followed by a potentially relative path. We need to make
|
// 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++")
|
else if (*source_file_type == "c++")
|
||||||
result.args.push_back("-std=c++11");
|
result.args.push_back("-std=c++11");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add -resource-dir so clang can correctly resolve system includes like
|
// Add -resource-dir so clang can correctly resolve system includes like
|
||||||
@ -486,19 +480,21 @@ TEST_SUITE("Project") {
|
|||||||
TEST_CASE("strip meta-compiler invocations") {
|
TEST_CASE("strip meta-compiler invocations") {
|
||||||
CheckFlags(
|
CheckFlags(
|
||||||
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
|
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
|
||||||
/* expected */ {"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11",
|
/* expected */
|
||||||
"-resource-dir=/w/resource_dir/",
|
{"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11",
|
||||||
"-Wno-unknown-warning-option"});
|
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"});
|
||||||
|
|
||||||
CheckFlags(/* raw */ {"goma", "clang"},
|
CheckFlags(
|
||||||
/* expected */ {"clang", "-xc++", "-std=c++11",
|
/* raw */ {"goma", "clang"},
|
||||||
"-resource-dir=/w/resource_dir/",
|
/* expected */
|
||||||
"-Wno-unknown-warning-option"});
|
{"clang", "-xc++", "-std=c++11", "-resource-dir=/w/resource_dir/",
|
||||||
|
"-Wno-unknown-warning-option"});
|
||||||
|
|
||||||
CheckFlags(/* raw */ {"goma", "clang", "--foo"},
|
CheckFlags(
|
||||||
/* expected */ {"clang", "--foo", "-xc++", "-std=c++11",
|
/* raw */ {"goma", "clang", "--foo"},
|
||||||
"-resource-dir=/w/resource_dir/",
|
/* expected */
|
||||||
"-Wno-unknown-warning-option"});
|
{"clang", "--foo", "-xc++", "-std=c++11",
|
||||||
|
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"});
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Fix this test.
|
// FIXME: Fix this test.
|
||||||
@ -512,11 +508,12 @@ TEST_SUITE("Project") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Implied binary") {
|
TEST_CASE("Implied binary") {
|
||||||
CheckFlags("/home/user", "/home/user/foo/bar.cc",
|
CheckFlags(
|
||||||
|
"/home/user", "/home/user/foo/bar.cc",
|
||||||
/* raw */ {"-DDONT_IGNORE_ME"},
|
/* raw */ {"-DDONT_IGNORE_ME"},
|
||||||
/* expected */ {"clang++", "-DDONT_IGNORE_ME", "-xc++", "-std=c++11",
|
/* expected */
|
||||||
"-resource-dir=/w/resource_dir/",
|
{"clang++", "-DDONT_IGNORE_ME", "-xc++", "-std=c++11",
|
||||||
"-Wno-unknown-warning-option"});
|
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks flag parsing for a random chromium file in comparison to what
|
// Checks flag parsing for a random chromium file in comparison to what
|
||||||
|
@ -51,7 +51,8 @@ struct QueryLocation {
|
|||||||
MAKE_REFLECT_STRUCT(QueryLocation, path, range);
|
MAKE_REFLECT_STRUCT(QueryLocation, path, range);
|
||||||
MAKE_HASHABLE(QueryLocation, t.path, t.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 };
|
enum class SymbolKind : int { Invalid, File, Type, Func, Var };
|
||||||
MAKE_REFLECT_TYPE_PROXY(SymbolKind, int);
|
MAKE_REFLECT_TYPE_PROXY(SymbolKind, int);
|
||||||
|
|
||||||
|
@ -425,7 +425,8 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
|||||||
return nullopt;
|
return nullopt;
|
||||||
|
|
||||||
lsSymbolInformation info;
|
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)
|
if (type.def->detailed_name != type.def->short_name)
|
||||||
info.containerName = type.def->detailed_name;
|
info.containerName = type.def->detailed_name;
|
||||||
info.kind = lsSymbolKind::Class;
|
info.kind = lsSymbolKind::Class;
|
||||||
@ -437,7 +438,8 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
|||||||
return nullopt;
|
return nullopt;
|
||||||
|
|
||||||
lsSymbolInformation info;
|
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.containerName = func.def->detailed_name;
|
||||||
info.kind = lsSymbolKind::Function;
|
info.kind = lsSymbolKind::Function;
|
||||||
|
|
||||||
@ -537,23 +539,23 @@ std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
|
|||||||
// important for macros which generate code so that we can resolving the
|
// important for macros which generate code so that we can resolving the
|
||||||
// macro argument takes priority over the entire macro body.
|
// macro argument takes priority over the entire macro body.
|
||||||
//
|
//
|
||||||
// Order SymbolKind::Var before SymbolKind::Type. Macro calls are treated as Var
|
// Order SymbolKind::Var before SymbolKind::Type. Macro calls are treated as
|
||||||
// currently. If a macro expands to tokens led by a SymbolKind::Type, the
|
// 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
|
// macro and the Type have the same range. We want to find the macro
|
||||||
// definition instead of the Type definition.
|
// definition instead of the Type definition.
|
||||||
//
|
//
|
||||||
// Then order functions before other types, which makes goto definition work
|
// Then order functions before other types, which makes goto definition work
|
||||||
// better on constructors.
|
// better on constructors.
|
||||||
std::sort(symbols.begin(), symbols.end(),
|
std::sort(symbols.begin(), symbols.end(), [](const SymbolRef& a,
|
||||||
[](const SymbolRef& a, const SymbolRef& b) {
|
const SymbolRef& b) {
|
||||||
int a_size = ComputeRangeSize(a.loc.range);
|
int a_size = ComputeRangeSize(a.loc.range);
|
||||||
int b_size = ComputeRangeSize(b.loc.range);
|
int b_size = ComputeRangeSize(b.loc.range);
|
||||||
|
|
||||||
if (a_size != b_size)
|
if (a_size != b_size)
|
||||||
return a_size < b_size;
|
return a_size < b_size;
|
||||||
// operator> orders Var/Func in front of orders.
|
// operator> orders Var/Func in front of orders.
|
||||||
return static_cast<int>(a.idx.kind) > static_cast<int>(b.idx.kind);
|
return static_cast<int>(a.idx.kind) > static_cast<int>(b.idx.kind);
|
||||||
});
|
});
|
||||||
|
|
||||||
return symbols;
|
return symbols;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user