1

I am using Sublime Text with the LSP-gopls plugin for Go development and I have a custom GOPATH set: $HOME/Code/go instead of $HOME/go.

However, every time I run Sublime Text, the directory go/pkg/mod/... is created in the $HOME directory. Normally, LSP-gopls should store these files in the directory specified in $GOPATH, but it uses the default directory.

How can it be fixed?

I'm convinced it's LSP-gopls, because this behavior disappears when I disable it, delete the directory in $HOME, and restart Sublime Text. I have export GOPATH=$HOME/Code/go in .zshrc. In the plugin settings, the custom path to gopls is set "command" : ["/Users/user/Code/go/bin/gopls"].

  • 2
    `GOPATH` is not used in "modern" (like, 3-4 last years) Go which operates on so-called [modules](https://go.dev/ref/mod). You might want to set [`GOCACHE`](https://pkg.go.dev/cmd/go#hdr-Build_and_test_caching) instead. – kostix Aug 28 '23 at 14:08
  • 1
    Thank you, @kostix. Your answer brought me to a decision. Turns out I needed to set `$GOMODCACHE` in LSP-golsp settings. `"settings":{"gopls.env":{"GOMODCACHE":"/Users/user/Code/go/pkg/mod"}}` – Modern Fears Aug 28 '23 at 20:11
  • 1
    I do not know what you're after exactly, but just in case I should note that while that setting will be respected by `gopls`, it won't be respected by `go build` (ostensibly also if somehow called from within Sublime Text), so given the limited context, it seems more sensible to override such settings on a per-user level (say, in your ~/.whateverrc). "The trick" with caching this stuff is that it's versioned and so every call to Go tooling can reuse this information as appropriate. – kostix Aug 29 '23 at 12:28
  • Thank you. This is an important addition! – Modern Fears Aug 29 '23 at 13:28

1 Answers1

2

Turns out I needed to set $GOMODCACHE in LSP-golsp settings.

"settings": {
  "gopls.env": {"GOMODCACHE":"/Users/user/Code/go/pkg/mod"}
}