diff options
author | Haojian Wu <hokein@google.com> | 2018-12-13 13:07:29 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2018-12-13 13:07:29 +0000 |
commit | 9d0d9f884cebc9a1cad49679b3b64b9fdae2c964 (patch) | |
tree | c99d78b820b3515c5a65048f4abc3ee35ea7c1e2 /clang-tools-extra | |
parent | cdbd5bef6d941b74963e76a0d271f70a268527db (diff) | |
download | bcm5719-llvm-9d0d9f884cebc9a1cad49679b3b64b9fdae2c964.tar.gz bcm5719-llvm-9d0d9f884cebc9a1cad49679b3b64b9fdae2c964.zip |
[clangd] Move the utility function to anonymous namespace, NFC.
llvm-svn: 349031
Diffstat (limited to 'clang-tools-extra')
-rw-r--r-- | clang-tools-extra/clangd/index/Background.cpp | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp index ca3e41a29e6..6c104cbe241 100644 --- a/clang-tools-extra/clangd/index/Background.cpp +++ b/clang-tools-extra/clangd/index/Background.cpp @@ -86,6 +86,39 @@ IncludeGraph getSubGraph(const URI &U, const IncludeGraph &FullGraph) { return IG; } + +// Creates a filter to not collect index results from files with unchanged +// digests. +// \p FileDigests contains file digests for the current indexed files, and all +// changed files will be added to \p FilesToUpdate. +decltype(SymbolCollector::Options::FileFilter) +createFileFilter(const llvm::StringMap<FileDigest> &FileDigests, + llvm::StringMap<FileDigest> &FilesToUpdate) { + return [&FileDigests, &FilesToUpdate](const SourceManager &SM, FileID FID) { + StringRef Path; + if (const auto *F = SM.getFileEntryForID(FID)) + Path = F->getName(); + if (Path.empty()) + return false; // Skip invalid files. + SmallString<128> AbsPath(Path); + if (std::error_code EC = + SM.getFileManager().getVirtualFileSystem()->makeAbsolute(AbsPath)) { + elog("Warning: could not make absolute file: {0}", EC.message()); + return false; // Skip files without absolute path. + } + sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); + auto Digest = digestFile(SM, FID); + if (!Digest) + return false; + auto D = FileDigests.find(AbsPath); + if (D != FileDigests.end() && D->second == Digest) + return false; // Skip files that haven't changed. + + FilesToUpdate[AbsPath] = *Digest; + return true; + }; +} + } // namespace BackgroundIndex::BackgroundIndex( @@ -281,38 +314,6 @@ void BackgroundIndex::update(StringRef MainFile, IndexFileIn Index, } } -// Creates a filter to not collect index results from files with unchanged -// digests. -// \p FileDigests contains file digests for the current indexed files, and all -// changed files will be added to \p FilesToUpdate. -decltype(SymbolCollector::Options::FileFilter) -createFileFilter(const llvm::StringMap<FileDigest> &FileDigests, - llvm::StringMap<FileDigest> &FilesToUpdate) { - return [&FileDigests, &FilesToUpdate](const SourceManager &SM, FileID FID) { - StringRef Path; - if (const auto *F = SM.getFileEntryForID(FID)) - Path = F->getName(); - if (Path.empty()) - return false; // Skip invalid files. - SmallString<128> AbsPath(Path); - if (std::error_code EC = - SM.getFileManager().getVirtualFileSystem()->makeAbsolute(AbsPath)) { - elog("Warning: could not make absolute file: {0}", EC.message()); - return false; // Skip files without absolute path. - } - sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); - auto Digest = digestFile(SM, FID); - if (!Digest) - return false; - auto D = FileDigests.find(AbsPath); - if (D != FileDigests.end() && D->second == Digest) - return false; // Skip files that haven't changed. - - FilesToUpdate[AbsPath] = *Digest; - return true; - }; -} - Error BackgroundIndex::index(tooling::CompileCommand Cmd, BackgroundIndexStorage *IndexStorage) { trace::Span Tracer("BackgroundIndex"); |