internal/gopathwalk: ignore $GOROOT/.../vendor/ in module mode

go list in module mode doesn't like looking at vendor directories in
GOROOT. Skip them.

Change-Id: Iec501fbab70914ea6dd76dcbed97ecda461358d0
Reviewed-on: https://go-review.googlesource.com/c/148159
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/gopathwalk/walk.go b/internal/gopathwalk/walk.go
index dc085fc..a561f9f 100644
--- a/internal/gopathwalk/walk.go
+++ b/internal/gopathwalk/walk.go
@@ -11,12 +11,13 @@
 	"bytes"
 	"fmt"
 	"go/build"
-	"golang.org/x/tools/internal/fastwalk"
 	"io/ioutil"
 	"log"
 	"os"
 	"path/filepath"
 	"strings"
+
+	"golang.org/x/tools/internal/fastwalk"
 )
 
 // Options controls the behavior of a Walk call.
@@ -176,7 +177,9 @@
 	if typ == os.ModeDir {
 		base := filepath.Base(path)
 		if base == "" || base[0] == '.' || base[0] == '_' ||
-			base == "testdata" || (!w.opts.ModulesEnabled && base == "node_modules") {
+			base == "testdata" ||
+			(w.root.Type == RootGOROOT && w.opts.ModulesEnabled && base == "vendor") ||
+			(!w.opts.ModulesEnabled && base == "node_modules") {
 			return filepath.SkipDir
 		}
 		fi, err := os.Lstat(path)