- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15.1k
 
[clangd] Fix code action kind for readability-identifier-naming fixes #162808
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
[clangd] Fix code action kind for readability-identifier-naming fixes #162808
Conversation
Commit a45df47 (llvm#78454) converted readability-identifier-naming fixes to use rename mechanism to leverage the index for better results. However, it set the code action kind to "refactor" instead of "quickfix", which caused the fixes to be filtered out when editors (like VS Code) request quick fixes for diagnostics. On VS Code, for example, users would see "No quick fixes available" despite the diagnostic indicating "(fix available)", and the following warning would appear in the output console: [warning] llvm-vs-code-extensions.vscode-clangd - Code actions of kind 'quickfix' requested but returned code action is of kind 'refactor'. Code action will be dropped. Please check 'CodeActionContext.only' to only return requested code actions. Fix that by changing the code action kind back to "quickfix". Addresses llvm#78454 (comment). Signed-off-by: Ruoyu Zhong <[email protected]>
| 
          
 @llvm/pr-subscribers-clangd @llvm/pr-subscribers-clang-tools-extra Author: Ruoyu Zhong (ZhongRuoyu) ChangesCommit a45df47 (#78454) converted readability-identifier-naming fixes to use rename mechanism to leverage the index for better results. However, it set the code action kind to "refactor" instead of "quickfix", which caused the fixes to be filtered out when editors (like VS Code) request quick fixes for diagnostics. On VS Code, for example, users would see "No quick fixes available" despite the diagnostic indicating "(fix available)", and the following warning would appear in the output console: Fix that by changing the code action kind back to "quickfix". Addresses #78454 (comment). CC @tom-anders @HighCommander4. Full diff: https://github.com/llvm/llvm-project/pull/162808.diff 2 Files Affected: 
 diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index b445dcf2bbd2e..0f765e96fb152 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -81,7 +81,7 @@ CodeAction toCodeAction(const ClangdServer::CodeActionResult::Rename &R,
                         const URIForFile &File) {
   CodeAction CA;
   CA.title = R.FixMessage;
-  CA.kind = std::string(CodeAction::REFACTOR_KIND);
+  CA.kind = std::string(CodeAction::QUICKFIX_KIND);
   CA.command.emplace();
   CA.command->title = R.FixMessage;
   CA.command->command = std::string(ApplyRenameCommand);
diff --git a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
index 2c7f50d8c9e4c..95bf5e54fc792 100644
--- a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -235,7 +235,8 @@ TEST_F(LSPTest, ClangTidyRename) {
             .takeValue()
             .getAsArray())[0];
 
-  ASSERT_EQ((*RenameCommand.getAsObject())["title"], "change 'foo' to 'Foo'");
+  ASSERT_EQ((*RenameCommand.getAsObject())["title"],
+            "Apply fix: change 'foo' to 'Foo'");
 
   Client.expectServerCall("workspace/applyEdit");
   Client.call("workspace/executeCommand", RenameCommand);
 | 
    
          
 Ouch! Thanks very much for catching and fixing that.  | 
    
| 
           Thanks for merging, @HighCommander4! What do you think about backporting this to the 21.x branch so that existing users can get this without having to wait for a 22.x release? If you think it's OK: #163130  | 
    
…llvm#162808) llvm#78454 converted readability-identifier-naming fixes to use rename mechanism to rename the symbol project-wide. However, it set the code action kind to "refactor" instead of "quickfix", which caused the fixes to be filtered out when editors (like VS Code) request quick fixes for diagnostics. On VS Code, for example, users would see "No quick fixes available" despite the diagnostic indicating "(fix available)". Fix that by changing the code action kind back to "quickfix". Signed-off-by: Ruoyu Zhong <[email protected]>
…llvm#162808) llvm#78454 converted readability-identifier-naming fixes to use rename mechanism to rename the symbol project-wide. However, it set the code action kind to "refactor" instead of "quickfix", which caused the fixes to be filtered out when editors (like VS Code) request quick fixes for diagnostics. On VS Code, for example, users would see "No quick fixes available" despite the diagnostic indicating "(fix available)". Fix that by changing the code action kind back to "quickfix". Signed-off-by: Ruoyu Zhong <[email protected]>
…#162808) #78454 converted readability-identifier-naming fixes to use rename mechanism to rename the symbol project-wide. However, it set the code action kind to "refactor" instead of "quickfix", which caused the fixes to be filtered out when editors (like VS Code) request quick fixes for diagnostics. On VS Code, for example, users would see "No quick fixes available" despite the diagnostic indicating "(fix available)". Fix that by changing the code action kind back to "quickfix". Signed-off-by: Ruoyu Zhong <[email protected]>
…llvm#162808) llvm#78454 converted readability-identifier-naming fixes to use rename mechanism to rename the symbol project-wide. However, it set the code action kind to "refactor" instead of "quickfix", which caused the fixes to be filtered out when editors (like VS Code) request quick fixes for diagnostics. On VS Code, for example, users would see "No quick fixes available" despite the diagnostic indicating "(fix available)". Fix that by changing the code action kind back to "quickfix". Signed-off-by: Ruoyu Zhong <[email protected]>
Commit a45df47 (#78454) converted readability-identifier-naming fixes to use rename mechanism to leverage the index for better results. However, it set the code action kind to "refactor" instead of "quickfix", which caused the fixes to be filtered out when editors (like VS Code) request quick fixes for diagnostics. On VS Code, for example, users would see "No quick fixes available" despite the diagnostic indicating "(fix available)", and the following warning would appear in the output console:
Fix that by changing the code action kind back to "quickfix".
Addresses #78454 (comment).
CC @tom-anders @HighCommander4.