GithubHelp home page GithubHelp logo

Manually specify gopls path about go.nvim HOT 6 CLOSED

ray-x avatar ray-x commented on July 16, 2024
Manually specify gopls path

from go.nvim.

Comments (6)

ray-x avatar ray-x commented on July 16, 2024

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

from go.nvim.

jonleopard avatar jonleopard commented on July 16, 2024

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

from go.nvim.

jonleopard avatar jonleopard commented on July 16, 2024

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?

from go.nvim.

ray-x avatar ray-x commented on July 16, 2024

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()

from go.nvim.

jonleopard avatar jonleopard commented on July 16, 2024

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!

from go.nvim.

ray-x avatar ray-x commented on July 16, 2024

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

from go.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.