This commit is contained in:
Walter Erquinigo 2017-12-14 21:18:43 -08:00 committed by Jacob Dufault
parent ea5c89e956
commit 5238c50027
4 changed files with 34 additions and 18 deletions

View File

@ -85,6 +85,7 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
case CXCursor_ObjCInstanceMethodDecl:
case CXCursor_CXXMethod:
case CXCursor_ObjCClassMethodDecl:
return lsCompletionItemKind::Method;
case CXCursor_FunctionTemplate:
@ -101,6 +102,7 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
case CXCursor_VarDecl:
case CXCursor_ParmDecl:
case CXCursor_ObjCIvarDecl:
return lsCompletionItemKind::Variable;
case CXCursor_UnionDecl:
@ -112,6 +114,11 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
case CXCursor_TypedefDecl:
case CXCursor_TypeAliasDecl:
case CXCursor_TypeAliasTemplateDecl:
case CXCursor_ObjCCategoryDecl:
case CXCursor_ObjCProtocolDecl:
case CXCursor_ObjCPropertyDecl:
case CXCursor_ObjCImplementationDecl:
case CXCursor_ObjCCategoryImplDecl:
return lsCompletionItemKind::Class;
case CXCursor_EnumConstantDecl:
@ -120,6 +127,7 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
case CXCursor_MacroInstantiation:
case CXCursor_MacroDefinition:
case CXCursor_ObjCInterfaceDecl:
return lsCompletionItemKind::Interface;
case CXCursor_Namespace:
@ -129,6 +137,9 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
case CXCursor_MemberRef:
case CXCursor_TypeRef:
case CXCursor_ObjCSuperClassRef:
case CXCursor_ObjCProtocolRef:
case CXCursor_ObjCClassRef:
return lsCompletionItemKind::Reference;
// return lsCompletionItemKind::Property;

View File

@ -1048,7 +1048,7 @@ int main(int argc, char** argv) {
}
if (print_help) {
std::cout << R"help(cquery is a low-latency C++ language server.
std::cout << R"help(cquery is a low-latency C/C++/Objective-C language server.
Command line options:
--language-server

View File

@ -956,8 +956,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
param->ctors.NotifyConstructor(decl->cursor);
}
assert(AreEqualLocations(decl->loc, decl->cursor));
CXFile file;
clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(decl->loc),
&file, nullptr, nullptr, nullptr);

View File

@ -84,8 +84,16 @@ bool ShouldAddToAngleIncludes(const std::string& arg) {
// Returns true if we should use the C, not C++, language spec for the given
// file.
bool IsCFile(const std::string& path) {
return EndsWith(path, ".c");
optional<std::string> SourceFileType(const std::string& path) {
if (EndsWith(path, ".c"))
return std::string("c");
else if (EndsWith(path, ".cpp") || EndsWith(path, ".cc"))
return std::string("c++");
else if (EndsWith(path, ".mm"))
return std::string("objective-c++");
else if (EndsWith(path, ".m"))
return std::string("objective-c");
return nullopt;
}
Project::Entry GetCompilationEntryFromCompileCommandEntry(
@ -181,19 +189,19 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
// Clang does not have good hueristics for determining source language, we
// should explicitly specify it.
if (!AnyStartsWith(result.args, "-x")) {
if (IsCFile(entry.file))
result.args.push_back("-xc");
else
result.args.push_back("-xc++");
if (auto source_file_type = SourceFileType(entry.file)) {
if (AnyStartsWith(result.args, "-x")) {
result.args.push_back("-x" + *source_file_type);
}
if (!AnyStartsWith(result.args, "-std=")) {
if (IsCFile(entry.file))
if (*source_file_type == "c")
result.args.push_back("-std=c11");
else
else if (*source_file_type == "c++")
result.args.push_back("-std=c++11");
}
}
// Add -resource-dir so clang can correctly resolve system includes like
// <cstddef>
if (!AnyStartsWith(result.args, "-resource-dir"))
@ -227,8 +235,7 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) {
std::vector<std::string> files = GetFilesInFolder(
config->project_dir, true /*recursive*/, true /*add_folder_to_path*/);
for (const std::string& file : files) {
if (EndsWith(file, ".cc") || EndsWith(file, ".cpp") ||
EndsWith(file, ".c")) {
if (SourceFileType(file)) {
CompileCommandsEntry e;
e.file = NormalizePathWithTestOptOut(file);
e.args = args;