From ace782f2fa4f5e6016f5f75ceab466bd371a4a7b Mon Sep 17 00:00:00 2001 From: Abbyyan <1678144569@qq.com> Date: Wed, 8 Jul 2020 14:45:03 +0800 Subject: [PATCH] fix when workspace has soft link; eg: /home/Abbyyan->/data/home/Abbyan and open with /home/Abbyyan --- src/clang_tu.cc | 11 ++++++++++- src/clang_tu.hh | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 0763279d..19163db1 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -20,10 +20,19 @@ using namespace clang; using namespace llvm; namespace ccls { +bool checkFolder(std::string &path) { + for (auto &[root, real] : g_config->workspaceFolders) + if (StringRef(path).startswith(root)) + return true; + return false; +} + std::string pathFromFileEntry(const FileEntry &file) { SmallString<128> path(file.getName()); sys::path::remove_dots(path, /*remove_dot_dot=*/true); std::string ret(path.str()); + if (checkFolder(ret)) + return ret; // Resolve symlinks outside of workspace folders, e.g. /usr/include/c++/7.3.0 return normalizeFolder(ret) ? ret : realPath(ret); } @@ -113,7 +122,7 @@ buildCompilerInvocation(const std::string &main, std::vector args, const driver::JobList &jobs = comp->getJobs(); bool offload_compilation = false; if (jobs.size() > 1) { - for (auto &a : comp->getActions()){ + for (auto &a : comp->getActions()) { // On MacOSX real actions may end up being wrapped in BindArchAction if (isa(a)) a = *a->input_begin(); diff --git a/src/clang_tu.hh b/src/clang_tu.hh index b3795092..2e2d1b1f 100644 --- a/src/clang_tu.hh +++ b/src/clang_tu.hh @@ -20,6 +20,8 @@ namespace vfs = clang::vfs; namespace ccls { std::string pathFromFileEntry(const clang::FileEntry &file); +bool checkFolder(std::string &path); + bool isInsideMainFile(const clang::SourceManager &sm, clang::SourceLocation sl); Range fromCharSourceRange(const clang::SourceManager &sm,