[PATCH] D148213: [clangd] Use FileEntryRef for canonicalizing filepaths.
This revision was automatically updated to reflect the committed changes. Closed by commit rGed365f464a0a: [clangd] Use FileEntryRef for canonicalizing filepaths. (authored by usaxena95). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148213/new/ https://reviews.llvm.org/D148213 Files: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/SourceCode.h clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/index/Background.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/indexer/IndexerMain.cpp clang-tools-extra/clangd/refactor/Tweak.cpp Index: clang-tools-extra/clangd/refactor/Tweak.cpp === --- clang-tools-extra/clangd/refactor/Tweak.cpp +++ clang-tools-extra/clangd/refactor/Tweak.cpp @@ -104,8 +104,9 @@ Tweak::Effect::fileEdit(const SourceManager , FileID FID, tooling::Replacements Replacements) { Edit Ed(SM.getBufferData(FID), std::move(Replacements)); - if (auto FilePath = getCanonicalPath(SM.getFileEntryForID(FID), SM)) -return std::make_pair(*FilePath, std::move(Ed)); + if (const auto FE = SM.getFileEntryRefForID(FID)) +if (auto FilePath = getCanonicalPath(*FE, SM)) + return std::make_pair(*FilePath, std::move(Ed)); return error("Failed to get absolute path for edited file: {0}", SM.getFileEntryRefForID(FID)->getName()); } Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp === --- clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -46,10 +46,10 @@ SymbolCollector::Options Opts; Opts.CountReferences = true; Opts.FileFilter = [&](const SourceManager , FileID FID) { - const auto *F = SM.getFileEntryForID(FID); + const auto F = SM.getFileEntryRefForID(FID); if (!F) return false; // Skip invalid files. - auto AbsPath = getCanonicalPath(F, SM); + auto AbsPath = getCanonicalPath(*F, SM); if (!AbsPath) return false; // Skip files without absolute path. std::lock_guard Lock(FilesMu); Index: clang-tools-extra/clangd/index/SymbolCollector.cpp === --- clang-tools-extra/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -205,11 +205,11 @@ // Returns a canonical URI for the file \p FE. // We attempt to make the path absolute first. - const std::string (const FileEntry *FE) { + const std::string (const FileEntryRef FE) { auto R = CacheFEToURI.try_emplace(FE); if (R.second) { auto CanonPath = getCanonicalPath(FE, SM); - R.first->second = (CanonPath ? *CanonPath : FE->getName()); + R.first->second = (CanonPath ? *CanonPath : FE.getName()); } return *R.first->second; } @@ -218,7 +218,7 @@ // If the file is in the FileManager, use that to canonicalize the path. // We attempt to make the path absolute in any case. const std::string (llvm::StringRef Path) { -if (auto File = SM.getFileManager().getFile(Path)) +if (auto File = SM.getFileManager().getFileRef(Path)) return toURI(*File); return toURIInternal(Path); } @@ -373,7 +373,7 @@ } llvm::StringRef getIncludeHeaderUncached(FileID FID) { -const FileEntry *FE = SM.getFileEntryForID(FID); +const auto FE = SM.getFileEntryRefForID(FID); if (!FE || FE->getName().empty()) return ""; llvm::StringRef Filename = FE->getName(); @@ -392,13 +392,13 @@ // Framework headers are spelled as , not // "path/FrameworkName.framework/Headers/Foo.h". auto = PP->getHeaderSearchInfo(); -if (const auto *HFI = HS.getExistingFileInfo(FE, /*WantExternal*/ false)) +if (const auto *HFI = HS.getExistingFileInfo(*FE, /*WantExternal*/ false)) if (!HFI->Framework.empty()) if (auto Spelling = -getFrameworkHeaderIncludeSpelling(FE, HFI->Framework, HS)) +getFrameworkHeaderIncludeSpelling(*FE, HFI->Framework, HS)) return *Spelling; -if (!tooling::isSelfContainedHeader(FE, PP->getSourceManager(), +if (!tooling::isSelfContainedHeader(*FE, PP->getSourceManager(), PP->getHeaderSearchInfo())) { // A .inc or .def file is often included into a real header to define // symbols (e.g. LLVM tablegen files). @@ -409,7 +409,7 @@ return ""; } // Standard case: just insert the file itself. -return toURI(FE); +return toURI(*FE); } }; @@ -417,12 +417,12 @@ std::optional SymbolCollector::getTokenLocation(SourceLocation TokLoc) { const auto = ASTCtx->getSourceManager(); - auto *FE =
[PATCH] D148213: [clangd] Use FileEntryRef for canonicalizing filepaths.
kadircet accepted this revision. kadircet added a comment. This revision is now accepted and ready to land. thanks! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148213/new/ https://reviews.llvm.org/D148213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148213: [clangd] Use FileEntryRef for canonicalizing filepaths.
usaxena95 updated this revision to Diff 513219. usaxena95 marked 6 inline comments as done. usaxena95 added a comment. Addressed comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148213/new/ https://reviews.llvm.org/D148213 Files: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/SourceCode.h clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/index/Background.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/indexer/IndexerMain.cpp clang-tools-extra/clangd/refactor/Tweak.cpp Index: clang-tools-extra/clangd/refactor/Tweak.cpp === --- clang-tools-extra/clangd/refactor/Tweak.cpp +++ clang-tools-extra/clangd/refactor/Tweak.cpp @@ -104,8 +104,9 @@ Tweak::Effect::fileEdit(const SourceManager , FileID FID, tooling::Replacements Replacements) { Edit Ed(SM.getBufferData(FID), std::move(Replacements)); - if (auto FilePath = getCanonicalPath(SM.getFileEntryForID(FID), SM)) -return std::make_pair(*FilePath, std::move(Ed)); + if (const auto FE = SM.getFileEntryRefForID(FID)) +if (auto FilePath = getCanonicalPath(*FE, SM)) + return std::make_pair(*FilePath, std::move(Ed)); return error("Failed to get absolute path for edited file: {0}", SM.getFileEntryRefForID(FID)->getName()); } Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp === --- clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -46,10 +46,10 @@ SymbolCollector::Options Opts; Opts.CountReferences = true; Opts.FileFilter = [&](const SourceManager , FileID FID) { - const auto *F = SM.getFileEntryForID(FID); + const auto F = SM.getFileEntryRefForID(FID); if (!F) return false; // Skip invalid files. - auto AbsPath = getCanonicalPath(F, SM); + auto AbsPath = getCanonicalPath(*F, SM); if (!AbsPath) return false; // Skip files without absolute path. std::lock_guard Lock(FilesMu); Index: clang-tools-extra/clangd/index/SymbolCollector.cpp === --- clang-tools-extra/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -205,11 +205,11 @@ // Returns a canonical URI for the file \p FE. // We attempt to make the path absolute first. - const std::string (const FileEntry *FE) { + const std::string (const FileEntryRef FE) { auto R = CacheFEToURI.try_emplace(FE); if (R.second) { auto CanonPath = getCanonicalPath(FE, SM); - R.first->second = (CanonPath ? *CanonPath : FE->getName()); + R.first->second = (CanonPath ? *CanonPath : FE.getName()); } return *R.first->second; } @@ -218,7 +218,7 @@ // If the file is in the FileManager, use that to canonicalize the path. // We attempt to make the path absolute in any case. const std::string (llvm::StringRef Path) { -if (auto File = SM.getFileManager().getFile(Path)) +if (auto File = SM.getFileManager().getFileRef(Path)) return toURI(*File); return toURIInternal(Path); } @@ -373,7 +373,7 @@ } llvm::StringRef getIncludeHeaderUncached(FileID FID) { -const FileEntry *FE = SM.getFileEntryForID(FID); +const auto FE = SM.getFileEntryRefForID(FID); if (!FE || FE->getName().empty()) return ""; llvm::StringRef Filename = FE->getName(); @@ -392,13 +392,13 @@ // Framework headers are spelled as , not // "path/FrameworkName.framework/Headers/Foo.h". auto = PP->getHeaderSearchInfo(); -if (const auto *HFI = HS.getExistingFileInfo(FE, /*WantExternal*/ false)) +if (const auto *HFI = HS.getExistingFileInfo(*FE, /*WantExternal*/ false)) if (!HFI->Framework.empty()) if (auto Spelling = -getFrameworkHeaderIncludeSpelling(FE, HFI->Framework, HS)) +getFrameworkHeaderIncludeSpelling(*FE, HFI->Framework, HS)) return *Spelling; -if (!tooling::isSelfContainedHeader(FE, PP->getSourceManager(), +if (!tooling::isSelfContainedHeader(*FE, PP->getSourceManager(), PP->getHeaderSearchInfo())) { // A .inc or .def file is often included into a real header to define // symbols (e.g. LLVM tablegen files). @@ -409,7 +409,7 @@ return ""; } // Standard case: just insert the file itself. -return toURI(FE); +return toURI(*FE); } }; @@ -417,12 +417,12 @@ std::optional SymbolCollector::getTokenLocation(SourceLocation TokLoc) { const auto = ASTCtx->getSourceManager(); - auto *FE = SM.getFileEntryForID(SM.getFileID(TokLoc)); + const auto FE =
[PATCH] D148213: [clangd] Use FileEntryRef for canonicalizing filepaths.
kadircet added a comment. we've got one more reference to `getCanonicalPath` in `clang-tools-extra/clangd/IncludeCleaner.cpp:320`, i guess the best way is just calling `getLastRef` on the FileEntry* Comment at: clang-tools-extra/clangd/SourceCode.cpp:518 const SourceManager ) { if (!F) return std::nullopt; we don't need this check anymore Comment at: clang-tools-extra/clangd/SourceCode.h:166 /// possible. -std::optional getCanonicalPath(const FileEntry *F, +std::optional getCanonicalPath(const FileEntryRef , const SourceManager ); just `FileEntryRef`, it's a cheap value type that provides an immutable view into underlying `FileEntry` Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:208 // We attempt to make the path absolute first. - const std::string (const FileEntry *FE) { + const std::string (const FileEntryRef ) { auto R = CacheFEToURI.try_emplace(FE); again just `FileEntryRef` Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:395 auto = PP->getHeaderSearchInfo(); -if (const auto *HFI = HS.getExistingFileInfo(FE, /*WantExternal*/ false)) +if (const auto *HFI = HS.getExistingFileInfo(>getFileEntry(), + /*WantExternal*/ false)) `FileEntryRef` should be implicitly convertable to `FileEntry*` (so just `*FE` should be enough?) Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:399 +if (auto Spelling = getFrameworkHeaderIncludeSpelling( +>getFileEntry(), HFI->Framework, HS)) return *Spelling; same as above Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:402 -if (!tooling::isSelfContainedHeader(FE, PP->getSourceManager(), +if (!tooling::isSelfContainedHeader(>getFileEntry(), +PP->getSourceManager(), same as above Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148213/new/ https://reviews.llvm.org/D148213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D148213: [clangd] Use FileEntryRef for canonicalizing filepaths.
usaxena95 updated this revision to Diff 513168. usaxena95 added a comment. Rebase Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148213/new/ https://reviews.llvm.org/D148213 Files: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/SourceCode.h clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/index/Background.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/indexer/IndexerMain.cpp clang-tools-extra/clangd/refactor/Tweak.cpp Index: clang-tools-extra/clangd/refactor/Tweak.cpp === --- clang-tools-extra/clangd/refactor/Tweak.cpp +++ clang-tools-extra/clangd/refactor/Tweak.cpp @@ -104,8 +104,9 @@ Tweak::Effect::fileEdit(const SourceManager , FileID FID, tooling::Replacements Replacements) { Edit Ed(SM.getBufferData(FID), std::move(Replacements)); - if (auto FilePath = getCanonicalPath(SM.getFileEntryForID(FID), SM)) -return std::make_pair(*FilePath, std::move(Ed)); + if (const auto FE = SM.getFileEntryRefForID(FID)) +if (auto FilePath = getCanonicalPath(*FE, SM)) + return std::make_pair(*FilePath, std::move(Ed)); return error("Failed to get absolute path for edited file: {0}", SM.getFileEntryRefForID(FID)->getName()); } Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp === --- clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -46,10 +46,10 @@ SymbolCollector::Options Opts; Opts.CountReferences = true; Opts.FileFilter = [&](const SourceManager , FileID FID) { - const auto *F = SM.getFileEntryForID(FID); + const auto F = SM.getFileEntryRefForID(FID); if (!F) return false; // Skip invalid files. - auto AbsPath = getCanonicalPath(F, SM); + auto AbsPath = getCanonicalPath(*F, SM); if (!AbsPath) return false; // Skip files without absolute path. std::lock_guard Lock(FilesMu); Index: clang-tools-extra/clangd/index/SymbolCollector.cpp === --- clang-tools-extra/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -205,11 +205,11 @@ // Returns a canonical URI for the file \p FE. // We attempt to make the path absolute first. - const std::string (const FileEntry *FE) { + const std::string (const FileEntryRef ) { auto R = CacheFEToURI.try_emplace(FE); if (R.second) { auto CanonPath = getCanonicalPath(FE, SM); - R.first->second = (CanonPath ? *CanonPath : FE->getName()); + R.first->second = (CanonPath ? *CanonPath : FE.getName()); } return *R.first->second; } @@ -218,7 +218,7 @@ // If the file is in the FileManager, use that to canonicalize the path. // We attempt to make the path absolute in any case. const std::string (llvm::StringRef Path) { -if (auto File = SM.getFileManager().getFile(Path)) +if (auto File = SM.getFileManager().getFileRef(Path)) return toURI(*File); return toURIInternal(Path); } @@ -373,7 +373,7 @@ } llvm::StringRef getIncludeHeaderUncached(FileID FID) { -const FileEntry *FE = SM.getFileEntryForID(FID); +const auto FE = SM.getFileEntryRefForID(FID); if (!FE || FE->getName().empty()) return ""; llvm::StringRef Filename = FE->getName(); @@ -392,13 +392,15 @@ // Framework headers are spelled as , not // "path/FrameworkName.framework/Headers/Foo.h". auto = PP->getHeaderSearchInfo(); -if (const auto *HFI = HS.getExistingFileInfo(FE, /*WantExternal*/ false)) +if (const auto *HFI = HS.getExistingFileInfo(>getFileEntry(), + /*WantExternal*/ false)) if (!HFI->Framework.empty()) -if (auto Spelling = -getFrameworkHeaderIncludeSpelling(FE, HFI->Framework, HS)) +if (auto Spelling = getFrameworkHeaderIncludeSpelling( +>getFileEntry(), HFI->Framework, HS)) return *Spelling; -if (!tooling::isSelfContainedHeader(FE, PP->getSourceManager(), +if (!tooling::isSelfContainedHeader(>getFileEntry(), +PP->getSourceManager(), PP->getHeaderSearchInfo())) { // A .inc or .def file is often included into a real header to define // symbols (e.g. LLVM tablegen files). @@ -409,7 +411,7 @@ return ""; } // Standard case: just insert the file itself. -return toURI(FE); +return toURI(*FE); } }; @@ -417,12 +419,12 @@ std::optional SymbolCollector::getTokenLocation(SourceLocation TokLoc) { const auto = ASTCtx->getSourceManager(); - auto *FE =
[PATCH] D148213: [clangd] Use FileEntryRef for canonicalizing filepaths.
usaxena95 updated this revision to Diff 513165. usaxena95 added a comment. More refactorings. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148213/new/ https://reviews.llvm.org/D148213 Files: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/SourceCode.h clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/index/Background.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/indexer/IndexerMain.cpp clang-tools-extra/clangd/refactor/Tweak.cpp Index: clang-tools-extra/clangd/refactor/Tweak.cpp === --- clang-tools-extra/clangd/refactor/Tweak.cpp +++ clang-tools-extra/clangd/refactor/Tweak.cpp @@ -104,8 +104,9 @@ Tweak::Effect::fileEdit(const SourceManager , FileID FID, tooling::Replacements Replacements) { Edit Ed(SM.getBufferData(FID), std::move(Replacements)); - if (auto FilePath = getCanonicalPath(SM.getFileEntryForID(FID), SM)) -return std::make_pair(*FilePath, std::move(Ed)); + if (const auto FE = SM.getFileEntryRefForID(FID)) +if (auto FilePath = getCanonicalPath(*FE, SM)) + return std::make_pair(*FilePath, std::move(Ed)); return error("Failed to get absolute path for edited file: {0}", SM.getFileEntryRefForID(FID)->getName()); } Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp === --- clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -46,10 +46,10 @@ SymbolCollector::Options Opts; Opts.CountReferences = true; Opts.FileFilter = [&](const SourceManager , FileID FID) { - const auto *F = SM.getFileEntryForID(FID); + const auto F = SM.getFileEntryRefForID(FID); if (!F) return false; // Skip invalid files. - auto AbsPath = getCanonicalPath(F, SM); + auto AbsPath = getCanonicalPath(*F, SM); if (!AbsPath) return false; // Skip files without absolute path. std::lock_guard Lock(FilesMu); Index: clang-tools-extra/clangd/index/SymbolCollector.cpp === --- clang-tools-extra/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -205,11 +205,11 @@ // Returns a canonical URI for the file \p FE. // We attempt to make the path absolute first. - const std::string (const FileEntry *FE) { + const std::string (const FileEntryRef ) { auto R = CacheFEToURI.try_emplace(FE); if (R.second) { auto CanonPath = getCanonicalPath(FE, SM); - R.first->second = (CanonPath ? *CanonPath : FE->getName()); + R.first->second = (CanonPath ? *CanonPath : FE.getName()); } return *R.first->second; } @@ -218,7 +218,7 @@ // If the file is in the FileManager, use that to canonicalize the path. // We attempt to make the path absolute in any case. const std::string (llvm::StringRef Path) { -if (auto File = SM.getFileManager().getFile(Path)) +if (auto File = SM.getFileManager().getFileRef(Path)) return toURI(*File); return toURIInternal(Path); } @@ -373,7 +373,7 @@ } llvm::StringRef getIncludeHeaderUncached(FileID FID) { -const FileEntry *FE = SM.getFileEntryForID(FID); +const auto FE = SM.getFileEntryRefForID(FID); if (!FE || FE->getName().empty()) return ""; llvm::StringRef Filename = FE->getName(); @@ -392,13 +392,15 @@ // Framework headers are spelled as , not // "path/FrameworkName.framework/Headers/Foo.h". auto = PP->getHeaderSearchInfo(); -if (const auto *HFI = HS.getExistingFileInfo(FE, /*WantExternal*/ false)) +if (const auto *HFI = HS.getExistingFileInfo(>getFileEntry(), + /*WantExternal*/ false)) if (!HFI->Framework.empty()) -if (auto Spelling = -getFrameworkHeaderIncludeSpelling(FE, HFI->Framework, HS)) +if (auto Spelling = getFrameworkHeaderIncludeSpelling( +>getFileEntry(), HFI->Framework, HS)) return *Spelling; -if (!tooling::isSelfContainedHeader(FE, PP->getSourceManager(), +if (!tooling::isSelfContainedHeader(>getFileEntry(), +PP->getSourceManager(), PP->getHeaderSearchInfo())) { // A .inc or .def file is often included into a real header to define // symbols (e.g. LLVM tablegen files). @@ -409,7 +411,7 @@ return ""; } // Standard case: just insert the file itself. -return toURI(FE); +return toURI(*FE); } }; @@ -417,12 +419,12 @@ std::optional SymbolCollector::getTokenLocation(SourceLocation TokLoc) { const auto =
[PATCH] D148213: [clangd] Use FileEntryRef for canonicalizing filepaths.
usaxena95 created this revision. Herald added subscribers: kadircet, arphaman. Herald added a project: All. usaxena95 requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D148213 Files: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/SourceCode.h clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/index/Background.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/indexer/IndexerMain.cpp clang-tools-extra/clangd/refactor/Tweak.cpp Index: clang-tools-extra/clangd/refactor/Tweak.cpp === --- clang-tools-extra/clangd/refactor/Tweak.cpp +++ clang-tools-extra/clangd/refactor/Tweak.cpp @@ -104,8 +104,9 @@ Tweak::Effect::fileEdit(const SourceManager , FileID FID, tooling::Replacements Replacements) { Edit Ed(SM.getBufferData(FID), std::move(Replacements)); - if (auto FilePath = getCanonicalPath(SM.getFileEntryForID(FID), SM)) -return std::make_pair(*FilePath, std::move(Ed)); + if (const auto FERef = SM.getFileEntryRefForID(FID)) +if (auto FilePath = getCanonicalPath(*FERef, SM)) + return std::make_pair(*FilePath, std::move(Ed)); return error("Failed to get absolute path for edited file: {0}", SM.getFileEntryRefForID(FID)->getName()); } Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp === --- clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -46,10 +46,10 @@ SymbolCollector::Options Opts; Opts.CountReferences = true; Opts.FileFilter = [&](const SourceManager , FileID FID) { - const auto *F = SM.getFileEntryForID(FID); + const auto F = SM.getFileEntryRefForID(FID); if (!F) return false; // Skip invalid files. - auto AbsPath = getCanonicalPath(F, SM); + auto AbsPath = getCanonicalPath(*F, SM); if (!AbsPath) return false; // Skip files without absolute path. std::lock_guard Lock(FilesMu); Index: clang-tools-extra/clangd/index/SymbolCollector.cpp === --- clang-tools-extra/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -205,11 +205,11 @@ // Returns a canonical URI for the file \p FE. // We attempt to make the path absolute first. - const std::string (const FileEntry *FE) { + const std::string (const FileEntryRef ) { auto R = CacheFEToURI.try_emplace(FE); if (R.second) { auto CanonPath = getCanonicalPath(FE, SM); - R.first->second = (CanonPath ? *CanonPath : FE->getName()); + R.first->second = (CanonPath ? *CanonPath : FE.getName()); } return *R.first->second; } @@ -218,7 +218,7 @@ // If the file is in the FileManager, use that to canonicalize the path. // We attempt to make the path absolute in any case. const std::string (llvm::StringRef Path) { -if (auto File = SM.getFileManager().getFile(Path)) +if (auto File = SM.getFileManager().getFileRef(Path)) return toURI(*File); return toURIInternal(Path); } @@ -373,7 +373,7 @@ } llvm::StringRef getIncludeHeaderUncached(FileID FID) { -const FileEntry *FE = SM.getFileEntryForID(FID); +const auto FE = SM.getFileEntryRefForID(FID); if (!FE || FE->getName().empty()) return ""; llvm::StringRef Filename = FE->getName(); @@ -392,13 +392,15 @@ // Framework headers are spelled as , not // "path/FrameworkName.framework/Headers/Foo.h". auto = PP->getHeaderSearchInfo(); -if (const auto *HFI = HS.getExistingFileInfo(FE, /*WantExternal*/ false)) +if (const auto *HFI = HS.getExistingFileInfo(>getFileEntry(), + /*WantExternal*/ false)) if (!HFI->Framework.empty()) -if (auto Spelling = -getFrameworkHeaderIncludeSpelling(FE, HFI->Framework, HS)) +if (auto Spelling = getFrameworkHeaderIncludeSpelling( +>getFileEntry(), HFI->Framework, HS)) return *Spelling; -if (!tooling::isSelfContainedHeader(FE, PP->getSourceManager(), +if (!tooling::isSelfContainedHeader(>getFileEntry(), +PP->getSourceManager(), PP->getHeaderSearchInfo())) { // A .inc or .def file is often included into a real header to define // symbols (e.g. LLVM tablegen files). @@ -409,7 +411,7 @@ return ""; } // Standard case: just insert the file itself. -return toURI(FE); +return toURI(*FE); } }; @@ -417,12 +419,12 @@