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

Need help in understanding on_attach vs setup config #341

Open
sbushmanov opened this issue Sep 13, 2024 · 4 comments
Open

Need help in understanding on_attach vs setup config #341

sbushmanov opened this issue Sep 13, 2024 · 4 comments

Comments

@sbushmanov
Copy link

sbushmanov commented Sep 13, 2024

I've setup lsp_signature with the following in my lsp_signature.lua (lazy):

return {
  "ray-x/lsp_signature.nvim",
  event = "LspAttach",
  lazy = true,
  config = function()
    require("lsp_signature").setup {
      hint_enable = true
    }
  end
}

However, this doesn't work at all.

After a bit of experimenting I succeeded in showing up signature help (still without a panda) with the following:

return {
  "ray-x/lsp_signature.nvim",
  event = "LspAttach",
  lazy = true,
  config = function()
    require("lsp_signature").on_attach {
      hint_enable = true
    }
  end
}

Can somebody please guide me on the proper way on setting up the plugin (lazy) and explaining the difference between the 2?

@ray-x
Copy link
Owner

ray-x commented Sep 15, 2024

With latest lazy.nvim
You should be able to use

{
    'ray-x/lsp_signature.nvim',
    event = { 'InsertEnter' },
    opts = {
      ...
    }
  }

@sbushmanov
Copy link
Author

sbushmanov commented Sep 15, 2024

Sorry, does't work with the suggested setup.

And even when I tried to restore the previous setup that used to work Im getting:

Error detected while processing CursorHold Autocommands for "<buffer=1>":
Error executing lua callback: ...vim/lazy/lsp_signature.nvim/lua/lsp_signature/helper.lua:756: attempt to c
all field 'empty' (a nil value)
stack traceback:
        ...vim/lazy/lsp_signature.nvim/lua/lsp_signature/helper.lua:756: in function 'check_lsp_cap'
        .../nvim/lazy/lsp_signature.nvim/lua/lsp_signature/init.lua:669: in function 'signature'
        .../nvim/lazy/lsp_signature.nvim/lua/lsp_signature/init.lua:907: in function 'on_UpdateSignature'
        ...vim/lazy/lsp_signature.nvim/lua/lsp_signature/helper.lua:28: in function <...vim/lazy/lsp_signat
ure.nvim/lua/lsp_signature/helper.lua:27>
Press ENTER or type command to continue

And even though lua vim.lsp.buf.signature_help() does produces signature (accompanied with some error messages) lua require'lsp_signature'.signature() only produces error message

@ray-x
Copy link
Owner

ray-x commented Sep 16, 2024

The error you saw was fixed.
Also, use the attach method making sure the setup is after lsp_config.

@ChaseOne1
Copy link

ChaseOne1 commented Nov 9, 2024

There is some additional information here about this issue(on_attach & setup):
As mentioned in #47 (comment), these two methods seem to affect the correct performance of the plugin.
For example, if lazy loading the plugin on InsertEnter event with lazy.nvim, the float window doesn't display as expected. But when you call up the telescope window (even if you just open and then close it), the plugin works correctly.
I have seen some comments in certain places speculating that this is a lazy loading mechanism issue with lazy.nvim (if you don't use lazy loading, there won't be this problem). I have tried a configuration that can solve this problem:

-- in lsp_signature.lua
return {
    "ray-x/lsp_signature.nvim",
    event = "InsertEnter",
    opts = function()
        require("lsp_signature").on_attach({
            -- your own settings
        })
    end,
}

One of the points is the on_attach method.
According to lazy.nvim:

config is executed when the plugin loads. The default implementation will automatically run require(MAIN).setup(opts) if opts or config = true is set.

Hope this information can help you and improve.

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

3 participants