Home > Blockchain >  VSCode Go extension Error loading workspace with private repository dependency
VSCode Go extension Error loading workspace with private repository dependency

Time:11-10

Everything was working fine until I added a dependency of a private repository. I noticed that autocomplete stopped working and there was an error notification by vscode:

Error loading workspace: err: exit status 1: stderr: go:
bitbucket.org/my-group/my-private-repo@v0.0.0-20210512194559-2c29669c4ecc: 
reading https://api.bitbucket.org/2.0/repositories/my-group/my-private-repo?fields=scm: 
403 Forbidden server response: Access denied. You must have write or admin access. 
go: bitbucket.org/my-group/my-private-repo@v0.0.0-20210512194559-2c29669c4ecc: 
reading https://api.bitbucket.org/2.0/repositories/my-group/my-private-repo?fields=scm: 
403 Forbidden server response: Access denied. You must have write or admin access. 
: packages.Load error

It seems like the go extension is trying to access my private repo:

  1. Why is this necessary for code competition to be able to work?
  2. If it is necessary, how do I provide my SSH-key to the go extension?
  3. Other workaround?

CodePudding user response:

  1. It attempts to get the sources for your dependency so it can generate the actual suggestions for your. It wants to load the source go module style and I am guessing you have your dependency located in the GOPATH. You would hope it would gracefully handle the connection errors and still provide completions for the code it can access, so maybe this is a bug, consider creating an issue on github(I don't know which project).
  2. In this case it is, also by doing the following fix you will be able to use go mod for private dependencies as well instead of having to manually manage dependencies the "old fashion" way. Go modules uses Git by default, you can instruct git to always use SSH instead of HTTPS by adding the following to your global git config file:
[url "[email protected]:"]
    insteadOf = https://bitbucket.org/

Your private key should be used automatically, assuming you don't require any special config for normal git over ssh operations.

  1. Go modules supports inclusion of dependencies via the vendor directory. If you place your dependency in there the code completion should use it instead of trying to download it. But I can't confirm this, have never tried it
  • Related