[clang-tools-extra] [Clangd][NFC] Normalize all file path root names (PR #153736)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 14 20:50:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangd
Author: zhujiatao (EcutAtom336)
<details>
<summary>Changes</summary>
Normalize all file path root names in GlobalChanges to uppercase to avoid case-sensitive copying on Windows. This will cause vscode-clangd to be unable to rename symbols (renaming cannot apply modifications).
---
Full diff: https://github.com/llvm/llvm-project/pull/153736.diff
1 Files Affected:
- (modified) clang-tools-extra/clangd/refactor/Rename.cpp (+20)
``````````diff
diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp
index c56375b1a98d3..6b2b38caf15fd 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -31,12 +31,16 @@
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/JSON.h"
+#include "llvm/Support/Path.h"
#include <algorithm>
#include <optional>
+#include <string>
namespace clang {
namespace clangd {
@@ -1196,6 +1200,22 @@ llvm::Expected<RenameResult> rename(const RenameInputs &RInputs) {
// Attach the rename edits for the main file.
Result.GlobalChanges.try_emplace(RInputs.MainFilePath,
std::move(MainFileEdits));
+
+#if defined(_WIN32) || defined(_WIN64)
+ // Normalize all file path root names in GlobalChanges to uppercase to avoid
+ // Case-sensitive replication on Windows.
+ FileEdits Normalized;
+ for (auto &Entry : Result.GlobalChanges) {
+ std::string Key = Entry.first().str();
+ llvm::sys::path::convert_to_slash(Key);
+ if (llvm::sys::path::has_root_name(llvm::Twine(Key))) {
+ Key[0] = llvm::toUpper(Key[0]);
+ }
+ Normalized[Key] = std::move(Entry.second);
+ }
+ Result.GlobalChanges.swap(Normalized);
+#endif // defined(_WIN32) || defined(_WIN64)
+
return Result;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/153736
More information about the cfe-commits
mailing list