Skip to content

Conversation

@EcutAtom336
Copy link

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).

Normalize all file path root names in GlobalChanges to uppercase
to avoid case-sensitive replication on Windows.
@github-actions
Copy link

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 Aug 15, 2025

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

@llvm/pr-subscribers-clangd

Author: zhujiatao (EcutAtom336)

Changes

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 --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;
 }
 

@HighCommander4
Copy link
Collaborator

Making this change in code specific to the "rename" operation is just going to address one symptom of a larger underlying problem, which is clangd/clangd#108.

A more comprehensive fix for the underlying issue is being worked on in #136439.

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