fix when workspace has soft link; eg: /home/Abbyyan->/data/home/Abbyan and open with /home/Abbyyan

This commit is contained in:
Abbyyan 2020-07-08 14:45:03 +08:00
parent 99f0b402a7
commit ace782f2fa
2 changed files with 12 additions and 1 deletions

View File

@ -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<const char *> 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<driver::BindArchAction>(a))
a = *a->input_begin();

View File

@ -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,