Skip to content
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

[BUG] Wrap with widget code action does not enter select mode #426

Open
1 task done
payolin opened this issue Jan 3, 2025 · 1 comment
Open
1 task done

[BUG] Wrap with widget code action does not enter select mode #426

payolin opened this issue Jan 3, 2025 · 1 comment

Comments

@payolin
Copy link

payolin commented Jan 3, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When using the 'Wrap with Widget' code action, a widget called "widget" is created. The cursor stays in the middle of the name and the placeholder is not selected.
2025-01-03-145301_sway-screenshot

Expected Behavior

It should enter select mode, allowing to select a widget. For example, when using the "Stateless widget" snippet, it creates a class called "MyWidget" and selects the name of the class. Entering text erases the placeholder.
2025-01-03-145456_sway-screenshot

It could also brind up a popup or query, for example as when renaming a variable.

Steps To Reproduce

I am using the following config (lazy.nvim):

  {
    "nvim-flutter/flutter-tools.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "stevearc/dressing.nvim"
    },
    config = function ()
      local map = vim.keymap.set
      map("n", "fR", "<cmd> FlutterRun <cr>")
      map("n", "fd", "<cmd> FlutterDevices <cr>")
      map("n", "fr", "<cmd> FlutterRestart <cr>")
      map("n", "fo", "<cmd> FlutterOutlineToggle <cr>")
      require("flutter-tools").setup {
        flutter_lookup_cmd = "asdf where flutter",
        widget_guides = {
          enabled = true,
        }
      }
    end,
    ft = "dart"
  },

I have called the code action on the following snippet, at Placeholder

Widget test() {
  return Placeholder()
}

Environment

- OS:Fedora 40
- Flutter version: tested on
  - 3.19.5
  - 3.19.6
  - 3.22.0
  - 3.22.2
  - 3.24.3
  - 3.24.4

- Is flutter in $PATH: yes
- neovim version: 0.10.2

Anything else?

No response

@sidlatau
Copy link
Collaborator

sidlatau commented Jan 3, 2025

I investigated a bit and found, that if

capabilities.experimental = { snippetTextEdit = true }

is provided, then Wrap with widget... returns the result in LSP snippet format. Here is the action output:

{                                                                                                                                                                        
  command = {                                                                                                                                                            
    arguments = { {                                                                                                                                                      
        action = "dart.assist.flutter.wrap.generic"                                                                                                                      
      } },                                                                                                                                                               
    command = "dart.logAction",                                                                                                                                          
    title = "Log Action"                                                                                                                                                 
  },                                                                                                                                                                     
  diagnostics = {},                                                                                                                                                      
  edit = {                                                                                                                                                               
    documentChanges = { {                                                                                                                                                
        edits = { {                                                                                                                                                      
            insertTextFormat = 2,                                                                                                                                        
            newText = "${1:widget}(${2:child}: Text(context.l10n.internalNote))",                                                                                        
            range = {                                                                                                                                                    
              ["end"] = {                                                                                                                                                
                character = 63,                                                                                                                                          
                line = 123                                                                                                                                               
              },                                                                                                                                                         
              start = {                                                                                                                                                  
                character = 32,                                                                                                                                          
                line = 123                                                                                                                                               
              }                                                                                                                                                          
            }                                                                                                                                                            
          } },                                                                                                                                                           
        textDocument = {                                                                                                                                                 
          uri = "file:///Users/ts/Documents/github/widget.dart",                                               
          version = 0                                                                                                                                                    
        }                                                                                                                                                                
      } }                                                                                                                                                                
  },                                                                                                                                                                     
  kind = "refactor.flutter.wrap.generic",                                                                                                                                
  title = "Wrap with widget..."                                                                                                                                          
}     

That is how, I think, VSCode handles it. But I haven't found any easy way how to expand this snippet from code action. Neovim has some basic support for expanding snippets via vim.snippet.expand(), but not sure if it is possible to expand it here. I think at some point this should be supported directly by neovim, maybe via vim.lsp.util.apply_workspace_edit().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants