From 3fbfb99e1b95776c78dcd99b7a7a398d7c4e4add Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 7 Apr 2018 10:43:56 -0700 Subject: [PATCH] Use clang_File_tryGetRealPathName --- README.md | 2 +- ci/before_deploy.sh | 8 ++++---- src/clang_utils.cc | 9 +++++++-- src/command_line.cc | 4 ++-- src/project.cc | 4 ++-- src/utils.cc | 3 ++- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5d9737d2..d6495551 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ a C/C++/Objective-C language server. * code completion (with both signature help and snippets) * finding [definition](src/messages/text_document_definition.cc)/[references](src/messages/text_document_references.cc) - * [call (caller/callee) hierarchy](src/messages/cquery_call_hierarchy.cc), [inheritance (base/derived) hierarchy](src/messages/cquery_inheritance_hierarchy.cc), [member hierarchy](src/messages/cquery_member_hierarchy.cc) + * [call (caller/callee) hierarchy](src/messages/ccls_call_hierarchy.cc), [inheritance (base/derived) hierarchy](src/messages/ccls_inheritance_hierarchy.cc), [member hierarchy](src/messages/ccls_member_hierarchy.cc) * [symbol rename](src/messages/text_document_rename.cc) * [document symbols](src/messages/text_document_document_symbol.cc) and approximate search of [workspace symbol](src/messages/workspace_symbol.cc) * [hover information](src/messages/text_document_hover.cc) diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh index 25fa14e0..e954d7f5 100755 --- a/ci/before_deploy.sh +++ b/ci/before_deploy.sh @@ -7,15 +7,15 @@ case $(uname -s) in Darwin) libclang=(lib/clang+llvm-*/lib/libclang.dylib) strip_option="-x" - name=cquery-$version-x86_64-apple-darwin ;; + name=ccls-$version-x86_64-apple-darwin ;; FreeBSD) libclang=(lib/clang+llvm-*/lib/libclang.so.?) strip_option="-s" - name=cquery-$version-x86_64-unknown-freebsd10 ;; + name=ccls-$version-x86_64-unknown-freebsd10 ;; Linux) libclang=(lib/clang+llvm-*/lib/libclang.so.?) strip_option="-s" - name=cquery-$version-x86_64-unknown-linux-gnu ;; + name=ccls-$version-x86_64-unknown-linux-gnu ;; *) echo Unsupported >&2 exit 1 ;; @@ -26,7 +26,7 @@ mkdir "$pkg/$name" rsync -rtLR bin "./${libclang[-1]}" ./lib/clang+llvm-*/lib/clang/*/include "$pkg/$name" cd "$pkg" -strip "$strip_option" "$name/bin/cquery" "$name/${libclang[-1]}" +strip "$strip_option" "$name/bin/ccls" "$name/${libclang[-1]}" case $(uname -s) in Darwin) # https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/tar.1.html diff --git a/src/clang_utils.cc b/src/clang_utils.cc index 4a62db7d..2a79b847 100644 --- a/src/clang_utils.cc +++ b/src/clang_utils.cc @@ -106,8 +106,13 @@ std::optional BuildAndDisposeDiagnostic(CXDiagnostic diagnostic, } std::string FileName(CXFile file) { - CXString cx_name = clang_getFileName(file); - std::string ret = NormalizePath(ToString(cx_name)); + std::string ret; + // clang > 6 +#if CINDEX_VERSION >= 48 + ret = ToString(clang_File_tryGetRealPathName(file)); +#endif + if (ret.empty()) + ret = ToString(clang_getFileName(file)); // Resolve /usr/include/c++/7.3.0 symlink. if (!StartsWith(ret, g_config->projectRoot)) ret = fs::canonical(ret); diff --git a/src/command_line.cc b/src/command_line.cc index 3604aca3..2cbc311e 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -77,7 +77,7 @@ bool ShouldDisplayMethodTiming(MethodType type) { void PrintHelp() { std::cout - << R"help(ccls is a low-latency C/C++/Objective-C language server. + << R"help(ccls is a C/C++/Objective-C language server. Mode: --test-unit Run unit tests. @@ -91,7 +91,7 @@ Mode: Other command line options: --init Override client provided initialization options - https://github.com/cquery-project/cquery/wiki/Initialization-options + https://github.com/MaskRay/ccls/wiki/Initialization-options --log-file Logging file for diagnostics --log-file-append Like --log-file, but appending --log-all-to-stderr Write all log messages to STDERR. diff --git a/src/project.cc b/src/project.cc index 9370c3ac..74790c75 100644 --- a/src/project.cc +++ b/src/project.cc @@ -80,8 +80,8 @@ std::vector kNormalizePathArgs = {"--sysroot="}; // Arguments whose path arguments should be injected into include dir lookup // for #include completion. -std::vector kQuoteIncludeArgs = {"-iquote"}; -std::vector kAngleIncludeArgs = {"-I", "/I", "-isystem"}; +std::vector kQuoteIncludeArgs = {"-iquote", "-I", "/I"}; +std::vector kAngleIncludeArgs = {"-isystem", "-I", "/I"}; bool ShouldAddToQuoteIncludes(const std::string& arg) { return StartsWithAny(arg, kQuoteIncludeArgs); diff --git a/src/utils.cc b/src/utils.cc index 593cf0a8..b993c8ef 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -248,7 +249,7 @@ std::string TextReplacer::Apply(const std::string& content) { void WriteToFile(const std::string& filename, const std::string& content) { FILE* f = fopen(filename.c_str(), "wb"); if (!f || fwrite(content.c_str(), content.size(), 1, f) != 1) { - LOG_S(ERROR) << "Cannot write to " << filename; + LOG_S(ERROR) << "Failed to write to " << filename << ' ' << strerror(errno); return; } fclose(f);