Coc.nvim: Help with gopls

Created on 7 Apr 2019  路  26Comments  路  Source: neoclide/coc.nvim

Hi

I am not sure if this is a issue or maybe just me not knowing how to configure it, I am using go1.12.1 darwin/amd64.

I am trying to configure gopls in coc-settings.json

    "golang": {
      "command": "gopls",
      "rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
      "filetypes": ["go"]
    }

I have also install gopls as per this instructions, https://github.com/golang/go/wiki/gopls
go get -u golang.org/x/tools/cmd/gopls

however autocompletion is not working, If i change it to go-langserver it's working fine.

if you could assist would be greatly appreciated.

help wanted

Most helpful comment

@lanox workAround: add the full path to your gopls in the cocConfig json... here:

{
  "languageserver": {
    "golang": {
      "command": "[full-path-to-your-gopls-binary]/gopls",
      "rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
      "filetypes": ["go"]
    }
  }
}

All 26 comments

It looks like you need to pass extra arguments to the command, but I'm not sure.

2019/04/08 13:23:57 get package failed: no packages found for /Users/xx/code/go/src/github.com/lanox/lanox.go
2019/04/08 13:23:58 get token failed: no packages found for /Users/xx/code/go/src/github.com/lanox/lanox.go

adding under gopls in coc-settings.json "args": ["-logfile=lano.log"], I get above error messages

@lanox try this

git clone -b bingo https://github.com/saibing/tools.git
cd tools/cmd/gopls
go install

@taigacute tried that as well, no luck, that was the first thing I did.

After digging more through it, it seems that only works if you are in your GOPATH.
e.g
if I am in my $HOME, and I do vi lanox.go autocompletion will not work.

If I am navigate to my $GOPATH and do same as above, autocompletion works, although I don't get any documentation on floating window like I do with go-langserver.

@lanox it surpport go mod project you should go mod init

I don't get any documentation on floating window like I do with go-langserver.

this is a question i said to @chemzqm . the dohover of gopls works well on vscode. but didnt work with coc

the dohover of gopls works well on vscode. but didnt work with coc

Need output of language server https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel

I am little confused with gopls, if I open my existing project it seems that autocompletion works, however if I start new project and start typing code, autocompletion will not work.

@lanox if your project is a go mod pro you should go mod init first锛孠nown issue, unsaved buffer import third party package auto completion is not working, waiting to be repaired锛孏opls are unstable and have many problems.

@taigacute that is the interesting part, it is not this is just a normal folder with a .go file in it.

It might requires a correct workspaceFolder to work ,check out https://github.com/neoclide/coc.nvim/wiki/Using-workspaceFolders

ah, I am giving up on gopls, its just pain, and random.

    "languageserver": {
        "golang": {
            "command": "gopls",
            "filetypes": ["go"],
        }
    }

this is my settings for gopls.

  1. be sure to have $GOPATH correctly set
  2. use go-modules (You will get an error code 0 otherwise)
  3. the go file must exsist, you can't just open a new buffer (eg :e newfile.go)

EDIT: try using https://github.com/saibing/tools (it's just gopls with some edits the bingo developer did on the code)

Has anyone had any luck setting up any of GO language servers. I cant seem to get auto completion working for gopls or go-langserver. Can someone please help me out, or help me troubleshoot it.

works well
11

I managed to get it working with @alzedd's advice but it doesn't show any completion till you hit . so in my case for the screenshot above log wouldn't be in the autocompletion only log.F would give options

@Akin909 i use my config not @alzedd 's advice.

It seems to be working okay for me, however no floating windows, but I think that is due to gopls issue.

@taigacute to be honest with you screenshot you are showing only snippets, at least when I looked at you config you had stars if the definition is coming from snippets.

@lanox not snippets. do you see the [ls] that mean the completion from server

Yep I agree, i did not see that, however I did see in your config that your snippets also have stars, so I just assumed. Never assume I guess.

@lanox did you get it working with upstream gopls? It'd be great if coc.nvim didn't depend on the fork. Installing from the fork is a pain and it breaks all sorts of things with golang.org/x/tools

@luan no not really, its sporadic, but I haven't tried it in a while.

@lanox workAround: add the full path to your gopls in the cocConfig json... here:

{
  "languageserver": {
    "golang": {
      "command": "[full-path-to-your-gopls-binary]/gopls",
      "rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
      "filetypes": ["go"]
    }
  }
}

Thanks @ucef29 your suggestion "command": "[full-path-to-your-gopls-binary]/gopls" it works for me.
Than you very much 馃挴

There's the coc-go extension too, which is even nicer and easier to use.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhou13 picture zhou13  路  3Comments

lanox picture lanox  路  3Comments

hackingcat picture hackingcat  路  3Comments

svenstaro picture svenstaro  路  4Comments

cvlmtg picture cvlmtg  路  3Comments