From 99f0b402a7584f92de12f0af164ad7e0c772fcd2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 5 Jul 2020 15:12:03 -0700 Subject: [PATCH] Index symlinks by replacing tryGetRealName with getName+normalization Fix #639 --- src/clang_tu.cc | 8 ++++---- src/messages/initialize.cc | 7 +++---- src/utils.cc | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 8e2ff3fc8..0763279d7 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -17,13 +17,13 @@ #include using namespace clang; +using namespace llvm; namespace ccls { std::string pathFromFileEntry(const FileEntry &file) { - StringRef name = file.tryGetRealPathName(); - if (name.empty()) - name = file.getName(); - std::string ret = normalizePath(name); + SmallString<128> path(file.getName()); + sys::path::remove_dots(path, /*remove_dot_dot=*/true); + std::string ret(path.str()); // Resolve symlinks outside of workspace folders, e.g. /usr/include/c++/7.3.0 return normalizeFolder(ret) ? ret : realPath(ret); } diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 9b9e2bb5a..1601db704 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -348,17 +348,16 @@ void do_initialize(MessageHandler *m, InitializeParam ¶m, std::string path = wf.uri.getPath(); ensureEndsInSlash(path); std::string real = realPath(path) + '/'; - workspaceFolders.emplace_back(path, path == real ? "" : real); + workspaceFolders.emplace_back(path, real); } if (workspaceFolders.empty()) { std::string real = realPath(project_path) + '/'; - workspaceFolders.emplace_back(project_path, - project_path == real ? "" : real); + workspaceFolders.emplace_back(project_path, real); } std::sort(workspaceFolders.begin(), workspaceFolders.end(), [](auto &l, auto &r) { return l.first.size() > r.first.size(); }); for (auto &[folder, real] : workspaceFolders) - if (real.empty()) + if (real == folder) LOG_S(INFO) << "workspace folder: " << folder; else LOG_S(INFO) << "workspace folder: " << folder << " -> " << real; diff --git a/src/utils.cc b/src/utils.cc index 207568be9..04f17b1fa 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -139,7 +139,7 @@ std::string realPath(const std::string &path) { bool normalizeFolder(std::string &path) { for (auto &[root, real] : g_config->workspaceFolders) - if (real.size() && llvm::StringRef(path).startswith(real)) { + if (StringRef(path).startswith(real)) { path = root + path.substr(real.size()); return true; }