Go language server extension using gopls
for coc.nvim.
In your vim/neovim, run command:
:CocInstall coc-go
See gopls
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 |
-
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 are imported from microsoft/vscode-go
and require coc-snippets to be
installed.
| 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.
- Run
yarn buildoryarn build:watch - Run
yarn run link:addto link extension
-
Add
goimplcommand{ "command": "go.impl.cursor", "title": "Go: Generate Interface Stubs" } -
Add
godoctorrefactor commands{ "command": "go.godoctor.extract", "title": "Go: Extract to function" }, { "command": "go.godoctor.variable", "title": "Go: Extract to variable" } -
Add
fillstructcommand{ "command": "go.fill.struct", "title": "Go: Fill struct" }