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

Manually specify gopls path #17

Closed
jonleopard opened this issue Jul 25, 2021 · 6 comments
Closed

Manually specify gopls path #17

jonleopard opened this issue Jul 25, 2021 · 6 comments

Comments

@jonleopard
Copy link

I'm using nvim-lspinstall to manage all my lsp installations. Is it possible to tell go.nvim where the path to this binary is?

Here's an example of what I was doing before:

DATA_PATH = vim.fn.stdpath "data"
require('lspconfig').gopls.setup{
    cmd = { DATA_PATH .. "/lspinstall/go/gopls" },
    settings = {
      gopls = {
        analyses = {
          unusedparams = true,
        },
        staticcheck = true,
      },
    },
}
@ray-x
Copy link
Owner

ray-x commented Jul 26, 2021

Hi, @jonleopard
I added gopls_cmd in config
Could you check if the latest version works for you?

@jonleopard
Copy link
Author

Seems to be working now! I've added gopls_cmd = {DATA_PATH .. "/lspinstall/go/gopls"} to my config. When I run lspinfo it seems that two clients are attached, which confuses me:

Screenshot 2021-07-26 at 10 05 17

It looks like its adding two paths for some reason:
...lspinstall/go/./gopls
...lspinstall/go/gopls

Additionally, when I save the file and it formats, it prompts me for which lsp server to use:
Screenshot 2021-07-26 at 10 06 44

@jonleopard
Copy link
Author

Ah, I fixed it! There was something wrong in my config. One last quick question: when I save a buffer, it formats but doesn't import missing packages. Is this default setting or do I need to enable it somehow?

@ray-x
Copy link
Owner

ray-x commented Jul 26, 2021

If you want both import and format. You can use either Goimport, which is defined as:

  vim.cmd([[command! Goimport lua require("go.format").goimport()]])

Or add:

autocmd BufWritePre *.go :silent! lua require('go.format').goimport()

@jonleopard
Copy link
Author

Works like a charm, thanks! It seems Lua doesn't have a autocommand support yet. So if anyone reading this wants this autocmd BufWritePre *.go :silent! lua require('go.format').goimport() to work in lua, you can do so like this:

-- Format on save
vim.api.nvim_exec([[ autocmd BufWritePre *.go :silent! lua require('go.format').gofmt() ]], false)

-- Import on save
vim.api.nvim_exec([[ autocmd BufWritePre *.go :silent! lua require('go.format').goimport() ]], false)

Thanks again for your help!

@ray-x
Copy link
Owner

ray-x commented Jul 26, 2021

Thanks!
I will put your codes in README.md as well

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