Go language server extension using gopls
for coc.nvim
.
In your vim/neovim, run this command:
:CocInstall coc-go
See gopls
Additional to commands provided by gopls, this extensions provides these commands:
Key | Description |
---|---|
go.gopls.tidy |
Run gopls.tidy LSP command |
go.impl.cursor |
Generate interface stubs |
go.install.gomodifytags |
Install / update gomodifytags |
go.install.goplay |
Install / update goplay |
go.install.gopls |
Install / update gopls |
go.install.gotests |
Install / update gotests |
go.install.impl |
Install / update impl |
go.install.tools |
Install / update all tools |
go.playground |
Run on go playground |
go.tags.add |
Add tags to struct fields |
go.tags.add.line |
Add tags to struct field in current line |
go.tags.add.prompt |
Add tags to struct fields (prompt) |
go.tags.clear |
Remove all tags from struct fields |
go.tags.clear.line |
Remove all tags from struct fields in current line |
go.tags.remove |
Remove tags from struct fields |
go.tags.remove.line |
Remove tags from struct field in current line |
go.tags.remove.prompt |
Remove tags from struct fields (prompt) |
go.test.generate.exported |
Generate unit tests for exported functions in file |
go.test.generate.file |
Generate unit tests for file |
go.test.generate.function |
Generate unit tests for current function |
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 :silent call CocAction('runCommand', '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 golang/vscode-go
and require coc-snippets
to be
installed.
Key | Description | Default |
---|---|---|
go.checkForUpdates |
Check for gopls updates on start. | install |
go.disable |
Disable gopls features | {} |
β£Β completion |
Disable completion feature (Change requires :CocRestart ) |
false |
β£Β diagnostics |
Disable handle diagnostics (Change requires :CocRestart ) |
false |
β£Β features |
Disabled features (Change requires :CocRestart ) |
[] |
β£Β snippetCompletion |
Disable snippet completion (Change requires :CocRestart ) |
false |
β£Β workspaceFolders |
Disable workspaceFolders feature (Change requires :CocRestart ) |
false |
go.enable |
Enable Go extension | true |
go.goplsArgs |
Arguments passed to gopls (Change requires :CocRestart ) |
|
go.goplsEnv |
ENV passed to gopls (Change requires :CocRestart ) |
|
go.goplsOptions |
See gopls documentation |
|
β£Β allowImplicitNetworkAccess |
This setting is experimental and may be deleted. allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module downloads rather than requiring user action. | false |
β£Β allowModfileModifications |
This setting is experimental and may be deleted. allowModfileModifications disables -mod=readonly, allowing imports from out-of-scope modules. | false |
β£Β analyses |
analyses specify analyses that the user would like to enable or disable. | |
β£Β analysisProgressReporting |
analysisProgressReporting controls whether gopls sends progress notifications when construction of its index of analysis facts is taking a long time. | true |
β£Β annotations |
This setting is experimental and may be deleted. annotations specifies the various kinds of optimization diagnostics that should be reported by the gc_details command. | |
β£Β buildFlags |
buildFlags is the set of flags passed on to the build system when invoked. | |
β£Β codelenses |
codelenses overrides the enabled/disabled state of code lenses. | |
β£Β completeFunctionCalls |
completeFunctionCalls enables function call completion. | true |
β£Β completionBudget |
This setting is for debugging purposes only. completionBudget is the soft latency goal for completion requests. | 100ms |
β£Β diagnosticsDelay |
This is an advanced setting and should not be configured by most gopls users. diagnosticsDelay controls the amount of time that gopls waits after the most recent file modification before computing deep diagnostics. |
1s |
β£Β diagnosticsTrigger |
This setting is experimental and may be deleted. diagnosticsTrigger controls when to run diagnostics. | Edit |
β£Β directoryFilters |
directoryFilters can be used to exclude unwanted directories from the workspace. | |
β£Β env |
env adds environment variables to external commands run by gopls , most notably go list . |
|
β£Β expandWorkspaceToModule |
This setting is experimental and may be deleted. expandWorkspaceToModule determines which packages are considered "workspace packages" when the workspace is using modules. | true |
β£Β experimentalPostfixCompletions |
This setting is experimental and may be deleted. experimentalPostfixCompletions enables artificial method snippets such as "someSlice.sort!". | true |
β£Β gofumpt |
gofumpt indicates if we should run gofumpt formatting. | false |
β£Β hints |
This setting is experimental and may be deleted. hints specify inlay hints that users want to see. | |
β£Β hoverKind |
hoverKind controls the information that appears in the hover text. | FullDocumentation |
β£Β importShortcut |
importShortcut specifies whether import statements should link to documentation or go to definitions. | Both |
β£Β linkTarget |
linkTarget controls where documentation links go. | pkg.go.dev |
β£Β linksInHover |
linksInHover toggles the presence of links to documentation in hover. | true |
β£Β local |
local is the equivalent of the goimports -local flag, which puts imports beginning with this string after third-party packages. |
|
β£Β matcher |
This is an advanced setting and should not be configured by most gopls users. matcher sets the algorithm that is used when calculating completion candidates. |
Fuzzy |
β£Β memoryMode |
This setting is experimental and may be deleted. obsolete, no effect | |
β£Β noSemanticNumber |
This setting is experimental and may be deleted. noSemanticNumber turns off the sending of the semantic token 'number' | false |
β£Β noSemanticString |
This setting is experimental and may be deleted. noSemanticString turns off the sending of the semantic token 'string' | false |
β£Β semanticTokens |
This setting is experimental and may be deleted. semanticTokens controls whether the LSP server will send semantic tokens to the client. | false |
β£Β standaloneTags |
standaloneTags specifies a set of build constraints that identify individual Go source files that make up the entire main package of an executable. | |
β£Β staticcheck |
This setting is experimental and may be deleted. staticcheck enables additional analyses from staticcheck.io. | false |
β£Β symbolMatcher |
This is an advanced setting and should not be configured by most gopls users. symbolMatcher sets the algorithm that is used when finding workspace symbols. |
FastFuzzy |
β£Β symbolScope |
symbolScope controls which packages are searched for workspace/symbol requests. | all |
β£Β symbolStyle |
This is an advanced setting and should not be configured by most gopls users. symbolStyle controls how symbols are qualified in symbol responses. |
Dynamic |
β£Β templateExtensions |
templateExtensions gives the extensions of file names that are treateed as template files. | |
β£Β usePlaceholders |
placeholders enables placeholders for function parameters or struct fields in completion responses. | false |
β£Β verboseOutput |
This setting is for debugging purposes only. verboseOutput enables additional debug logging. | false |
β£Β vulncheck |
This setting is experimental and may be deleted. vulncheck enables vulnerability scanning. | Off |
go.goplsPath |
Path to gopls bin (Change requires :CocRestart ) |
|
go.goplsUseDaemon |
Run gopls as daemon | true |
go.tags |
||
β£Β options |
Comma separated tag=options pairs to be used by go.tags.add command |
json=omitempty |
β£Β skipUnexported |
If true, skip unexported fields | false |
β£Β tags |
Comma separated tags to be used by go.tags.add command |
json |
β£Β transform |
Transformation rule used by go.tags.add command to add tags |
snakecase |
go.tests |
||
β£Β generateFlags |
Additional command line flags to pass to gotests for generating tests. |
[] |
go.trace.server |
Trace level of gopls | off |
Trigger completion in coc-settings.json
to get complete list.
{
"go.goplsOptions": {
"completeUnimported": true
}
}
- Run
npm run build
ornpm run build:watch
- Link extension:
npm run link
/npm run unlink
With coc-go
I do not aim to recreate the features of vim-go
. For now, the
main goal is to provide a convenient way to install gopls
and use it with
coc.nvim
.
If you need more than the features provided by gopls
, you are probably better
of with vim-go
or
govim
.
Add this to you (local) coc-settings.json
(run :CocLocalConfig
).
{
"go.goplsEnv": {
"GOOS": "js",
"GOARCH": "wasm",
}
}
coc-go
runs gopls
as shared daemon by passing -remote=auto
to gopls
. To
disable this behavior set go.goplsUseDaemon
to false
.
See Running gopls as a daemon for more information.