Skip to content

Commit

Permalink
Index symlinks by replacing tryGetRealName with getName+normalization
Browse files Browse the repository at this point in the history
Fix #639
  • Loading branch information
MaskRay committed Jul 5, 2020
1 parent 5e73349 commit 99f0b40
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/clang_tu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include <llvm/Support/Path.h>

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);

This comment has been minimized.

Copy link
@Abbyyan

Abbyyan Jul 13, 2020

while file.getName() = /../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/iostream, sys::path::remove_dots will be /include/c++/4.8.5/iostream. While in centos , it will be
image

This comment has been minimized.

Copy link
@MaskRay

MaskRay Jul 19, 2020

Author Owner

Thanks. I seem to recall this before. Is /../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/iostream relative to /usr/?

This comment has been minimized.

Copy link
@Abbyyan

Abbyyan Jul 20, 2020

/../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/iostream

image

It doesn't relative to /usr.
image

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);
}
Expand Down
7 changes: 3 additions & 4 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,16 @@ void do_initialize(MessageHandler *m, InitializeParam &param,
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;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 99f0b40

Please sign in to comment.