From 757eddb147104f81d562fa0cb4fae6daa24ad5cf Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 14 Jul 2017 12:19:13 +0200 Subject: [PATCH] Further workarounds for ArchLinux's clang_getFileName that sometime returns wrong paths --- src/source_clang.cc | 51 +++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/source_clang.cc b/src/source_clang.cc index 5ad8d0e..6df009e 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -945,16 +945,8 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file } }, &client_data); - if(!client_data.found_include.empty()) { - // Workaround for bug in ArchLinux's clang_getFileName() - // TODO: remove the workaround when this is fixed - auto include_path=filesystem::get_normal_path(client_data.found_include); - boost::system::error_code ec; - if(!boost::filesystem::exists(include_path, ec)) - include_path="/usr/include"/include_path; - - return Offset(0, 0, include_path); - } + if(!client_data.found_include.empty()) + return Offset(0, 0, client_data.found_include); // Find a matching include file if no include was found previously clang_getInclusions(clang_tu->cx_tu, [](CXFile included_file, CXSourceLocation *inclusion_stack, unsigned include_len, CXClientData client_data_) { @@ -975,16 +967,8 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file } }, &client_data); - if(!client_data.found_include.empty()) { - // Workaround for bug in ArchLinux's clang_getFileName() - // TODO: remove the workaround when this is fixed - auto include_path=filesystem::get_normal_path(client_data.found_include); - boost::system::error_code ec; - if(!boost::filesystem::exists(include_path, ec)) - include_path="/usr/include"/include_path; - - return Offset(0, 0, include_path); - } + if(!client_data.found_include.empty()) + return Offset(0, 0, client_data.found_include); } } return Offset(); @@ -998,6 +982,14 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file auto offset=declaration_location(); if(!offset) Info::get().print("No declaration found"); + + // Workaround for bug in ArchLinux's clang_getFileName() + // TODO: remove the workaround when this is fixed + auto include_path=filesystem::get_normal_path(offset.file_path); + boost::system::error_code ec; + if(!boost::filesystem::exists(include_path, ec)) + offset.file_path="/usr/include"/include_path; + return offset; }; @@ -1095,6 +1087,16 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file auto offsets=implementation_locations(views); if(offsets.empty()) Info::get().print("No implementation found"); + + // Workaround for bug in ArchLinux's clang_getFileName() + // TODO: remove the workaround when this is fixed + for(auto &offset: offsets) { + auto include_path=filesystem::get_normal_path(offset.file_path); + boost::system::error_code ec; + if(!boost::filesystem::exists(include_path, ec)) + offset.file_path="/usr/include"/include_path; + } + return offsets; }; @@ -1140,6 +1142,15 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file if(offsets.empty()) Info::get().print("No declaration or implementation found"); + // Workaround for bug in ArchLinux's clang_getFileName() + // TODO: remove the workaround when this is fixed + for(auto &offset: offsets) { + auto include_path=filesystem::get_normal_path(offset.file_path); + boost::system::error_code ec; + if(!boost::filesystem::exists(include_path, ec)) + offset.file_path="/usr/include"/include_path; + } + return offsets; };