Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Golang struct auto-fill does not work #36

Open
and3rson opened this issue Dec 14, 2021 · 4 comments
Open

Golang struct auto-fill does not work #36

and3rson opened this issue Dec 14, 2021 · 4 comments

Comments

@and3rson
Copy link

and3rson commented Dec 14, 2021

Neovim version: NVIM v0.7.0-dev+715-g1f3c0593e
LSP server: gopls

My config:

vim.g.code_action_menu_show_details = false
vim.g.code_action_menu_show_diff = false

image

When selecting Fill log.TextFormatter, nothing happens. However when using vim.lsp.buf.code_action(), the struct is properly auto-filled.

In the meantime, Organize imports works just fine. Any ideas?

@weilbith
Copy link
Owner

Interesting. 🤔
I think I need to start adding a debug mode for these issues. Typically I need to inspect the actual actions that get sent by the server.
But does the window close when you select the 2? Or does it stay open?

@and3rson
Copy link
Author

@weilbith yes, it closes. I can provide more details if necessary, please let me know if you need anything!

@and3rson
Copy link
Author

@weilbith I've tried to do some debugging, here's an action that is being executed in code_action_menu.lua:119:

{
  server_data = {
    command = {
      arguments = { {
          Fix = "fill_struct",
          Range = {
            end = {
              character = 20,
              line = 62
            },
            start = {
              character = 1,
              line = 62
            }
          },
          URI = "file:///home/anderson/src/darwin/main.go"
        } },
      command = "gopls.apply_fix",
      title = "Fill log.TextFormatter"
    },
    edit = vim.empty_dict(),
    kind = "refactor.rewrite",
    title = "Fill log.TextFormatter"
  },
  <metatable> = <1>{
    __index = <table 1>,
    execute = <function 1>,
    get_disabled_reason = <function 2>,
    get_kind = <function 3>,
    get_name = <function 4>,
    get_workspace_edit = <function 5>,
    is_command = <function 6>,
    is_disabled = <function 7>,
    is_preferred = <function 8>,
    is_workspace_edit = <function 9>,
    new = <function 10>,
    server_data = {},
    <metatable> = <2>{
      __index = <table 2>,
      execute = <function 11>,
      get_disabled_reason = <function 12>,
      get_kind = <function 13>,
      get_name = <function 14>,
      get_title = <function 15>,
      get_workspace_edit = <function 16>,
      is_disabled = <function 17>,
      is_preferred = <function 18>,
      new = <function 19>
    }
  }
}

The selected_action:execute() call returns nil, so I'm not sure at which point do things go wrong.

@and3rson
Copy link
Author

and3rson commented Dec 19, 2021

@weilbith I think I've spotted a reason why vim.lsp.buf.code_action() works and :CodeActionMenu doesn't. Relevant lines are in code_action.lua:79:

  if self:is_workspace_edit() then
    vim.lsp.util.apply_workspace_edit(self.server_data.edit)
  elseif self:is_command() then
    vim.lsp.buf.execute_command(self.server_data.command)

If I remove first check (is_workspace_edit), the second one succeeds, i.e. is_command returns true and the struct is properly filled! However, with this check removed, another action "organize imports" fails (since it should be treated like a "workspace edit" kind of command). I'm not too familiar with how LSP protocol works, so maybe you could shed some light on this.

I think vim/lsp/buf.lua:522 is something that can be used as a reference here.

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

No branches or pull requests

2 participants