[clangd][NFC] Make some local variables HeaderSourceSwitch.cpp const and constexpr (#143193)

This commit is contained in:
Jouni 2025-08-03 06:23:19 +02:00 committed by GitHub
parent 7de0da40c0
commit 1da76b42ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,22 +20,24 @@ namespace clangd {
std::optional<Path> getCorrespondingHeaderOrSource( std::optional<Path> getCorrespondingHeaderOrSource(
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx", static constexpr llvm::StringRef SourceExtensions[] = {
".c++", ".m", ".mm"}; ".cpp", ".c", ".cc", ".cxx", ".c++", ".m", ".mm"};
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", static constexpr llvm::StringRef HeaderExtensions[] = {
".inc", ".cppm", ".ccm", ".cxxm", ".h", ".hh", ".hpp", ".hxx", ".inc",
".c++m", ".ixx"}; ".cppm", ".ccm", ".cxxm", ".c++m", ".ixx"};
llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile); llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile);
// Lookup in a list of known extensions. // Lookup in a list of known extensions.
bool IsSource = llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) { const bool IsSource =
return SourceExt.equals_insensitive(PathExt); llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
}); return SourceExt.equals_insensitive(PathExt);
});
bool IsHeader = llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) { const bool IsHeader =
return HeaderExt.equals_insensitive(PathExt); llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
}); return HeaderExt.equals_insensitive(PathExt);
});
// We can only switch between the known extensions. // We can only switch between the known extensions.
if (!IsSource && !IsHeader) if (!IsSource && !IsHeader)
@ -94,7 +96,7 @@ std::optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
// //
// For each symbol in the original file, we get its target location (decl or // For each symbol in the original file, we get its target location (decl or
// def) from the index, then award that target file. // def) from the index, then award that target file.
bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts()); const bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
Index->lookup(Request, [&](const Symbol &Sym) { Index->lookup(Request, [&](const Symbol &Sym) {
if (IsHeader) if (IsHeader)
AwardTarget(Sym.Definition.FileURI); AwardTarget(Sym.Definition.FileURI);