Skip to content

Commit 99f0b40

Browse files
committed
Index symlinks by replacing tryGetRealName with getName+normalization
Fix #639
1 parent 5e73349 commit 99f0b40

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/clang_tu.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
#include <llvm/Support/Path.h>
1818

1919
using namespace clang;
20+
using namespace llvm;
2021

2122
namespace ccls {
2223
std::string pathFromFileEntry(const FileEntry &file) {
23-
StringRef name = file.tryGetRealPathName();
24-
if (name.empty())
25-
name = file.getName();
26-
std::string ret = normalizePath(name);
24+
SmallString<128> path(file.getName());
25+
sys::path::remove_dots(path, /*remove_dot_dot=*/true);
26+
std::string ret(path.str());
2727
// Resolve symlinks outside of workspace folders, e.g. /usr/include/c++/7.3.0
2828
return normalizeFolder(ret) ? ret : realPath(ret);
2929
}

src/messages/initialize.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,16 @@ void do_initialize(MessageHandler *m, InitializeParam &param,
348348
std::string path = wf.uri.getPath();
349349
ensureEndsInSlash(path);
350350
std::string real = realPath(path) + '/';
351-
workspaceFolders.emplace_back(path, path == real ? "" : real);
351+
workspaceFolders.emplace_back(path, real);
352352
}
353353
if (workspaceFolders.empty()) {
354354
std::string real = realPath(project_path) + '/';
355-
workspaceFolders.emplace_back(project_path,
356-
project_path == real ? "" : real);
355+
workspaceFolders.emplace_back(project_path, real);
357356
}
358357
std::sort(workspaceFolders.begin(), workspaceFolders.end(),
359358
[](auto &l, auto &r) { return l.first.size() > r.first.size(); });
360359
for (auto &[folder, real] : workspaceFolders)
361-
if (real.empty())
360+
if (real == folder)
362361
LOG_S(INFO) << "workspace folder: " << folder;
363362
else
364363
LOG_S(INFO) << "workspace folder: " << folder << " -> " << real;

src/utils.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ std::string realPath(const std::string &path) {
139139

140140
bool normalizeFolder(std::string &path) {
141141
for (auto &[root, real] : g_config->workspaceFolders)
142-
if (real.size() && llvm::StringRef(path).startswith(real)) {
142+
if (StringRef(path).startswith(real)) {
143143
path = root + path.substr(real.size());
144144
return true;
145145
}

0 commit comments

Comments
 (0)