dotnet / dotnet/vscode-csharp

[BUG] Keyboard shortcut for code action refactor.extract.function fails when the menu action works.

Open
#7,454 3 comments 2 reactions 0 assignees View on GitHub
Bug
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
18h 40m
Merged PRs (30d)
31

Description

Originally filed by @rilehudd at https://github.com/microsoft/vscode-dotnettools/issues/1335

### Describe the Issue

Activating a key-binding to extract a method (using C#) does not extract the method. Though the code action does work if you do it through the right click menu.

### Steps To Reproduce

Reproduction steps:
1. Install C# Dev Kit extension.
2. Setup key-binding for "Extract Method" (per https://code.visualstudio.com/docs/editor/refactoring#_keybindings-for-code-actions)
3. Attempt to use hotkey to extract code into a method.
```csharp
public class Program
{
public static void Main()
{
// Highlighting from here
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Test" + i);
}
// to here
}
}
```
The hotkey fails with tooltip: "No code actions for 'refactor.extract.function' available"

### Expected Behavior

The action to extract a method via a hotkey (step 3) does not work (unexpected).
If you use the UI menu instead of a keyboard shortcut to extract into a method ("Right Click -> Refactor -> Extract Method") the functionality does succeed.

### Environment Information

Edition Windows 11 Enterprise
Version 23H2
Installed on ‎7/‎13/‎2023
OS build 22631.3880
Experience Windows Feature Experience Pack 1000.22700.1020.0

Version: 1.93.0-insider
Commit: 3b27f1f74bc09fe2e2068997fcd42768be44a4e3
Date: 2024-08-02T05:03:53.254Z
Electron: 30.1.2
ElectronBuildId: 9870757
Chromium: 124.0.6367.243
Node.js: 20.14.0
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.22631

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.