Author: Haojian Wu Date: 2023-06-02T12:55:21+02:00 New Revision: be8da1f6e68603fd49ee7faa7c309f44f5b1a8b2
URL: https://github.com/llvm/llvm-project/commit/be8da1f6e68603fd49ee7faa7c309f44f5b1a8b2 DIFF: https://github.com/llvm/llvm-project/commit/be8da1f6e68603fd49ee7faa7c309f44f5b1a8b2.diff LOG: [clangd] Use FileManager for getCanonicalPath, NFC get rid of the SourceManager dependency -- getCanonicalPath doesn't use other SourceManager fields. Added: Modified: 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 Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index 4c5def3063f1..bae528a105c8 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -710,7 +710,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, auto FID = SM.getFileID(Info.getLocation()); if (const auto FE = SM.getFileEntryRefForID(FID)) { D.File = FE->getName().str(); - D.AbsFile = getCanonicalPath(*FE, SM); + D.AbsFile = getCanonicalPath(*FE, SM.getFileManager()); } D.ID = Info.getID(); return D; diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp index 18be1329f1fa..a3e08bc56b31 100644 --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -336,7 +336,7 @@ std::string spellHeader(ParsedAST &AST, const FileEntry *MainFile, include_cleaner::Header Provider) { if (Provider.kind() == include_cleaner::Header::Physical) { if (auto CanonicalPath = getCanonicalPath(Provider.physical()->getLastRef(), - AST.getSourceManager())) { + AST.getSourceManager().getFileManager())) { std::string SpelledHeader = llvm::cantFail(URI::includeSpelling(URI::create(*CanonicalPath))); if (!SpelledHeader.empty()) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 831adc3d5fd8..c460ae307f11 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -514,11 +514,11 @@ std::vector<TextEdit> replacementsToEdits(llvm::StringRef Code, } std::optional<std::string> getCanonicalPath(const FileEntryRef F, - const SourceManager &SourceMgr) { + FileManager &FileMgr) { llvm::SmallString<128> FilePath = F.getName(); if (!llvm::sys::path::is_absolute(FilePath)) { if (auto EC = - SourceMgr.getFileManager().getVirtualFileSystem().makeAbsolute( + FileMgr.getVirtualFileSystem().makeAbsolute( FilePath)) { elog("Could not turn relative path '{0}' to absolute: {1}", FilePath, EC.message()); @@ -537,10 +537,10 @@ std::optional<std::string> getCanonicalPath(const FileEntryRef F, // // The file path of Symbol is "/project/src/foo.h" instead of // "/tmp/build/foo.h" - if (auto Dir = SourceMgr.getFileManager().getDirectory( + if (auto Dir = FileMgr.getDirectory( llvm::sys::path::parent_path(FilePath))) { llvm::SmallString<128> RealPath; - llvm::StringRef DirName = SourceMgr.getFileManager().getCanonicalName(*Dir); + llvm::StringRef DirName = FileMgr.getCanonicalName(*Dir); llvm::sys::path::append(RealPath, DirName, llvm::sys::path::filename(FilePath)); return RealPath.str().str(); diff --git a/clang-tools-extra/clangd/SourceCode.h b/clang-tools-extra/clangd/SourceCode.h index 8b7c028eb247..3ba6f8b80ef3 100644 --- a/clang-tools-extra/clangd/SourceCode.h +++ b/clang-tools-extra/clangd/SourceCode.h @@ -164,7 +164,7 @@ TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M, /// component that generate it, so that paths are normalized as much as /// possible. std::optional<std::string> getCanonicalPath(const FileEntryRef F, - const SourceManager &SourceMgr); + FileManager &FileMgr); /// Choose the clang-format style we should apply to a certain file. /// This will usually use FS to look for .clang-format directories. diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index 51a3ef894c54..ad4819fe4b4d 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -217,7 +217,7 @@ std::optional<Location> makeLocation(const ASTContext &AST, SourceLocation Loc, const auto F = SM.getFileEntryRefForID(SM.getFileID(Loc)); if (!F) return std::nullopt; - auto FilePath = getCanonicalPath(*F, SM); + auto FilePath = getCanonicalPath(*F, SM.getFileManager()); if (!FilePath) { log("failed to get path!"); return std::nullopt; @@ -1688,7 +1688,7 @@ declToHierarchyItem(const NamedDecl &ND, llvm::StringRef TUPath) { const auto FE = SM.getFileEntryRefForID(SM.getFileID(NameLoc)); if (!FE) return std::nullopt; - auto FilePath = getCanonicalPath(*FE, SM); + auto FilePath = getCanonicalPath(*FE, SM.getFileManager()); if (!FilePath) return std::nullopt; // Not useful without a uri. diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp index 73330b3ae6a8..c35de750435c 100644 --- a/clang-tools-extra/clangd/index/Background.cpp +++ b/clang-tools-extra/clangd/index/Background.cpp @@ -291,7 +291,7 @@ llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd) { const auto F = SM.getFileEntryRefForID(FID); if (!F) return false; // Skip invalid files. - auto AbsPath = getCanonicalPath(*F, SM); + auto AbsPath = getCanonicalPath(*F, SM.getFileManager()); if (!AbsPath) return false; // Skip files without absolute path. auto Digest = digestFile(SM, FID); diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index d1840ff34bfe..131d0a3d0391 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -208,7 +208,7 @@ class SymbolCollector::HeaderFileURICache { const std::string &toURI(const FileEntryRef FE) { auto R = CacheFEToURI.try_emplace(FE); if (R.second) { - auto CanonPath = getCanonicalPath(FE, SM); + auto CanonPath = getCanonicalPath(FE, SM.getFileManager()); R.first->second = &toURIInternal(CanonPath ? *CanonPath : FE.getName()); } return *R.first->second; diff --git a/clang-tools-extra/clangd/indexer/IndexerMain.cpp b/clang-tools-extra/clangd/indexer/IndexerMain.cpp index a66ab91c0423..2717030e9796 100644 --- a/clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ b/clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -49,7 +49,7 @@ class IndexActionFactory : public tooling::FrontendActionFactory { const auto F = SM.getFileEntryRefForID(FID); if (!F) return false; // Skip invalid files. - auto AbsPath = getCanonicalPath(*F, SM); + auto AbsPath = getCanonicalPath(*F, SM.getFileManager()); if (!AbsPath) return false; // Skip files without absolute path. std::lock_guard<std::mutex> Lock(FilesMu); diff --git a/clang-tools-extra/clangd/refactor/Tweak.cpp b/clang-tools-extra/clangd/refactor/Tweak.cpp index bfa8bf6984f4..840843d1bfc4 100644 --- a/clang-tools-extra/clangd/refactor/Tweak.cpp +++ b/clang-tools-extra/clangd/refactor/Tweak.cpp @@ -105,7 +105,7 @@ Tweak::Effect::fileEdit(const SourceManager &SM, FileID FID, tooling::Replacements Replacements) { Edit Ed(SM.getBufferData(FID), std::move(Replacements)); if (const auto FE = SM.getFileEntryRefForID(FID)) - if (auto FilePath = getCanonicalPath(*FE, SM)) + if (auto FilePath = getCanonicalPath(*FE, SM.getFileManager())) return std::make_pair(*FilePath, std::move(Ed)); return error("Failed to get absolute path for edited file: {0}", SM.getFileEntryRefForID(FID)->getName()); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits