3 Go language server extension using [`gopls`](https://github.com/golang/go/wiki/gopls)
4 for [`coc.nvim`](https://github.com/neoclide/coc.nvim).
8 In your vim/neovim, run this command:
16 See [`gopls`](https://github.com/golang/tools/blob/master/gopls/README.md)
20 Additional to commands provided by gopls, this extensions provides these commands:
23 |---------------------------------|----------------------------------------------------|
24 | **`go.impl.cursor`** | Generate interface stubs |
25 | **`go.install.gomodifytags`** | Install / update gomodifytags |
26 | **`go.install.goplay`** | Install / update goplay |
27 | **`go.install.gopls`** | Install / update gopls |
28 | **`go.install.gotests`** | Install / update gotests |
29 | **`go.install.impl`** | Install / update impl |
30 | **`go.install.tools`** | Install / update all tools |
31 | **`go.playground`** | Run on go playground |
32 | **`go.tags.add`** | Add tags to struct fields |
33 | **`go.tags.add.line`** | Add tags to struct field in current line |
34 | **`go.tags.add.prompt`** | Add tags to struct fields (prompt) |
35 | **`go.tags.clear`** | Remove all tags from struct fields |
36 | **`go.tags.clear.line`** | Remove all tags from struct fields in current line |
37 | **`go.tags.remove`** | Remove tags from struct fields |
38 | **`go.tags.remove.line`** | Remove tags from struct field in current line |
39 | **`go.tags.remove.prompt`** | Remove tags from struct fields (prompt) |
40 | **`go.test.generate.exported`** | Generate unit tests for exported functions in file |
41 | **`go.test.generate.file`** | Generate unit tests for file |
42 | **`go.test.generate.function`** | Generate unit tests for current function |
43 | **`go.test.toggle`** | Toggle test file |
44 | **`go.version`** | Print extension version |
48 - **Add or Remove specific tags**
51 CocCommand go.tags.add yaml
52 CocCommand go.tags.add yaml json xml
53 CocCommand go.tags.remove xml
56 - **Add missing imports on save**
59 autocmd BufWritePre *.go :silent call CocAction('runCommand', 'editor.action.organizeImport')
62 - **Map Keys to command**
65 autocmd FileType go nmap gtj :CocCommand go.tags.add json<cr>
66 autocmd FileType go nmap gty :CocCommand go.tags.add yaml<cr>
67 autocmd FileType go nmap gtx :CocCommand go.tags.clear<cr>
72 Snippets are imported from [`microsoft/vscode-go`](https://github.com/microsoft/vscode-go)
73 and require [`coc-snippets`](https://github.com/neoclide/coc-snippets) to be
76 ## Configuration options
78 | Key | Description | Default |
79 |----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|
80 | **`go.checkForUpdates`** | **EXPERIMENTAL** Check for gopls updates on start. | disabled |
81 | **`go.disable`** | Disable gopls features | {} |
82 | ‣ `completion` | Disable completion feature (Change requires `:CocRestart`) | false |
83 | ‣ `diagnostics` | Disable handle diagnostics (Change requires `:CocRestart`) | false |
84 | ‣ `workspaceFolders` | Disable workspaceFolders feature (Change requires `:CocRestart`) | false |
85 | **`go.enable`** | Enable Go extension | true |
86 | **`go.goplsArgs`** | Arguments passed to `gopls` (Change requires `:CocRestart`) | |
87 | **`go.goplsEnv`** | ENV passed to `gopls` (Change requires `:CocRestart`) | |
88 | **`go.goplsOptions`** | See [`gopls` documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md ) | |
89 | ‣ `allowImplicitNetworkAccess` | **This setting is experimental and may be deleted.** allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module downloads rather than requiring user action. | false |
90 | ‣ `allowModfileModifications` | **This setting is experimental and may be deleted.** allowModfileModifications disables -mod=readonly, allowing imports from out-of-scope modules. | false |
91 | ‣ `analyses` | analyses specify analyses that the user would like to enable or disable. | |
92 | ‣ `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. | |
93 | ‣ `buildFlags` | buildFlags is the set of flags passed on to the build system when invoked. | |
94 | ‣ `codelenses` | codelenses overrides the enabled/disabled state of code lenses. | |
95 | ‣ `completionBudget` | **This setting is for debugging purposes only.** completionBudget is the soft latency goal for completion requests. | 100ms |
96 | ‣ `directoryFilters` | directoryFilters can be used to exclude unwanted directories from the workspace. | |
97 | ‣ `env` | env adds environment variables to external commands run by `gopls`, most notably `go list`. | |
98 | ‣ `expandWorkspaceToModule` | **This setting is experimental and may be deleted.** expandWorkspaceToModule instructs `gopls` to adjust the scope of the workspace to find the best available module root. | true |
99 | ‣ `experimentalDiagnosticsDelay` | **This setting is experimental and may be deleted.** experimentalDiagnosticsDelay controls the amount of time that gopls waits after the most recent file modification before computing deep diagnostics. | 250ms |
100 | ‣ `experimentalPackageCacheKey` | **This setting is experimental and may be deleted.** experimentalPackageCacheKey controls whether to use a coarser cache key for package type information to increase cache hits. | true |
101 | ‣ `experimentalWorkspaceModule` | **This setting is experimental and may be deleted.** experimentalWorkspaceModule opts a user into the experimental support for multi-module workspaces. | false |
102 | ‣ `gofumpt` | gofumpt indicates if we should run gofumpt formatting. | false |
103 | ‣ `hoverKind` | hoverKind controls the information that appears in the hover text. | FullDocumentation |
104 | ‣ `importShortcut` | importShortcut specifies whether import statements should link to documentation or go to definitions. | Both |
105 | ‣ `linkTarget` | linkTarget controls where documentation links go. | pkg.go.dev |
106 | ‣ `linksInHover` | linksInHover toggles the presence of links to documentation in hover. | true |
107 | ‣ `local` | local is the equivalent of the `goimports -local` flag, which puts imports beginning with this string after third-party packages. | |
108 | ‣ `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 |
109 | ‣ `semanticTokens` | **This setting is experimental and may be deleted.** semanticTokens controls whether the LSP server will send semantic tokens to the client. | false |
110 | ‣ `staticcheck` | **This setting is experimental and may be deleted.** staticcheck enables additional analyses from staticcheck.io. | false |
111 | ‣ `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. | Fuzzy |
112 | ‣ `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 |
113 | ‣ `usePlaceholders` | placeholders enables placeholders for function parameters or struct fields in completion responses. | false |
114 | ‣ `verboseOutput` | **This setting is for debugging purposes only.** verboseOutput enables additional debug logging. | false |
115 | **`go.goplsPath`** | Path to `gopls` bin (Change requires `:CocRestart`) | |
116 | **`go.goplsUseDaemon`** | Run gopls as daemon | true |
117 | **`go.tags`** | | |
118 | ‣ `options` | Comma separated tag=options pairs to be used by `go.tags.add` command | json=omitempty |
119 | ‣ `skipUnexported` | If true, skip unexported fields | false |
120 | ‣ `tags` | Comma separated tags to be used by `go.tags.add` command | json |
121 | ‣ `transform` | Transformation rule used by `go.tags.add` command to add tags | snakecase |
122 | **`go.tests`** | | |
123 | ‣ `generateFlags` | Additional command line flags to pass to `gotests` for generating tests. | [] |
124 | **`go.trace.server`** | Trace level of gopls | off |
126 Trigger completion in `coc-settings.json` to get complete list.
128 ### Example Configuration
133 "completeUnimported": true
140 1. Run `yarn build` or `yarn build:watch`
141 2. Link extension: `yarn run link` / `yarn run unlink`
145 - [`gomodifytags`](http://github.com/fatih/gomodifytags) - [BSD](https://github.com/fatih/gomodifytags/blob/master/LICENSE)
146 - [`goplay`](http://github.com/haya14busa/goplay) - [MIT](https://github.com/haya14busa/goplay/blob/master/LICENSE)
147 - [`gopls`](https://golang.org/x/tools/cmd/gopls)
148 - [`gotests`](http://github.com/cweill/gotests) - [Apache](https://github.com/cweill/gotests/blob/develop/LICENSE)
149 - [`impl`](https://github.com/josharian/impl) - [MIT](https://github.com/josharian/impl/blob/master/LICENSE.txt)
153 ### How does `coc-go` compare to `vim-go`?
155 With `coc-go` I do not aim to recreate the features of `vim-go`. For now, the
156 main goal is to provide a convenient way to install `gopls` and use it with
159 If you need more than the features provided by `gopls`, you are probably better
160 of with [`vim-go`](https://github.com/fatih/vim-go) or
161 [`govim`](https://github.com/govim/govim).
163 ### How to use `coc-go` with wasm?
165 Add this to you (local) `coc-settings.json` (run `:CocLocalConfig`).
176 ### Running `gopls` as a daemon
178 `coc-go` runs `gopls` as shared daemon by passing `-remote=auto` to `gopls`. To
179 disable this behavior set `go.goplsUseDaemon` to `false`.
181 See [Running gopls as a daemon](https://github.com/golang/tools/blob/master/gopls/doc/daemon.md) for more information.
185 [MIT © Josa Gesell](LICENSE).