massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-go / README.md
1 # coc-go
2
3 Go language server extension using [`gopls`](https://github.com/golang/go/wiki/gopls)
4 for [`coc.nvim`](https://github.com/neoclide/coc.nvim).
5
6 ## Install
7
8 In your vim/neovim, run this command:
9
10 ```
11 :CocInstall coc-go
12 ```
13
14 ## Features
15
16 See [`gopls`](https://github.com/golang/tools/blob/master/gopls/README.md)
17
18 ## Commands
19
20 Additional to commands provided by gopls, this extensions provides these commands:
21
22 | Key                             | Description                                        |
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                            |
45
46 ### Examples
47
48 - **Add or Remove specific tags**
49
50   ```
51   CocCommand go.tags.add yaml
52   CocCommand go.tags.add yaml json xml
53   CocCommand go.tags.remove xml
54   ```
55
56 - **Add missing imports on save**
57
58   ```viml
59   autocmd BufWritePre *.go :silent call CocAction('runCommand', 'editor.action.organizeImport')
60   ```
61
62 - **Map Keys to command**
63
64   ```viml
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>
68   ```
69
70 ## Snippets
71
72 Snippets are imported from [`golang/vscode-go`](https://github.com/microsoft/vscode-go)
73 and require [`coc-snippets`](https://github.com/neoclide/coc-snippets) to be
74 installed.
75
76 ## Configuration options
77
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 | ‣ `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.                                       | 250ms             |
97 | ‣ `directoryFilters`               | directoryFilters can be used to exclude unwanted directories from the workspace.                                                                                                                                                                                    |                   |
98 | ‣ `env`                            | env adds environment variables to external commands run by `gopls`, most notably `go list`.                                                                                                                                                                         |                   |
99 | ‣ `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              |
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 | ‣ `experimentalPostfixCompletions` | **This setting is experimental and may be deleted.**  experimentalPostfixCompletions enables artifical method snippets such as "someSlice.sort!".                                                                                                                   | true              |
102 | ‣ `experimentalTemplateSupport`    | **This setting is experimental and may be deleted.**  experimentalTemplateSupport opts into the experimental support for template files.                                                                                                                            | false             |
103 | ‣ `experimentalUseInvalidMetadata` | **This setting is experimental and may be deleted.**  experimentalUseInvalidMetadata enables gopls to fall back on outdated package metadata to provide editor features if the go command fails to load packages for some reason (like an invalid go.mod file).     | false             |
104 | ‣ `experimentalWatchedFileDelay`   | **This setting is experimental and may be deleted.**  experimentalWatchedFileDelay controls the amount of time that gopls waits for additional workspace/didChangeWatchedFiles notifications to arrive, before processing all such notifications in a single batch. | 0s                |
105 | ‣ `experimentalWorkspaceModule`    | **This setting is experimental and may be deleted.**  experimentalWorkspaceModule opts a user into the experimental support for multi-module workspaces.                                                                                                            | false             |
106 | ‣ `gofumpt`                        | gofumpt indicates if we should run gofumpt formatting.                                                                                                                                                                                                              | false             |
107 | ‣ `hoverKind`                      | hoverKind controls the information that appears in the hover text.                                                                                                                                                                                                  | FullDocumentation |
108 | ‣ `importShortcut`                 | importShortcut specifies whether import statements should link to documentation or go to definitions.                                                                                                                                                               | Both              |
109 | ‣ `linkTarget`                     | linkTarget controls where documentation links go.                                                                                                                                                                                                                   | pkg.go.dev        |
110 | ‣ `linksInHover`                   | linksInHover toggles the presence of links to documentation in hover.                                                                                                                                                                                               | true              |
111 | ‣ `local`                          | local is the equivalent of the `goimports -local` flag, which puts imports beginning with this string after third-party packages.                                                                                                                                   |                   |
112 | ‣ `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             |
113 | ‣ `memoryMode`                     | **This setting is experimental and may be deleted.**  memoryMode controls the tradeoff `gopls` makes between memory usage and correctness.                                                                                                                          | Normal            |
114 | ‣ `semanticTokens`                 | **This setting is experimental and may be deleted.**  semanticTokens controls whether the LSP server will send semantic tokens to the client.                                                                                                                       | false             |
115 | ‣ `staticcheck`                    | **This setting is experimental and may be deleted.**  staticcheck enables additional analyses from staticcheck.io.                                                                                                                                                  | false             |
116 | ‣ `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             |
117 | ‣ `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           |
118 | ‣ `usePlaceholders`                | placeholders enables placeholders for function parameters or struct fields in completion responses.                                                                                                                                                                 | false             |
119 | ‣ `verboseOutput`                  | **This setting is for debugging purposes only.**  verboseOutput enables additional debug logging.                                                                                                                                                                   | false             |
120 | **`go.goplsPath`**                 | Path to `gopls` bin (Change requires `:CocRestart`)                                                                                                                                                                                                                 |                   |
121 | **`go.goplsUseDaemon`**            | Run gopls as daemon                                                                                                                                                                                                                                                 | true              |
122 | **`go.tags`**                      |                                                                                                                                                                                                                                                                     |                   |
123 | ‣ `options`                        | Comma separated tag=options pairs to be used by `go.tags.add` command                                                                                                                                                                                               | json=omitempty    |
124 | ‣ `skipUnexported`                 | If true, skip unexported fields                                                                                                                                                                                                                                     | false             |
125 | ‣ `tags`                           | Comma separated tags to be used by `go.tags.add` command                                                                                                                                                                                                            | json              |
126 | ‣ `transform`                      | Transformation rule used by `go.tags.add` command to add tags                                                                                                                                                                                                       | snakecase         |
127 | **`go.tests`**                     |                                                                                                                                                                                                                                                                     |                   |
128 | ‣ `generateFlags`                  | Additional command line flags to pass to `gotests` for generating tests.                                                                                                                                                                                            | []                |
129 | **`go.trace.server`**              | Trace level of gopls                                                                                                                                                                                                                                                | off               |
130
131 Trigger completion in `coc-settings.json` to get complete list.
132
133 ### Example Configuration
134
135 ```json
136 {
137   "go.goplsOptions": {
138     "completeUnimported": true
139   }
140 }
141 ```
142
143 ## Development
144
145 1. Run `yarn build` or `yarn build:watch`
146 2. Link extension: `yarn run link` / `yarn run unlink`
147
148 ## Tools
149
150 - [`gomodifytags`](http://github.com/fatih/gomodifytags) - [BSD](https://github.com/fatih/gomodifytags/blob/master/LICENSE)
151 - [`goplay`](http://github.com/haya14busa/goplay) - [MIT](https://github.com/haya14busa/goplay/blob/master/LICENSE)
152 - [`gopls`](https://golang.org/x/tools/cmd/gopls)
153 - [`gotests`](http://github.com/cweill/gotests) - [Apache](https://github.com/cweill/gotests/blob/develop/LICENSE)
154 - [`impl`](https://github.com/josharian/impl) - [MIT](https://github.com/josharian/impl/blob/master/LICENSE.txt)
155
156 ## FAQ
157
158 ### How does `coc-go` compare to `vim-go`?
159
160 With `coc-go` I do not aim to recreate the features of `vim-go`. For now, the
161 main goal is to provide a convenient way to install `gopls` and use it with
162 `coc.nvim`.
163
164 If you need more than the features provided by `gopls`, you are probably better
165 of with [`vim-go`](https://github.com/fatih/vim-go) or
166 [`govim`](https://github.com/govim/govim).
167
168 ### How to use `coc-go` with wasm?
169
170 Add this to you (local) `coc-settings.json` (run `:CocLocalConfig`).
171
172 ```json
173 {
174   "go.goplsEnv": {
175     "GOOS": "js",
176     "GOARCH": "wasm",
177   }
178 }
179 ```
180
181 ### Running `gopls` as a daemon
182
183 `coc-go` runs `gopls` as shared daemon by passing `-remote=auto` to `gopls`. To
184 disable this behavior set `go.goplsUseDaemon` to `false`.
185
186 See [Running gopls as a daemon](https://github.com/golang/tools/blob/master/gopls/doc/daemon.md) for more information.
187
188 ## License
189
190 [MIT © Josa Gesell](LICENSE).