Skip to content

[clangd][NFC] added const and constexpr to HeaderSourceSwitch #143193

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JohnFinn
Copy link

@JohnFinn JohnFinn commented Jun 6, 2025

No description provided.

Copy link

github-actions bot commented Jun 6, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2025

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Jouni (JohnFinn)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/143193.diff

1 Files Affected:

  • (modified) clang-tools-extra/clangd/HeaderSourceSwitch.cpp (+14-12)
diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
index d54c3668570eb..ee4bea1401490 100644
--- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
+++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
@@ -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)
@@ -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);

@JohnFinn
Copy link
Author

JohnFinn commented Jul 3, 2025

@ChuanqiXu9

@vbvictor vbvictor changed the title [clangd] added const and constexpr [clangd][NFC] added const and constexpr Jul 4, 2025
Copy link
Contributor

@vbvictor vbvictor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch LGTM, but it may have to be approved by one of clangd's maintainers that I added.
You should also add NFC in the title if you have non-functional changes (I already did it this time).

@vbvictor vbvictor changed the title [clangd][NFC] added const and constexpr [clangd][NFC] added const and constexpr to HeaderSourceSwitch Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants