1.3.33 • Published 4 months ago

coc-go v1.3.33

Weekly downloads
1,263
License
MIT
Repository
github
Last release
4 months ago

coc-go

Go language server extension using gopls for coc.nvim.

Install

In your vim/neovim, run this command:

:CocInstall coc-go

Features

See gopls

Commands

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

KeyDescription
go.gopls.tidyRun gopls.tidy LSP command
go.impl.cursorGenerate interface stubs
go.install.gomodifytagsInstall / update gomodifytags
go.install.goplayInstall / update goplay
go.install.goplsInstall / update gopls
go.install.gotestsInstall / update gotests
go.install.implInstall / update impl
go.install.toolsInstall / update all tools
go.playgroundRun on go playground
go.tags.addAdd tags to struct fields
go.tags.add.lineAdd tags to struct field in current line
go.tags.add.promptAdd tags to struct fields (prompt)
go.tags.clearRemove all tags from struct fields
go.tags.clear.lineRemove all tags from struct fields in current line
go.tags.removeRemove tags from struct fields
go.tags.remove.lineRemove tags from struct field in current line
go.tags.remove.promptRemove tags from struct fields (prompt)
go.test.generate.exportedGenerate unit tests for exported functions in file
go.test.generate.fileGenerate unit tests for file
go.test.generate.functionGenerate unit tests for current function
go.test.toggleToggle test file
go.versionPrint 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 :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

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

Configuration options

KeyDescriptionDefault
go.checkForUpdatesCheck for gopls updates on start.install
go.disableDisable gopls features{}
‣ completionDisable completion feature (Change requires :CocRestart)false
‣ diagnosticsDisable handle diagnostics (Change requires :CocRestart)false
‣ featuresDisabled features (Change requires :CocRestart)[]
‣ snippetCompletionDisable snippet completion (Change requires :CocRestart)false
‣ workspaceFoldersDisable workspaceFolders feature (Change requires :CocRestart)false
go.enableEnable Go extensiontrue
go.goplsArgsArguments passed to gopls (Change requires :CocRestart)
go.goplsEnvENV passed to gopls (Change requires :CocRestart)
go.goplsOptionsSee gopls documentation
‣ allowImplicitNetworkAccessThis setting is experimental and may be deleted. allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module downloads rather than requiring user action.false
‣ allowModfileModificationsThis setting is experimental and may be deleted. allowModfileModifications disables -mod=readonly, allowing imports from out-of-scope modules.false
‣ analysesanalyses specify analyses that the user would like to enable or disable.
‣ analysisProgressReportinganalysisProgressReporting controls whether gopls sends progress notifications when construction of its index of analysis facts is taking a long time.true
‣ annotationsThis setting is experimental and may be deleted. annotations specifies the various kinds of optimization diagnostics that should be reported by the gc_details command.
‣ buildFlagsbuildFlags is the set of flags passed on to the build system when invoked.
‣ codelensescodelenses overrides the enabled/disabled state of code lenses.
‣ completeFunctionCallscompleteFunctionCalls enables function call completion.true
‣ completionBudgetThis setting is for debugging purposes only. completionBudget is the soft latency goal for completion requests.100ms
‣ diagnosticsDelayThis 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
‣ diagnosticsTriggerThis setting is experimental and may be deleted. diagnosticsTrigger controls when to run diagnostics.Edit
‣ directoryFiltersdirectoryFilters can be used to exclude unwanted directories from the workspace.
‣ envenv adds environment variables to external commands run by gopls, most notably go list.
‣ expandWorkspaceToModuleThis setting is experimental and may be deleted. expandWorkspaceToModule determines which packages are considered "workspace packages" when the workspace is using modules.true
‣ experimentalPostfixCompletionsThis setting is experimental and may be deleted. experimentalPostfixCompletions enables artificial method snippets such as "someSlice.sort!".true
‣ gofumptgofumpt indicates if we should run gofumpt formatting.false
‣ hintsThis setting is experimental and may be deleted. hints specify inlay hints that users want to see.
‣ hoverKindhoverKind controls the information that appears in the hover text.FullDocumentation
‣ importShortcutimportShortcut specifies whether import statements should link to documentation or go to definitions.Both
‣ linkTargetlinkTarget controls where documentation links go.pkg.go.dev
‣ linksInHoverlinksInHover toggles the presence of links to documentation in hover.true
‣ locallocal is the equivalent of the goimports -local flag, which puts imports beginning with this string after third-party packages.
‣ matcherThis 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
‣ memoryModeThis setting is experimental and may be deleted. obsolete, no effect
‣ noSemanticNumberThis setting is experimental and may be deleted. noSemanticNumber turns off the sending of the semantic token 'number'false
‣ noSemanticStringThis setting is experimental and may be deleted. noSemanticString turns off the sending of the semantic token 'string'false
‣ semanticTokensThis setting is experimental and may be deleted. semanticTokens controls whether the LSP server will send semantic tokens to the client.false
‣ standaloneTagsstandaloneTags specifies a set of build constraints that identify individual Go source files that make up the entire main package of an executable.
‣ staticcheckThis setting is experimental and may be deleted. staticcheck enables additional analyses from staticcheck.io.false
‣ symbolMatcherThis 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
‣ symbolScopesymbolScope controls which packages are searched for workspace/symbol requests.all
‣ symbolStyleThis is an advanced setting and should not be configured by most gopls users. symbolStyle controls how symbols are qualified in symbol responses.Dynamic
‣ templateExtensionstemplateExtensions gives the extensions of file names that are treateed as template files.
‣ usePlaceholdersplaceholders enables placeholders for function parameters or struct fields in completion responses.false
‣ verboseOutputThis setting is for debugging purposes only. verboseOutput enables additional debug logging.false
‣ vulncheckThis setting is experimental and may be deleted. vulncheck enables vulnerability scanning.Off
go.goplsPathPath to gopls bin (Change requires :CocRestart)
go.goplsUseDaemonRun gopls as daemontrue
go.tags
‣ optionsComma separated tag=options pairs to be used by go.tags.add commandjson=omitempty
‣ skipUnexportedIf true, skip unexported fieldsfalse
‣ tagsComma separated tags to be used by go.tags.add commandjson
‣ transformTransformation rule used by go.tags.add command to add tagssnakecase
go.tests
‣ generateFlagsAdditional command line flags to pass to gotests for generating tests.[]
go.trace.serverTrace level of goplsoff

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

Example Configuration

{
  "go.goplsOptions": {
    "completeUnimported": true
  }
}

Development

  1. Run npm run build or npm run build:watch
  2. Link extension: npm run link / npm run unlink

Tools

FAQ

How does coc-go compare to vim-go?

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.

How to use coc-go with wasm?

Add this to you (local) coc-settings.json (run :CocLocalConfig).

{
  "go.goplsEnv": {
    "GOOS": "js",
    "GOARCH": "wasm",
  }
}

Running gopls as a daemon

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.

License

MIT © Josa Gesell.

1.3.33

4 months ago

1.3.32

5 months ago

1.3.31

5 months ago

1.3.18

9 months ago

1.3.19

9 months ago

1.3.20

9 months ago

1.3.21

9 months ago

1.3.24

8 months ago

1.3.25

7 months ago

1.3.22

8 months ago

1.3.23

8 months ago

1.3.28

6 months ago

1.3.29

5 months ago

1.3.26

7 months ago

1.3.27

6 months ago

1.3.30

5 months ago

1.3.14

1 year ago

1.3.17

12 months ago

1.3.15

12 months ago

1.3.16

12 months ago

1.3.13

1 year ago

1.3.10

1 year ago

1.3.11

1 year ago

1.3.12

1 year ago

1.3.9

1 year ago

1.3.8

1 year ago

1.3.7

1 year ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.2.0

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.13.3

3 years ago

0.13.2

3 years ago

0.13.0

3 years ago

0.13.1

3 years ago

0.12.1

3 years ago

0.12.0

4 years ago

0.11.0

4 years ago

0.10.0

4 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.0

4 years ago

0.9.1

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago