internal/lsp: better handling of .in files

This walks the list produced by the MustCopyFileTree call instead of
scanning the file system
It also removes the .in file from the copies, so only the trimmed
version will be present in the exported data set.

Change-Id: I95b0298ab49021a09f6b26e08158ce162b5a99e6
Reviewed-on: https://go-review.googlesource.com/c/149614
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go
index 8099328..9de3887 100644
--- a/internal/lsp/lsp_test.go
+++ b/internal/lsp/lsp_test.go
@@ -7,7 +7,6 @@
 import (
 	"context"
 	"go/token"
-	"io/ioutil"
 	"path/filepath"
 	"reflect"
 	"sort"
@@ -28,21 +27,10 @@
 	const dir = "testdata"
 
 	files := packagestest.MustCopyFileTree(dir)
-	subdirs, err := ioutil.ReadDir(dir)
-	if err != nil {
-		t.Fatal(err)
-	}
-	for _, subdir := range subdirs {
-		if !subdir.IsDir() {
-			continue
-		}
-		dirpath := filepath.Join(dir, subdir.Name())
-		if testFiles, err := ioutil.ReadDir(dirpath); err == nil {
-			for _, file := range testFiles {
-				if trimmed := strings.TrimSuffix(file.Name(), ".in"); trimmed != file.Name() {
-					files[filepath.Join(subdir.Name(), trimmed)] = packagestest.Copy(filepath.Join(dirpath, file.Name()))
-				}
-			}
+	for fragment, operation := range files {
+		if trimmed := strings.TrimSuffix(fragment, ".in"); trimmed != fragment {
+			delete(files, fragment)
+			files[trimmed] = operation
 		}
 	}
 	modules := []packagestest.Module{