11import path = require( 'path' ) ;
22import vscode = require( 'vscode' ) ;
3- import { getToolsEnvVars , runTool , ICheckResult , handleDiagnosticErrors , getWorkspaceFolderPath , getCurrentGoPath , getTempFilePath } from './util' ;
3+ import { getToolsEnvVars , runTool , ICheckResult , handleDiagnosticErrors , getWorkspaceFolderPath , getCurrentGoPath , getTempFilePath , getModuleCache } from './util' ;
44import { outputChannel } from './goStatus' ;
5- import os = require( 'os' ) ;
65import { getNonVendorPackages } from './goPackages' ;
76import { getTestFlags } from './testUtils' ;
87import { getCurrentGoWorkspaceFromGOPATH } from './goPath' ;
@@ -53,7 +52,7 @@ export function buildCode(buildWorkspace?: boolean) {
5352 * @param goConfig Configuration for the Go extension.
5453 * @param buildWorkspace If true builds code in all workspace.
5554 */
56- export function goBuild ( fileUri : vscode . Uri , isMod : boolean , goConfig : vscode . WorkspaceConfiguration , buildWorkspace ?: boolean ) : Promise < ICheckResult [ ] > {
55+ export async function goBuild ( fileUri : vscode . Uri , isMod : boolean , goConfig : vscode . WorkspaceConfiguration , buildWorkspace ?: boolean ) : Promise < ICheckResult [ ] > {
5756 epoch ++ ;
5857 let closureEpoch = epoch ;
5958 if ( tokenSource ) {
@@ -74,6 +73,11 @@ export function goBuild(fileUri: vscode.Uri, isMod: boolean, goConfig: vscode.Wo
7473 return Promise . resolve ( [ ] ) ;
7574 }
7675
76+ // Skip building if cwd is in the module cache
77+ if ( isMod && cwd . startsWith ( getModuleCache ( ) ) ) {
78+ return [ ] ;
79+ }
80+
7781 const buildEnv = Object . assign ( { } , getToolsEnvVars ( ) ) ;
7882 const tmpPath = getTempFilePath ( 'go-code-check' ) ;
7983 const isTestFile = fileUri && fileUri . fsPath . endsWith ( '_test.go' ) ;
@@ -115,7 +119,7 @@ export function goBuild(fileUri: vscode.Uri, isMod: boolean, goConfig: vscode.Wo
115119
116120 // Find the right importPath instead of directly using `.`. Fixes https://github.com/Microsoft/vscode-go/issues/846
117121 let currentGoWorkspace = getCurrentGoWorkspaceFromGOPATH ( getCurrentGoPath ( ) , cwd ) ;
118- let importPath = currentGoWorkspace ? cwd . substr ( currentGoWorkspace . length + 1 ) : '.' ;
122+ let importPath = ( currentGoWorkspace && ! isMod ) ? cwd . substr ( currentGoWorkspace . length + 1 ) : '.' ;
119123 running = true ;
120124 outputChannel . appendLine ( `Starting building the current package at ${ cwd } ` ) ;
121125 return runTool (
0 commit comments