1

Using go go1.10.2 darwin/amd64 together with glide 0.13.1. Dependencies are in the vendor directory. There is no error building from the command line. When viewing the code in VS Code, the following error is displayed:

Cannot find package "github.com/xxx/go-utility/log" in any of:

/usr/local/Cellar/go/1.10.2/libexec/src/github.com/xxx/go-utility/log (from $GOROOT) /Users/martin/go/src/github.com/xxx/go-utility/log (from $GOPATH)

Both the terminal and the VS Console report GOPATH="/Users/martin/go"

I expect that I can make the message go away if I issue a go get, but this defeats the purpose of the vendor directory.

This is a new installation on a new computer.

What configuration have I forgotten?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Martin Flower
  • 353
  • 4
  • 14
  • Where are your project code and the vendor directory located? – JimB May 21 '18 at 13:54
  • `/Users/martin/go/src/xxxdc.visualstudio.com/enlightcentre/reports/backend` – Martin Flower May 21 '18 at 15:07
  • `/Users/martin/go/src/xxxdc.visualstudio.com/enlightcentre/reports/backend/vendor/github.com/xxx/go-utility` – Martin Flower May 21 '18 at 15:08
  • That looks correct at first glance, are you sure there's no symlinks in that path? (you can quickly check from the project directory with `pwd -P`, which should match the paths above exactly)? – JimB May 21 '18 at 15:12
  • yes, there are symlinks in the path – Martin Flower May 21 '18 at 15:26
  • You can't have symlinks in your GOPATH. It seems that Go is resolving the package location, sees it's not in the workspace, so it doesn't look for a vendor directory. – JimB May 21 '18 at 15:28
  • I have just deleted the symlink and copied over all the files so the directory paths are now symlink-free. The project builds continues to build successfully from the command line. Visual Studio Code continues to report exactly the same problem. – Martin Flower May 21 '18 at 15:35
  • Does it build correctly when you use the package name, i.e. `go build xxxdc.visualstudio.com/enlightcentre/reports/backend`? I'm not sure what's different in your VSC setup, but the lack of checking for a vendor path means that it's not seeing the package directory as being properly located under GOPATH. – JimB May 21 '18 at 15:39
  • pwd `/Users/martin/go/src/xxxdc.visualstudio.com/enlightcentre/reports/backend/cmd/compliance/getnoncompliantassets` – Martin Flower May 21 '18 at 15:45
  • `go build xxxdc.visualstudio.com/enlightcentre/reports/backend/cmd/compliance/getnoncompliantassets` – Martin Flower May 21 '18 at 15:45
  • I note that in Visual Studio Code, the vendor directory is slightly darker - suggesting that it maybe should not be considered in the same way as the other source directories. I expect this is expected behaviour. – Martin Flower May 21 '18 at 15:49
  • How VSC highlights the directory could be from any plugin, e.g. git has changes in that path. I don't use VSC, but just started it up and no `vendor/` directories are shaded any differently. – JimB May 21 '18 at 15:53
  • I've just gone through these steps with a clean project (Hello World), and Visual Studio Code successfully finds the vendor dependencies, and the vendor directory is the same colour as the other directories. I have now deleted `vendor` from reports/.gitignore, and the VS Code error has now disappeared. – Martin Flower May 21 '18 at 18:39

1 Answers1

2

As reported on vscode-go github issue 1587 my solution was to add the following to user settings (Code > Preferences > Settings)

{ "search.useIgnoreFiles": false }
Martin Flower
  • 353
  • 4
  • 14