[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 22:14:19 PDT 2025
https://github.com/EcutAtom336 updated https://github.com/llvm/llvm-project/pull/153736
>From 0a478fdde90e4b02aa349ca62073d51871875af3 Mon Sep 17 00:00:00 2001
From: zhujiatao <1975841338 at qq.com>
Date: Fri, 15 Aug 2025 11:23:01 +0800
Subject: [PATCH] [Clangd][NFC] Normalize all file path root names
Normalize all file path root names in GlobalChanges to uppercase
to avoid case-sensitive replication on Windows.
---
clang-tools-extra/clangd/refactor/Rename.cpp | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
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;
}
More information about the cfe-commits
mailing list