Skip to content

[clangd] added const and constexpr #143193

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions clang-tools-extra/clangd/HeaderSourceSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@ namespace clangd {

std::optional<Path> getCorrespondingHeaderOrSource(
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
".c++", ".m", ".mm"};
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx",
".inc", ".cppm", ".ccm", ".cxxm",
".c++m", ".ixx"};
static constexpr llvm::StringRef SourceExtensions[] = {
".cpp", ".c", ".cc", ".cxx", ".c++", ".m", ".mm"};
static constexpr llvm::StringRef HeaderExtensions[] = {
".h", ".hh", ".hpp", ".hxx", ".inc",
".cppm", ".ccm", ".cxxm", ".c++m", ".ixx"};

llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile);

// Lookup in a list of known extensions.
bool IsSource = llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
return SourceExt.equals_insensitive(PathExt);
});
const bool IsSource =
llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
return SourceExt.equals_insensitive(PathExt);
});

bool IsHeader = llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
return HeaderExt.equals_insensitive(PathExt);
});
const bool IsHeader =
llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
return HeaderExt.equals_insensitive(PathExt);
});

// We can only switch between the known extensions.
if (!IsSource && !IsHeader)
Expand Down Expand Up @@ -94,7 +96,7 @@ std::optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
//
// For each symbol in the original file, we get its target location (decl or
// 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) {
if (IsHeader)
AwardTarget(Sym.Definition.FileURI);
Expand Down