I am trying to install the Go tools in Visual Studio Code and am getting the following error when installing gopls:
Tools environment: GOPATH=/Users/jal/go
Installing 1 tool at /Users/jal/go/bin in module mode.
gopls
Installing golang.org/x/tools/gopls@latest FAILED
{
"killed": false,
"code": 2,
"signal": null,
"cmd": "/opt/brew/bin/go install -v golang.org/x/tools/gopls@latest",
"stdout": "",
"stderr": "golang.org/x/tools/internal/fastwalk\n# golang.org/x/tools/internal/fastwalk\n../../go/pkg/mod/golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2/internal/fastwalk/fastwalk_darwin.go:11:10: fatal error: 'dirent.h' file not found\n#include <dirent.h>\n ^~~~~~~~~~\n1 error generated.\n"
}
1 tools failed to install.
gopls: failed to install gopls(golang.org/x/tools/gopls@latest): Error: Command failed: /opt/brew/bin/go install -v golang.org/x/tools/gopls@latest
golang.org/x/tools/internal/fastwalk
# golang.org/x/tools/internal/fastwalk
../../go/pkg/mod/golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2/internal/fastwalk/fastwalk_darwin.go:11:10: fatal error: 'dirent.h' file not found
#include <dirent.h>
^~~~~~~~~~
1 error generated.
I know I have dirent.h
because I see results in my local Xcode SDKs when running find / -iregex ".*/dirent.h$" 2>/dev/null
.
I am following the steps here: https://learn.microsoft.com/en-us/azure/developer/go/configure-visual-studio-code
My setup is:
- Fresh install of go from Homebrew
- Fresh install of VSCode macOS from go.dev/doc/install
- Instal the Go plugin
- In the Command Palette, search for and select "Go: Install/Update tools" and select all tools in the dropdown
All tools are installed successfully except for gopls. I have installed go via Homebrew and have also installed gopls via Homebrew but am not sure how to configure VSCode to point to this alternative gopls path.