Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Build, Install, Debug when using modules under GOPATH #2238
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Mar 12, 2019
1 parent 058eccf commit 15f571e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class Delve {
let dlvArgs = [mode || 'debug'];
if (mode === 'exec') {
dlvArgs = dlvArgs.concat([program]);
} else if (currentGOWorkspace) {
} else if (currentGOWorkspace && env['GO111MODULE'] !== 'on') {
dlvArgs = dlvArgs.concat([dirname.substr(currentGOWorkspace.length + 1)]);
}
dlvArgs = dlvArgs.concat(['--headless=true', '--listen=' + host + ':' + port.toString()]);
Expand Down
12 changes: 8 additions & 4 deletions src/goBuild.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import path = require('path');
import vscode = require('vscode');
import { getToolsEnvVars, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath, getCurrentGoPath, getTempFilePath } from './util';
import { getToolsEnvVars, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath, getCurrentGoPath, getTempFilePath, getModuleCache } from './util';
import { outputChannel } from './goStatus';
import os = require('os');
import { getNonVendorPackages } from './goPackages';
import { getTestFlags } from './testUtils';
import { getCurrentGoWorkspaceFromGOPATH } from './goPath';
Expand Down Expand Up @@ -53,7 +52,7 @@ export function buildCode(buildWorkspace?: boolean) {
* @param goConfig Configuration for the Go extension.
* @param buildWorkspace If true builds code in all workspace.
*/
export function goBuild(fileUri: vscode.Uri, isMod: boolean, goConfig: vscode.WorkspaceConfiguration, buildWorkspace?: boolean): Promise<ICheckResult[]> {
export async function goBuild(fileUri: vscode.Uri, isMod: boolean, goConfig: vscode.WorkspaceConfiguration, buildWorkspace?: boolean): Promise<ICheckResult[]> {
epoch++;
let closureEpoch = epoch;
if (tokenSource) {
Expand All @@ -74,6 +73,11 @@ export function goBuild(fileUri: vscode.Uri, isMod: boolean, goConfig: vscode.Wo
return Promise.resolve([]);
}

// Skip building if cwd is in the module cache
if (isMod && cwd.startsWith(getModuleCache())) {
return [];
}

const buildEnv = Object.assign({}, getToolsEnvVars());
const tmpPath = getTempFilePath('go-code-check');
const isTestFile = fileUri && fileUri.fsPath.endsWith('_test.go');
Expand Down Expand Up @@ -115,7 +119,7 @@ export function goBuild(fileUri: vscode.Uri, isMod: boolean, goConfig: vscode.Wo

// Find the right importPath instead of directly using `.`. Fixes https://github.com/Microsoft/vscode-go/issues/846
let currentGoWorkspace = getCurrentGoWorkspaceFromGOPATH(getCurrentGoPath(), cwd);
let importPath = currentGoWorkspace ? cwd.substr(currentGoWorkspace.length + 1) : '.';
let importPath = (currentGoWorkspace && !isMod) ? cwd.substr(currentGoWorkspace.length + 1) : '.';
running = true;
outputChannel.appendLine(`Starting building the current package at ${cwd}`);
return runTool(
Expand Down
14 changes: 11 additions & 3 deletions src/goInstall.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path = require('path');
import vscode = require('vscode');
import { getToolsEnvVars, getCurrentGoPath, getBinPath } from './util';
import { getToolsEnvVars, getCurrentGoPath, getBinPath, getModuleCache } from './util';
import { outputChannel } from './goStatus';
import { getCurrentGoWorkspaceFromGOPATH } from './goPath';
import cp = require('child_process');
import { isModSupported } from './goModules';

export function installCurrentPackage() {
export async function installCurrentPackage(): Promise<void> {
let editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showInformationMessage('No editor is active, cannot find current package to install');
Expand All @@ -24,6 +25,13 @@ export function installCurrentPackage() {

const env = Object.assign({}, getToolsEnvVars());
const cwd = path.dirname(editor.document.uri.fsPath);
const isMod = await isModSupported(editor.document.uri);

// Skip installing if cwd is in the module cache
if (isMod && cwd.startsWith(getModuleCache())) {
return;
}

const goConfig = vscode.workspace.getConfiguration('go', editor.document.uri);
const buildFlags = goConfig['buildFlags'] || [];
const args = ['install', ...buildFlags];
Expand All @@ -34,7 +42,7 @@ export function installCurrentPackage() {

// Find the right importPath instead of directly using `.`. Fixes https://github.com/Microsoft/vscode-go/issues/846
const currentGoWorkspace = getCurrentGoWorkspaceFromGOPATH(getCurrentGoPath(), cwd);
const importPath = currentGoWorkspace ? cwd.substr(currentGoWorkspace.length + 1) : '.';
let importPath = (currentGoWorkspace && !isMod) ? cwd.substr(currentGoWorkspace.length + 1) : '.';
args.push(importPath);

outputChannel.clear();
Expand Down

0 comments on commit 15f571e

Please sign in to comment.