vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

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

Open dibarbet opened this issue 1 year ago • 3 comments

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

dibarbet avatar Aug 19 '24 22:08 dibarbet