mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +00:00
Adapt llvm/llvm-project#74910: FileEntry::getName
Based on a patch by @zsrkmyn
This commit is contained in:
parent
f36ecb0c0e
commit
f8d2778b65
@ -23,13 +23,21 @@
|
||||
using namespace clang;
|
||||
|
||||
namespace ccls {
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
std::string pathFromFileEntry(const FileEntry &file) {
|
||||
#else
|
||||
std::string pathFromFileEntry(FileEntryRef file) {
|
||||
#endif
|
||||
std::string ret;
|
||||
if (file.getName().startswith("/../")) {
|
||||
// Resolve symlinks outside of working folders. This handles leading path
|
||||
// components, e.g. (/lib -> /usr/lib) in
|
||||
// /../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/utility
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
ret = file.tryGetRealPathName();
|
||||
#else
|
||||
ret = file.getFileEntry().tryGetRealPathName();
|
||||
#endif
|
||||
} else {
|
||||
// If getName() refers to a file within a workspace folder, we prefer it
|
||||
// (which may be a symlink).
|
||||
|
@ -22,7 +22,11 @@ namespace vfs = clang::vfs;
|
||||
#endif
|
||||
|
||||
namespace ccls {
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
std::string pathFromFileEntry(const clang::FileEntry &file);
|
||||
#else
|
||||
std::string pathFromFileEntry(clang::FileEntryRef file);
|
||||
#endif
|
||||
|
||||
bool isInsideMainFile(const clang::SourceManager &sm, clang::SourceLocation sl);
|
||||
|
||||
|
@ -68,7 +68,11 @@ struct IndexParam {
|
||||
// generating an index for it):
|
||||
auto [it, inserted] = uid2file.try_emplace(fid);
|
||||
if (inserted) {
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
const FileEntry *fe = ctx->getSourceManager().getFileEntryForID(fid);
|
||||
#else
|
||||
OptionalFileEntryRef fe = ctx->getSourceManager().getFileEntryRefForID(fid);
|
||||
#endif
|
||||
if (!fe)
|
||||
return;
|
||||
std::string path = pathFromFileEntry(*fe);
|
||||
@ -94,9 +98,14 @@ struct IndexParam {
|
||||
|
||||
bool useMultiVersion(FileID fid) {
|
||||
auto it = uid2multi.try_emplace(fid);
|
||||
if (it.second)
|
||||
if (it.second) {
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
if (const FileEntry *fe = ctx->getSourceManager().getFileEntryForID(fid))
|
||||
#else
|
||||
if (OptionalFileEntryRef fe = ctx->getSourceManager().getFileEntryRefForID(fid))
|
||||
#endif
|
||||
it.first->second = multiVersionMatcher->matches(pathFromFileEntry(*fe));
|
||||
}
|
||||
return it.first->second;
|
||||
}
|
||||
};
|
||||
@ -636,7 +645,11 @@ public:
|
||||
static int getFileLID(IndexFile *db, SourceManager &sm, FileID fid) {
|
||||
auto [it, inserted] = db->uid2lid_and_path.try_emplace(fid);
|
||||
if (inserted) {
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
const FileEntry *fe = sm.getFileEntryForID(fid);
|
||||
#else
|
||||
OptionalFileEntryRef fe = sm.getFileEntryRefForID(fid);
|
||||
#endif
|
||||
if (!fe) {
|
||||
it->second.first = -1;
|
||||
return -1;
|
||||
@ -1124,7 +1137,11 @@ public:
|
||||
filenameRange, nullptr);
|
||||
FileID fid = sm.getFileID(filenameRange.getBegin());
|
||||
if (IndexFile *db = param.consumeFile(fid)) {
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
std::string path = pathFromFileEntry(*file);
|
||||
#else
|
||||
std::string path = pathFromFileEntry(*fileRef);
|
||||
#endif
|
||||
if (path.size())
|
||||
db->includes.push_back({spell.start.line, intern(path)});
|
||||
}
|
||||
|
@ -194,7 +194,11 @@ public:
|
||||
const FileEntry *file = fileRef ? &fileRef->getFileEntry() : nullptr;
|
||||
#endif
|
||||
if (file && seen.insert(file).second)
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
out.emplace_back(pathFromFileEntry(*file), file->getModificationTime());
|
||||
#else
|
||||
out.emplace_back(pathFromFileEntry(*fileRef), file->getModificationTime());
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@ -236,7 +240,11 @@ public:
|
||||
FileID fid = sm.getFileID(l);
|
||||
auto it = fID2concerned.try_emplace(fid.getHashValue());
|
||||
if (it.second) {
|
||||
#if LLVM_VERSION_MAJOR < 19
|
||||
const FileEntry *fe = sm.getFileEntryForID(fid);
|
||||
#else
|
||||
OptionalFileEntryRef fe = sm.getFileEntryRefForID(fid);
|
||||
#endif
|
||||
it.first->second = fe && pathFromFileEntry(*fe) == path;
|
||||
}
|
||||
return it.first->second;
|
||||
|
Loading…
Reference in New Issue
Block a user