build: add setup_env to all.bash and update contributing.md

That can be used to install all the tools vscode-go test depends
on. We use this new command in build/Dockerfile and also,
reference in the contribution guideline.

We can also consider changing .github/workflows/* to use this
command. But I am not yet sure how to reuse it in Windows yet.

Change-Id: I328707ab4c60428e67ef43f99d5d533a6fa5f211
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/253749
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/build/Dockerfile b/build/Dockerfile
index bebc26a..026e667 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -4,8 +4,11 @@
 
 ENV GO111MODULE on
 ENV GOBIN /gobin
-ENV GOPROXY https://proxy.golang.org
-RUN cd $(mktemp -d) && go get golang.org/x/tools/gopls@latest
+
+# Install other Go tools tests depend on
+RUN mkdir -p /scratch/build
+ADD build/all.bash /scratch/build/all.bash
+RUN /scratch/build/all.bash setup_env
 
 FROM node:latest
 
@@ -20,20 +23,5 @@
 
 RUN apt-get update && apt-get install -y libnss3 libgtk-3-dev libxss1 libasound2 xvfb libsecret-1-0
 
-# Install other Go tools tests depend on
-RUN GO111MODULE=on go get -x -v github.com/acroca/go-symbols && \
-	GO111MODULE=on go get -x -v github.com/cweill/gotests/... && \
-	GO111MODULE=on go get -x -v github.com/davidrjenni/reftools/cmd/fillstruct && \
-	GO111MODULE=on go get -x -v	github.com/haya14busa/goplay/cmd/goplay && \
-	GO111MODULE=on go get -x -v github.com/mdempsky/gocode && \
-	GO111MODULE=on go get -x -v github.com/ramya-rao-a/go-outline && \
-	GO111MODULE=on go get -x -v github.com/rogpeppe/godef && \
-	GO111MODULE=on go get -x -v github.com/sqs/goreturns && \
-	GO111MODULE=on go get -x -v github.com/uudashr/gopkgs/v2/cmd/gopkgs && \
-	GO111MODULE=on go get -x -v github.com/zmb3/gogetdoc && \
-	GO111MODULE=on go get -x -v golang.org/x/lint/golint && \
-	GO111MODULE=on go get -x -v golang.org/x/tools/cmd/gorename && \
-	GO111MODULE=on go get -x -v github.com/go-delve/delve/cmd/dlv
-
 WORKDIR /workspace
 ENTRYPOINT ["build/all.bash"]
diff --git a/build/all.bash b/build/all.bash
index 10c3110..13fa205 100755
--- a/build/all.bash
+++ b/build/all.bash
@@ -11,6 +11,7 @@
   help      - display this help message.
   test      - build and test locally. Some tests may fail if vscode is already in use.
   testlocal - build and test in a locally built container.
+  setup_env - setup environment for test. This installs tools under GOPATH/bin.
   ci        - build and test with headless vscode. Requires Xvfb.
 EOUSAGE
 }
@@ -88,6 +89,24 @@
   cp build/nightly/const.ts src/const.ts
 }
 
+# setup dependencies required for tests.
+install_dependencies() {
+	GO111MODULE=on go get -x -v golang.org/x/tools/gopls
+	GO111MODULE=on go get -x -v github.com/acroca/go-symbols
+	GO111MODULE=on go get -x -v github.com/cweill/gotests/...
+	GO111MODULE=on go get -x -v github.com/davidrjenni/reftools/cmd/fillstruct
+	GO111MODULE=on go get -x -v github.com/haya14busa/goplay/cmd/goplay
+	GO111MODULE=on go get -x -v github.com/mdempsky/gocode
+	GO111MODULE=on go get -x -v github.com/ramya-rao-a/go-outline
+	GO111MODULE=on go get -x -v github.com/rogpeppe/godef
+	GO111MODULE=on go get -x -v github.com/sqs/goreturns
+	GO111MODULE=on go get -x -v github.com/uudashr/gopkgs/v2/cmd/gopkgs
+	GO111MODULE=on go get -x -v github.com/zmb3/gogetdoc
+	GO111MODULE=on go get -x -v golang.org/x/lint/golint
+	GO111MODULE=on go get -x -v golang.org/x/tools/cmd/gorename
+	GO111MODULE=on go get -x -v github.com/go-delve/delve/cmd/dlv
+}
+
 main() {
   cd "$(root_dir)"  # always run from the script root.
   case "$1" in
@@ -110,6 +129,9 @@
     "prepare_nightly")
       prepare_nightly
       ;;
+    "setup_env")
+      install_dependencies
+      ;;
     *)
       usage
       exit 2
diff --git a/docs/contributing.md b/docs/contributing.md
index 752b32d..5fe1cad 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -62,6 +62,15 @@
 
 ## Test
 
+Simple unit tests that do not require interaction with VS Code are located in `test/unit`. 
+Tests in `test/integration` and `test/gopls` directories are integration tests. They involve invocation of the VS Code API and 
+require external Go tools installed in `GOPATH`. The command `setup_env` in [`build/all.bash`](https://github.com/golang/vscode-go/blob/master/build/all.bash)
+installs all the tool dependencies in `GOPATH`. 
+
+1. `export GOPATH=/path/to/gopath/for/test`
+1. `build/all.bash setup_env`
+1. Unfortunately, VS Code test framework inherits your user settings when running tests [Issue 43](https://github.com/golang/vscode-go/issues/43). Make sure VS Code user settings do not contain any go related configuration, except `go.gopath` or `go.toolsGopath` in case you installed the tools for testing in a different `GOPATH`.
+
 There are currently three test launch configurations: (1) `Launch Extension Tests`, (2) `Launch Extension Tests with Gopls`, and (3) `Launch Unit Tests`. To run the tests locally, open the Run view (`Ctrl+Shift+D`), select the relevant launch configuration, and hit the Play button (`F5`).
 
 ## Sideload