zed icon indicating copy to clipboard operation
zed copied to clipboard

Cannot install gopls when Go is not in the default env path

Open jacobbednarz opened this issue 3 years ago • 19 comments

Before you begin Check the backlog of issues to reduce the chances of creating duplicates; if an issue already exists, place a +1 (👍) on it.

Describe the bug

When opening a Golang file, I encounter the following error.

Language server error: Go

failed to install gopls. Is go installed?

To reproduce

  • Use asdf-vm to install Go
  • Ensure it is correctly setup
  • Attempt to open a Golang file
  • See error reported

Expected behavior

  • Go file opens and gopls can be installed (or use the existing one on my $PATH

Screenshots If applicable, add screenshots to help explain your problem.

Environment:

Zed 0.45.0 – /Applications/Zed.app macOS 12.4 architecture x86_64

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jacob/Library/Caches/go-build"
GOENV="/Users/jacob/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jacob/.asdf/installs/golang/1.17.9/packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jacob/.asdf/installs/golang/1.17.9/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/jacob/.asdf/installs/golang/1.17.9/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/jacob/.asdf/installs/golang/1.17.9/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.9"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jacob/go/src/github.com/cloudflare/cloudflare-go/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/36/zlscnhfn27n1yxx52cr1kdmr0000gp/T/go-build632993627=/tmp/go-build -gno-record-gcc-switches -fno-common"
$ which go gopls
/Users/jacob/.asdf/shims/go
/Users/jacob/.asdf/shims/gopls

Is there a way I can manually work around this in the meantime? Either by downloading the language server manually or forcing it in? Docs state Go isn't yet supported but the invite email said it was so unsure if this is still in progress.

jacobbednarz avatar Jul 06 '22 20:07 jacobbednarz

We really need to include more details about the installation failure.

Zed is basically running this command to install gopls:

GO111MODULE=on GOBIN=~/.zed/gopls/gobin go install golang.org/x/tools/gopls@latest
mv ~/.zed/gopls/gobin/gopls ~/.zed/gopls/gopls_0.9.0

Other environment variables such as PATH should be set up to match the parent shell environment (if you started Zed via the CLI) or the environment variables set on startup of your default shell (if you launched Zed from Finder).

If you get a chance, I'd be curious what output you get if you run that command manually.

maxbrunsfeld avatar Jul 06 '22 20:07 maxbrunsfeld

running those two manually then opening zed . works

$ GO111MODULE=on GOBIN=~/.zed/gopls/gobin go install golang.org/x/tools/gopls@latest
go: downloading golang.org/x/tools/gopls v0.9.0
go: downloading golang.org/x/tools v0.1.11
go: downloading golang.org/x/tools v0.1.12-0.20220630195555-6178576f8ba1
go: downloading honnef.co/go/tools v0.3.2

$ mv ~/.zed/gopls/gobin/gopls ~/.zed/gopls/gopls_0.9.0
$ zed .

another tidbit to include here is that my env has GOPROXY unset for this directory, however, when firing up zed, it thinks the value is GOPROXY=off (which is my global). is this inheriting the env from somewhere globally as opposed to locally? that would explain why asdf-vm wasn't working too.

jacobbednarz avatar Jul 06 '22 21:07 jacobbednarz

running those two manually then opening zed . works

Interesting, thanks for the update!

is this inheriting the env from somewhere globally as opposed to locally?

Actually yes; I was incorrect in my earlier comment. We currently always just load environment variables from your default login shell, as opposed to capturing the environment variables from the zed CLI process.

So in this case, do you think GOPROXY being set to off was the reason for the installation failure?

maxbrunsfeld avatar Jul 06 '22 21:07 maxbrunsfeld

if i'm following correctly, i think the GOPROXY=off is a symptom of the larger issue of not loading the correct environment when calling zed .. due to the environment not loading correctly, go and gopls weren't detected (even though both were installed via asdf-vm) and subsequently, the environment variables were incorrect.

jacobbednarz avatar Jul 06 '22 21:07 jacobbednarz

I see, so go would not be on your PATH without detecting the environment from the shell that called zed ?

maxbrunsfeld avatar Jul 06 '22 21:07 maxbrunsfeld

correct. as asdf-vm is responsible for loading/unloading the environment ($PATH, $GO..), if i have a project specific version and launch zed from inside that directory, it won't have the correct paths resulting in binaries missing.

does GOBIN (from the commands above) ever pick up the value from the env if it is defined? reusing that may help here too if it doesn't already.

jacobbednarz avatar Jul 06 '22 21:07 jacobbednarz

does GOBIN (from the commands above) ever pick up the value from the env if it is defined? reusing that may help here too if it doesn't already.

We currently always try to install language servers ourselves, rather than looking for existing binaries, but we could add logic for finding existing language servers on your system.

maxbrunsfeld avatar Jul 06 '22 21:07 maxbrunsfeld

that would be rad; potentially save debugging version mismatches or why the language server in editor doesn't match the CLI invocation. will leave it up to you though 👍

thanks for the speedy support! you folks rock.

jacobbednarz avatar Jul 06 '22 22:07 jacobbednarz

What's the workaround for this issue with zed 0.75.2+?

rrpolanco avatar Mar 10 '23 16:03 rrpolanco

Is there a way to connect to lsp server remotely? I am using docker development environment to keep my host clean, so I can't install gopls on host machine. I am currently trying to install gopls into container and somehow trick zed to use it via docker volumes, but no luck so far. Also I guess there could be option to specify remote flag in lsp config in settings, but I believe it still would require existence of gopls on host system.

Someone trying to achieve setup like this with VSCode

zlpkhr avatar May 11 '23 09:05 zlpkhr

@zlpkhr this isn't possible right now. Feel free to upvote

  • https://github.com/zed-industries/zed/issues/5347.

hovsater avatar May 11 '23 11:05 hovsater

gopls is not compatible with golang version before 1.16. try upgrading golang first, it works for me

Before you begin Check the backlog of issues to reduce the chances of creating duplicates; if an issue already exists, place a +1 (👍) on it.

Describe the bug

When opening a Golang file, I encounter the following error.

Language server error: Go

failed to install gopls. Is go installed?

To reproduce

  • Use asdf-vm to install Go
  • Ensure it is correctly setup
  • Attempt to open a Golang file
  • See error reported

Expected behavior

  • Go file opens and gopls can be installed (or use the existing one on my $PATH

Screenshots If applicable, add screenshots to help explain your problem.

Environment:

Zed 0.45.0 – /Applications/Zed.app macOS 12.4 architecture x86_64

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jacob/Library/Caches/go-build"
GOENV="/Users/jacob/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jacob/.asdf/installs/golang/1.17.9/packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jacob/.asdf/installs/golang/1.17.9/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/jacob/.asdf/installs/golang/1.17.9/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/jacob/.asdf/installs/golang/1.17.9/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.9"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jacob/go/src/github.com/cloudflare/cloudflare-go/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/36/zlscnhfn27n1yxx52cr1kdmr0000gp/T/go-build632993627=/tmp/go-build -gno-record-gcc-switches -fno-common"
$ which go gopls
/Users/jacob/.asdf/shims/go
/Users/jacob/.asdf/shims/gopls

Is there a way I can manually work around this in the meantime? Either by downloading the language server manually or forcing it in? Docs state Go isn't yet supported but the invite email said it was so unsure if this is still in progress.

gopls is not compatible with golang version before 1.16. try upgrading golang first, it works for me

coooold avatar Aug 11 '23 08:08 coooold

@coooold i think you may have misread here. the go version used in this example is 1.17 so gopls is definitely available.

jacobbednarz avatar Aug 11 '23 09:08 jacobbednarz

I'll share my solution. Today, I downloaded support for Rust and Go programming language server. The Rust setup didn't work initially, but after using "workspace restart", Rust started working.

As for Go, I struggled with it for at least 20 attempts, going back and forth with the issue. Finally, by chance, it worked.

I performed the following steps:

// Navigated to the directory: 
cd ~/Library/Application\ Support/Zed/languages

// Removed the gopls directory: 
rm -dr gopls

// command + shift + p, and search restart 
run "workspace restart"

After following these steps, Go started working successfully. If you encounter permission issues, you can use sudo zed {your-go-project} and then follow the same steps mentioned above.

springzero avatar Sep 13 '23 07:09 springzero

I didn't encounter any permissions issue but the sudo zed . fixed the issue for me. Thanks @springzero

maxyurk avatar Sep 16 '23 08:09 maxyurk

MacOS 11.6.2 (20G314) Zed 0.106.2

image

I encountered a similar issue where Zed couldn't find the "go" command when starting. This might be due to Zed not having access to the complete $PATH. To resolve my issue, I used the following approach:

  1. create a openzed.app from Automator (Run Shell Script)
source ~/.zshrc && zed
  1. open openzed.app

laojianzi avatar Oct 10 '23 06:10 laojianzi

Can confirm these were still necessary w/ Zed 0.110.2

At this point, gopls is 0.14.2

$ GO111MODULE=on GOBIN=~/.zed/gopls/gobin go install golang.org/x/tools/gopls@latest
$ mv ~/.zed/gopls/gobin/gopls ~/.zed/gopls/gopls_0.14.1
$ zed .

lukeed avatar Nov 04 '23 02:11 lukeed

Encountering the same issue. Running sudo zed . in my application directory seemed to work. Any reason why sudo is required to make it work?

cyberbeast avatar Jan 26 '24 15:01 cyberbeast

Hey there 👋 I'm pretty sure the issue you're having where you need to run Zed via sudo is this issue where somehow the folder we install language servers into gets the wrong permissions:

  • https://github.com/zed-industries/zed/issues/5085

ForLoveOfCats avatar Feb 05 '24 19:02 ForLoveOfCats