gosublimetextsublime-text-plugingopls

LSP-gopls in Sublime Text creates go directory in $HOME instead of a custom location


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"].


Solution

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

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