mirror of
https://github.com/MaskRay/ccls.git
synced 2025-06-06 16:24:54 +00:00
Index symlinks by replacing tryGetRealName with getName+normalization
Fix #639
This commit is contained in:
parent
5e73349390
commit
99f0b402a7
@ -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);
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user