src/goCover.ts: provide explicit directory for running go list

go list needs to run to discover the correspondence between the
import paths used in coverage files, and the file names used in
vscode. This invocation used to have an optional working directory,
which is quite fragile. The change uses the workspaceFolder associated
with the open .go file.

This change adds a scope to go.coverShowCounts in package.json,
to silence a long-ignored error message.

Fixes https://github.com/golang/vscode-go/issues/610

Change-Id: I59e02244c84fbdc6fc38ea919c5ee0623d37d1b0
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/253600
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/package.json b/package.json
index 02b740c..9c29c30 100644
--- a/package.json
+++ b/package.json
@@ -1327,7 +1327,8 @@
         "go.coverShowCounts": {
           "type": "boolean",
           "default": false,
-          "description": "When generating code coverage, should counts be shown as --374--"
+          "description": "When generating code coverage, should counts be shown as --374--",
+          "scope": "resource"
         },
         "go.coverageOptions": {
           "type": "string",
diff --git a/src/goCover.ts b/src/goCover.ts
index aca37e2..0d90ede 100644
--- a/src/goCover.ts
+++ b/src/goCover.ts
@@ -205,9 +205,9 @@
  * Extract the coverage data from the given cover profile & apply them on the files in the open editors.
  * @param coverProfilePath Path to the file that has the cover profile data
  * @param packageDirPath Absolute path of the package for which the coverage was calculated
- * @param testDir Directory to execute go list in, when there is no workspace, for some tests
+ * @param dir Directory to execute go list in
  */
-export function applyCodeCoverageToAllEditors(coverProfilePath: string, testDir?: string): Promise<void> {
+export function applyCodeCoverageToAllEditors(coverProfilePath: string, dir: string): Promise<void> {
 	const v = new Promise<void>((resolve, reject) => {
 		try {
 			const showCounts = getGoConfig().get('coverShowCounts') as boolean;
@@ -254,7 +254,7 @@
 				coveragePath.set(parse[1], coverage);
 			});
 
-			getImportPathToFolder([...seenPaths], testDir)
+			getImportPathToFolder([...seenPaths], dir)
 				.then((pathsToDirs) => {
 					createCoverageData(pathsToDirs, coveragePath);
 					setDecorators();
diff --git a/src/goMain.ts b/src/goMain.ts
index affaa01..860a6ed 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -461,7 +461,7 @@
 						updateWorkspaceState(lastCoverProfilePathKey, coverProfilePath);
 					}
 					applyCodeCoverageToAllEditors(
-						coverProfilePath
+						coverProfilePath, getWorkspaceFolderPath(vscode.window.activeTextEditor.document.uri)
 					);
 				});
 		})