From 5238c50027e45c37b2f830094a61b495ab9aecbe Mon Sep 17 00:00:00 2001 From: Walter Erquinigo Date: Thu, 14 Dec 2017 21:18:43 -0800 Subject: [PATCH] objc --- src/clang_complete.cc | 11 +++++++++++ src/command_line.cc | 2 +- src/indexer.cc | 2 -- src/project.cc | 37 ++++++++++++++++++++++--------------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 47757581..5f05c9aa 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -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; diff --git a/src/command_line.cc b/src/command_line.cc index 4f87e93a..8c8d03cc 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -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 diff --git a/src/indexer.cc b/src/indexer.cc index c5c1c08b..0f90c737 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -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); diff --git a/src/project.cc b/src/project.cc index 00518ddf..627b6c54 100644 --- a/src/project.cc +++ b/src/project.cc @@ -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 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,17 +189,17 @@ 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 (!AnyStartsWith(result.args, "-std=")) { - if (IsCFile(entry.file)) - result.args.push_back("-std=c11"); - else - result.args.push_back("-std=c++11"); + 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 (*source_file_type == "c") + result.args.push_back("-std=c11"); + else if (*source_file_type == "c++") + result.args.push_back("-std=c++11"); + } + } // Add -resource-dir so clang can correctly resolve system includes like @@ -227,8 +235,7 @@ std::vector LoadFromDirectoryListing(ProjectConfig* config) { std::vector 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;