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 | ‣ `analyses` | **EXPERIMENTAL** analyses specify analyses that the user would like to enable or disable. | |
90 | ‣ `annotations` | **EXPERIMENTAL** annotations suppress various kinds of optimization diagnostics that would be reported by the gc_details command. | |
91 | ‣ `buildFlags` | buildFlags is the set of flags passed on to the build system when invoked. | |
92 | ‣ `codelens` | **EXPERIMENTAL** codelens overrides the enabled/disabled state of code lenses. | |
93 | ‣ `completeUnimported` | **EXPERIMENTAL** completeUnimported enables completion for packages that you do not currently import. | true |
94 | ‣ `completionDocumentation` | **EXPERIMENTAL** completionDocumentation enables documentation with completion results. | true |
95 | ‣ `deepCompletion` | **EXPERIMENTAL** deepCompletion enables the ability to return completions from deep inside relevant entities, rather than just the locally accessible ones. | true |
96 | ‣ `env` | env adds environment variables to external commands run by `gopls`, most notably `go list`. | |
97 | ‣ `expandWorkspaceToModule` | **EXPERIMENTAL** expandWorkspaceToModule instructs `gopls` to expand the scope of the workspace to include the modules containing the workspace folders. | true |
98 | ‣ `experimentalDiagnosticsDelay` | **EXPERIMENTAL** experimentalDiagnosticsDelay controls the amount of time that gopls waits after the most recent file modification before computing deep diagnostics. | 0s |
99 | ‣ `experimentalPackageCacheKey` | **EXPERIMENTAL** experimentalPackageCacheKey controls whether to use a coarser cache key for package type information to increase cache hits. | true |
100 | ‣ `experimentalWorkspaceModule` | **EXPERIMENTAL** experimentalWorkspaceModule opts a user into the experimental support for multi-module workspaces. | false |
101 | ‣ `gofumpt` | gofumpt indicates if we should run gofumpt formatting. | false |
102 | ‣ `hoverKind` | hoverKind controls the information that appears in the hover text. | FullDocumentation |
103 | ‣ `importShortcut` | **EXPERIMENTAL** importShortcut specifies whether import statements should link to documentation or go to definitions. | Both |
104 | ‣ `linkTarget` | linkTarget controls where documentation links go. | pkg.go.dev |
105 | ‣ `linksInHover` | **EXPERIMENTAL** linksInHover toggles the presence of links to documentation in hover. | true |
106 | ‣ `local` | local is the equivalent of the `goimports -local` flag, which puts imports beginning with this string after 3rd-party packages. | |
107 | ‣ `matcher` | **EXPERIMENTAL** matcher sets the algorithm that is used when calculating completion candidates. | Fuzzy |
108 | ‣ `semanticTokens` | **EXPERIMENTAL** semanticTokens controls whether the LSP server will send semantic tokens to the client. | false |
109 | ‣ `staticcheck` | **EXPERIMENTAL** staticcheck enables additional analyses from staticcheck.io. | false |
110 | ‣ `symbolMatcher` | **EXPERIMENTAL** symbolMatcher sets the algorithm that is used when finding workspace symbols. | Fuzzy |
111 | ‣ `symbolStyle` | **EXPERIMENTAL** symbolStyle controls how symbols are qualified in symbol responses. | Package |
112 | ‣ `tempModfile` | **EXPERIMENTAL** tempModfile controls the use of the -modfile flag in Go 1.14. | true |
113 | ‣ `usePlaceholders` | placeholders enables placeholders for function parameters or struct fields in completion responses. | false |
114 | ‣ `verboseWorkDoneProgress` | **EXPERIMENTAL** verboseWorkDoneProgress controls whether the LSP server should send progress reports for all work done outside the scope of an RPC. | 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).