Skip to content

adamatom/coc-go

 
 

Repository files navigation

coc-go

Go language server extension using gopls for coc.nvim.

Install

In your vim/neovim, run command:

:CocInstall coc-go

Features

See gopls

Commands

Additional to commands provided by gopls, this extensions provides these commands:

Key
go.install.gomodifytags Install / Update gomodifytags
go.install.gopls Install / Update gopls
go.install.gotests Install / Update gotests
go.playground Run on Go Playground
go.tags.add.line Add Tags To Struct Field at current line
go.tags.add.prompt Add Tags To Struct Fields (prompt)
go.tags.add Add Tags To Struct Fields
go.tags.clear.line Remove All Tags From Struct Field at line
go.tags.clear Remove All Tags From Struct Fields
go.tags.remove.line Remove Tags From Struct Field at line
go.tags.remove.prompt Remove Tags From Struct Fields (prompt)
go.tags.remove Remove Tags From Struct Fields
go.test.generate.exported Generate Unit Tests For Exported Functions in File
go.test.generate.file: Generate Unit Tests For File
go.test.toggle Toggle Test File
go.version Print extension version

Examples

  • Add or Remove specific tags

    CocCommand go.tags.add yaml
    CocCommand go.tags.add yaml json xml
    CocCommand go.tags.remove xml
    
  • Add missing imports on save

    autocmd BufWritePre *.go :CocCommand editor.action.organizeImport
    
  • Map Keys to command

    autocmd FileType go nmap gtj :CocCommand go.tags.add json<cr>
    autocmd FileType go nmap gty :CocCommand go.tags.add yaml<cr>
    autocmd FileType go nmap gtx :CocCommand go.tags.clear<cr>
    

Snippets

Snippets are imported from microsoft/vscode-go and require coc-snippets to be installed.

Configuration options

Key
go.enable Set to false to disable gopls language server.
go.commandPath Absolute path of gopls executable.
go.tags.tags Comma separated tags to be used by go.tags.add command
go.tags.options Comma separated tag=options pairs to be used by go.tags.add command
go.tags.transform Transformation rule used by go.tags.add command to add tags
go.tests.generateFlags Additional command line flags to pass to gotests for generating tests."

Trigger completion in coc-settings.json to get complete list.

Development

  1. Run yarn build or yarn build:watch
  2. Run yarn run link:add to link extension

TODO

  • Add goimpl command

    {
      "command": "go.impl.cursor",
      "title": "Go: Generate Interface Stubs"
    }
    
  • Add godoctor refactor commands

    {
      "command": "go.godoctor.extract",
      "title": "Go: Extract to function"
    },
    {
      "command": "go.godoctor.variable",
      "title": "Go: Extract to variable"
    }
    
  • Add fillstruct command

    {
      "command": "go.fill.struct",
      "title": "Go: Fill struct"
    }
    

Tools

License

MIT © Josa Gesell

About

Go language server extension using gopls for coc.nvim.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • TypeScript 83.7%
  • JavaScript 16.3%