| 1 | --- |
| 2 | title: "Gopls: Using Helix" |
| 3 | --- |
| 4 | |
| 5 | Configuring `gopls` to work with Helix is rather straightforward. Install `gopls`, and then add it to the `PATH` variable. If it is in the `PATH` variable, Helix will be able to detect it automatically. |
| 6 | |
| 7 | The documentation explaining how to install the default language servers for Helix can be found [here](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers) |
| 8 | |
| 9 | ## Installing `gopls` |
| 10 | |
| 11 | The first step is to install `gopls` on your machine. |
| 12 | You can follow installation instructions [here](https://github.com/golang/tools/tree/master/gopls#installation). |
| 13 | |
| 14 | ## Setting your path to include `gopls` |
| 15 | |
| 16 | Set your `PATH` environment variable to point to `gopls`. |
| 17 | If you used `go install` to download `gopls`, it should be in `$GOPATH/bin`. |
| 18 | If you don't have `GOPATH` set, you can use `go env GOPATH` to find it. |
| 19 | |
| 20 | ## Additional information |
| 21 | |
| 22 | You can find more information about how to set up the LSP formatter [here](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers#autoformatting). |
| 23 | |
| 24 | It is possible to use `hx --health go` to see that the language server is properly set up. |
| 25 | |
| 26 | ### Configuration |
| 27 | |
| 28 | The settings for `gopls` can be configured in the `languages.toml` file. |
| 29 | The official Helix documentation for this can be found [here](https://docs.helix-editor.com/languages.html) |
| 30 | |
| 31 | Configuration pertaining to `gopls` should be in the table `language-server.gopls`. |
| 32 | |
| 33 | #### How to set flags |
| 34 | |
| 35 | To set flags, add them to the `args` array in the `language-server.gopls` section of the `languages.toml` file. |
| 36 | |
| 37 | #### How to set LSP configuration |
| 38 | |
| 39 | Configuration options can be set in the `language-server.gopls.config` section of the `languages.toml` file, or in the `config` key of the `language-server.gopls` section of the `languages.toml` file. |
| 40 | |
| 41 | #### A minimal config example |
| 42 | |
| 43 | In the `~/.config/helix/languages.toml` file, the following snippet would set up `gopls` with a logfile located at `/tmp/gopls.log` and enable staticcheck. |
| 44 | |
| 45 | ```toml |
| 46 | [language-server.gopls] |
| 47 | command = "gopls" |
| 48 | args = ["-logfile=/tmp/gopls.log", "serve"] |
| 49 | [language-server.gopls.config] |
| 50 | "ui.diagnostic.staticcheck" = true |
| 51 | ``` |
| 52 | |
| 53 |