From 00f688e0c9e0dc2a4a589b305f8daf5ce75cbea8 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 15 Aug 2019 11:17:12 -0400 Subject: [PATCH 1/9] install Go tools using modules --- go.mod | 5 ++++ go.sum | 10 +++++++ src/goInstallTools.ts | 63 ++++++++++++++++++++++++++++++------------- src/util.ts | 5 ++++ 4 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 000000000..854fa045c --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/stamblerre/vscode-go + +go 1.12 + +require golang.org/x/tools/gopls v0.1.3 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..2bc61b486 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190710153321-831012c29e42 h1:4IOeC7p+OItq3+O5BWkcmVu2uBe3jekXau5S4QZX9DU= +golang.org/x/tools v0.0.0-20190710153321-831012c29e42/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= +golang.org/x/tools/gopls v0.1.3 h1:CB5ECiPysqZrwxcyRjN+exyZpY0gODTZvNiqQi3lpeo= +golang.org/x/tools/gopls v0.1.3/go.mod h1:vrCQzOKxvuiZLjCKSmbbov04oeBQQOb4VQqwYK2PWIY= diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 148edc1c3..54a33bb8a 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -6,11 +6,12 @@ 'use strict'; import vscode = require('vscode'); +import os = require('os'); import fs = require('fs'); import path = require('path'); import cp = require('child_process'); import { showGoStatus, hideGoStatus, outputChannel } from './goStatus'; -import { getBinPath, getToolsGopath, getGoVersion, SemVersion, isVendorSupported, getCurrentGoPath, resolvePath } from './util'; +import { getBinPath, getToolsGopath, getGoVersion, SemVersion, isVendorSupported, getCurrentGoPath, resolvePath, isBelow } from './util'; import { goLiveErrorsEnabled } from './goLiveErrors'; import { getToolFromToolPath, envPath } from './goPath'; @@ -40,7 +41,7 @@ const allToolsWithImportPaths: { [key: string]: string } = { 'golangci-lint': 'github.com/golangci/golangci-lint/cmd/golangci-lint', 'revive': 'github.com/mgechev/revive', 'go-langserver': 'github.com/sourcegraph/go-langserver', - 'gopls': 'golang.org/x/tools/cmd/gopls', + 'gopls': 'golang.org/x/tools/gopls', 'dlv': 'github.com/go-delve/delve/cmd/dlv', 'fillstruct': 'github.com/davidrjenni/reftools/cmd/fillstruct', 'godoctor': 'github.com/godoctor/godoctor', @@ -311,7 +312,18 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< return; } - envForTools['GO111MODULE'] = 'off'; + // If the user is on Go >= 1.11, tools should be installed with modules enabled. + // This ensures that users get the latest tagged version, rather than master, + // which may be unstable. + let modulesOn = false; + if (isBelow(goVersion, 11)) { + envForTools['GO111MODULE'] = 'off'; + // Explicitly disable the proxy, as older versions of Go will not understand it. + envForTools['GOPROXY'] = ''; + } else { + envForTools['GO111MODULE'] = 'on'; + modulesOn = true; + } outputChannel.show(); outputChannel.clear(); @@ -323,7 +335,7 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< outputChannel.appendLine(''); // Blank line for spacing. return missing.reduce((res: Promise, tool: string) => { - return res.then(sofar => new Promise((resolve, reject) => { + return res.then(sofar => new Promise((resolve) => { const callback = (err: Error, stdout: string, stderr: string) => { if (err) { outputChannel.appendLine('Installing ' + getToolImportPath(tool, goVersion) + ' FAILED'); @@ -369,21 +381,36 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< resolve([...sofar, null]); return; } - const args = ['get', '-u', '-v']; - if (tool.endsWith('-gomod')) { - args.push('-d'); - } - args.push(getToolImportPath(tool, goVersion)); - cp.execFile(goRuntimePath, args, { env: envForTools }, (err, stdout, stderr) => { - if (stderr.indexOf('unexpected directory layout:') > -1) { - outputChannel.appendLine(`Installing ${tool} failed with error "unexpected directory layout". Retrying...`); - cp.execFile(goRuntimePath, args, { env: envForTools }, callback); - } else if (!err && tool.endsWith('-gomod')) { - const outputFile = path.join(toolsGopath, 'bin', process.platform === 'win32' ? `${tool}.exe` : tool); - cp.execFile(goRuntimePath, ['build', '-o', outputFile, getToolImportPath(tool, goVersion)], { env: envForTools }, callback); - } else { - callback(err, stdout, stderr); + // Install tools in a temporary directory, to avoid altering go.mod files. + fs.mkdtemp(path.join(os.tmpdir(), 'go-tools-'), (err, toolsTmpDir) => { + if (err) { + resolve([...sofar, null]); + return; } + const args = ['get', '-v']; + // Only get tools at master if we are not using modules. + if (!modulesOn) { + args.push('-u'); + } + if (tool.endsWith('-gomod')) { + args.push('-d'); + } + let opts = { + env: envForTools, + cwd: toolsTmpDir, + }; + args.push(getToolImportPath(tool, goVersion)); + cp.execFile(goRuntimePath, args, opts, (err, stdout, stderr) => { + if (stderr.indexOf('unexpected directory layout:') > -1) { + outputChannel.appendLine(`Installing ${tool} failed with error "unexpected directory layout". Retrying...`); + cp.execFile(goRuntimePath, args, opts, callback); + } else if (!err && tool.endsWith('-gomod')) { + const outputFile = path.join(toolsGopath, 'bin', process.platform === 'win32' ? `${tool}.exe` : tool); + cp.execFile(goRuntimePath, ['build', '-o', outputFile, getToolImportPath(tool, goVersion)], opts, callback); + } else { + callback(err, stdout, stderr); + } + }); }); }); })); diff --git a/src/util.ts b/src/util.ts index 66e369187..a64280cac 100644 --- a/src/util.ts +++ b/src/util.ts @@ -81,6 +81,11 @@ let vendorSupport: boolean = null; let telemtryReporter: TelemetryReporter; let toolsGopath: string; +// Assumes the Go version is always 1.x. +export function isBelow(goVersion: SemVersion, minor: number): boolean { + return goVersion && goVersion.major === 1 && goVersion.minor < minor; +} + export function byteOffsetAt(document: vscode.TextDocument, position: vscode.Position): number { const offset = document.offsetAt(position); const text = document.getText(); From 6bc74d1a7a34202020f2b1fd8918ee7a6c0b0a10 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 15 Aug 2019 11:17:25 -0400 Subject: [PATCH 2/9] remove go.mod/sum files --- go.mod | 2 -- go.sum | 10 ---------- 2 files changed, 12 deletions(-) diff --git a/go.mod b/go.mod index 854fa045c..f927f573f 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/stamblerre/vscode-go go 1.12 - -require golang.org/x/tools/gopls v0.1.3 // indirect diff --git a/go.sum b/go.sum index 2bc61b486..e69de29bb 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +0,0 @@ -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190710153321-831012c29e42 h1:4IOeC7p+OItq3+O5BWkcmVu2uBe3jekXau5S4QZX9DU= -golang.org/x/tools v0.0.0-20190710153321-831012c29e42/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= -golang.org/x/tools/gopls v0.1.3 h1:CB5ECiPysqZrwxcyRjN+exyZpY0gODTZvNiqQi3lpeo= -golang.org/x/tools/gopls v0.1.3/go.mod h1:vrCQzOKxvuiZLjCKSmbbov04oeBQQOb4VQqwYK2PWIY= From 44ee7971c87fc22a3a8c531c9057c80c6bf897f5 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 15 Aug 2019 11:20:03 -0400 Subject: [PATCH 3/9] actually remove go.mod/sum --- go.mod | 3 --- go.sum | 0 2 files changed, 3 deletions(-) delete mode 100644 go.mod delete mode 100644 go.sum diff --git a/go.mod b/go.mod deleted file mode 100644 index f927f573f..000000000 --- a/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/stamblerre/vscode-go - -go 1.12 diff --git a/go.sum b/go.sum deleted file mode 100644 index e69de29bb..000000000 From dccd6d65ece47e07c3131a774d1bdc5243fdd563 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 15 Aug 2019 13:09:43 -0400 Subject: [PATCH 4/9] disable modules for tools with wildcard import paths --- src/goInstallTools.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 54a33bb8a..cdcc8c4f5 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -315,14 +315,9 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< // If the user is on Go >= 1.11, tools should be installed with modules enabled. // This ensures that users get the latest tagged version, rather than master, // which may be unstable. - let modulesOn = false; + let modulesOff = false; if (isBelow(goVersion, 11)) { - envForTools['GO111MODULE'] = 'off'; - // Explicitly disable the proxy, as older versions of Go will not understand it. - envForTools['GOPROXY'] = ''; - } else { - envForTools['GO111MODULE'] = 'on'; - modulesOn = true; + modulesOff = true; } outputChannel.show(); @@ -335,6 +330,14 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< outputChannel.appendLine(''); // Blank line for spacing. return missing.reduce((res: Promise, tool: string) => { + // Disable modules for staticcheck and gotests, + // which are installed with the "..." wildcard. + // TODO: ... will be supported in Go 1.13, so enable these tools to use modules then. + if (modulesOff || tool === "staticcheck" || tool === "gotests") { + envForTools['GO111MODULE'] = 'off'; + } else { + envForTools['GO111MODULE'] = 'on'; + } return res.then(sofar => new Promise((resolve) => { const callback = (err: Error, stdout: string, stderr: string) => { if (err) { @@ -389,7 +392,7 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< } const args = ['get', '-v']; // Only get tools at master if we are not using modules. - if (!modulesOn) { + if (modulesOff) { args.push('-u'); } if (tool.endsWith('-gomod')) { From f59a1448e48ebaa19514edd6cd0ad50760f0c8ed Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 16 Aug 2019 19:39:18 -0400 Subject: [PATCH 5/9] resolve comments --- src/goInstallTools.ts | 8 ++++++-- src/util.ts | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index cdcc8c4f5..4c9e6e1ee 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -11,7 +11,10 @@ import fs = require('fs'); import path = require('path'); import cp = require('child_process'); import { showGoStatus, hideGoStatus, outputChannel } from './goStatus'; -import { getBinPath, getToolsGopath, getGoVersion, SemVersion, isVendorSupported, getCurrentGoPath, resolvePath, isBelow } from './util'; +import { + getBinPath, getToolsGopath, getGoVersion, SemVersion, isVendorSupported, getCurrentGoPath, + resolvePath, isBelow, rmdirRecursive +} from './util'; import { goLiveErrorsEnabled } from './goLiveErrors'; import { getToolFromToolPath, envPath } from './goPath'; @@ -316,7 +319,7 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< // This ensures that users get the latest tagged version, rather than master, // which may be unstable. let modulesOff = false; - if (isBelow(goVersion, 11)) { + if (isBelow(goVersion, 1, 11)) { modulesOff = true; } @@ -414,6 +417,7 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< callback(err, stdout, stderr); } }); + rmdirRecursive(toolsTmpDir); }); }); })); diff --git a/src/util.ts b/src/util.ts index a64280cac..e7ddc611b 100644 --- a/src/util.ts +++ b/src/util.ts @@ -81,9 +81,8 @@ let vendorSupport: boolean = null; let telemtryReporter: TelemetryReporter; let toolsGopath: string; -// Assumes the Go version is always 1.x. -export function isBelow(goVersion: SemVersion, minor: number): boolean { - return goVersion && goVersion.major === 1 && goVersion.minor < minor; +export function isBelow(goVersion: SemVersion, major: number, minor: number): boolean { + return goVersion && goVersion.major <= major && goVersion.minor < minor; } export function byteOffsetAt(document: vscode.TextDocument, position: vscode.Position): number { @@ -852,7 +851,7 @@ export function makeMemoizedByteOffsetConverter(buffer: Buffer): (byteOffset: nu }; } -function rmdirRecursive(dir: string) { +export function rmdirRecursive(dir: string) { if (fs.existsSync(dir)) { fs.readdirSync(dir).forEach(file => { const relPath = path.join(dir, file); From 5b0f6031e2b78bd3ca234a5cee60a98747262005 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 16 Aug 2019 21:35:35 -0400 Subject: [PATCH 6/9] fix lint errors --- go.mod | 17 +++++++++++++++++ go.sum | 29 +++++++++++++++++++++++++++++ src/goInstallTools.ts | 4 ++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 000000000..3d9a07544 --- /dev/null +++ b/go.mod @@ -0,0 +1,17 @@ +module github.com/stamblerre/vscode-go + +go 1.12 + +require ( + github.com/acroca/go-symbols v0.1.1 // indirect + github.com/alecthomas/gometalinter v3.0.0+incompatible // indirect + github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect + github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf // indirect + github.com/keegancsmith/rpc v1.1.0 // indirect + github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f // indirect + github.com/ramya-rao-a/go-outline v0.0.0-20181122025142-7182a932836a // indirect + github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518 // indirect + github.com/stamblerre/gocode v0.0.0-20190327203809-810592086997 // indirect + golang.org/x/tools v0.0.0-20190816200558-6889da9d5479 // indirect + gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..3e2a5852f --- /dev/null +++ b/go.sum @@ -0,0 +1,29 @@ +github.com/acroca/go-symbols v0.1.1 h1:q3IzaMNYocw/Bnc2a8jkXf0hM3+POfLoq30x8HYuaPE= +github.com/acroca/go-symbols v0.1.1/go.mod h1:RKAIDWtcELAw6/wjNJGWRYZ7QEinSWoJeJ2H5cfK6AM= +github.com/alecthomas/gometalinter v3.0.0+incompatible h1:e9Zfvfytsw/e6Kd/PYd75wggK+/kX5Xn8IYDUKyc5fU= +github.com/alecthomas/gometalinter v3.0.0+incompatible/go.mod h1:qfIpQGGz3d+NmgyPBqv+LSh50emm1pt72EtcX2vKYQk= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg= +github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= +github.com/keegancsmith/rpc v1.1.0 h1:bXVRk3EzbtrEegTGKxNTc+St1lR7t/Z1PAO8misBnCc= +github.com/keegancsmith/rpc v1.1.0/go.mod h1:Xow74TKX34OPPiPCdz6x1o9c0SCxRqGxDuKGk7ZOo8s= +github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f h1:ee+twVCignaZjt7jpbMSLxAeTN/Nfq9W/nm91E7QO1A= +github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f/go.mod h1:hltEC42XzfMNgg0S1v6JTywwra2Mu6F6cLR03debVQ8= +github.com/nicksnyder/go-i18n v2.0.2+incompatible h1:Xt6dluut3s2zBUha8/3sj6atWMQbFioi9OMqUGH9khg= +github.com/ramya-rao-a/go-outline v0.0.0-20181122025142-7182a932836a h1:rJS9v8WlLfIQ/22PlTXc47p5jB8RaY9XnTkX8Uols7w= +github.com/ramya-rao-a/go-outline v0.0.0-20181122025142-7182a932836a/go.mod h1:1WL5IqM+CnRCAbXetRnL1YVoS9KtU2zMhOi/5oAVPo4= +github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518 h1:iD+PFTQwKEmbwSdwfvP5ld2WEI/g7qbdhmHJ2ASfYGs= +github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518/go.mod h1:CKI4AZ4XmGV240rTHfO0hfE83S6/a3/Q1siZJ/vXf7A= +github.com/stamblerre/gocode v0.0.0-20190327203809-810592086997 h1:LF81AGV63kJoxjmSgQPT8FARAMHeY46CYQ4TNoVDWHM= +github.com/stamblerre/gocode v0.0.0-20190327203809-810592086997/go.mod h1:EM2T8YDoTCvGXbEpFHxarbpv7VE26QD1++Cb1Pbh7Gs= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479 h1:lfN2PY/jymfnxkNHlbBF5DwPsUvhqUnrdgfK01iH2s0= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vTxShRUnK60yd8DZU+f95p1zSLj814+5CuEh7NjF2/Y= +gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA= diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 4c9e6e1ee..2d39241de 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -336,7 +336,7 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< // Disable modules for staticcheck and gotests, // which are installed with the "..." wildcard. // TODO: ... will be supported in Go 1.13, so enable these tools to use modules then. - if (modulesOff || tool === "staticcheck" || tool === "gotests") { + if (modulesOff || tool === 'staticcheck' || tool === 'gotests') { envForTools['GO111MODULE'] = 'off'; } else { envForTools['GO111MODULE'] = 'on'; @@ -401,7 +401,7 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< if (tool.endsWith('-gomod')) { args.push('-d'); } - let opts = { + const opts = { env: envForTools, cwd: toolsTmpDir, }; From 0f6281645bf30101d73ac4774a65f8e0946b13b6 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 16 Aug 2019 21:35:55 -0400 Subject: [PATCH 7/9] fix gomod --- go.mod | 17 ----------------- go.sum | 29 ----------------------------- 2 files changed, 46 deletions(-) delete mode 100644 go.mod delete mode 100644 go.sum diff --git a/go.mod b/go.mod deleted file mode 100644 index 3d9a07544..000000000 --- a/go.mod +++ /dev/null @@ -1,17 +0,0 @@ -module github.com/stamblerre/vscode-go - -go 1.12 - -require ( - github.com/acroca/go-symbols v0.1.1 // indirect - github.com/alecthomas/gometalinter v3.0.0+incompatible // indirect - github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect - github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf // indirect - github.com/keegancsmith/rpc v1.1.0 // indirect - github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f // indirect - github.com/ramya-rao-a/go-outline v0.0.0-20181122025142-7182a932836a // indirect - github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518 // indirect - github.com/stamblerre/gocode v0.0.0-20190327203809-810592086997 // indirect - golang.org/x/tools v0.0.0-20190816200558-6889da9d5479 // indirect - gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect -) diff --git a/go.sum b/go.sum deleted file mode 100644 index 3e2a5852f..000000000 --- a/go.sum +++ /dev/null @@ -1,29 +0,0 @@ -github.com/acroca/go-symbols v0.1.1 h1:q3IzaMNYocw/Bnc2a8jkXf0hM3+POfLoq30x8HYuaPE= -github.com/acroca/go-symbols v0.1.1/go.mod h1:RKAIDWtcELAw6/wjNJGWRYZ7QEinSWoJeJ2H5cfK6AM= -github.com/alecthomas/gometalinter v3.0.0+incompatible h1:e9Zfvfytsw/e6Kd/PYd75wggK+/kX5Xn8IYDUKyc5fU= -github.com/alecthomas/gometalinter v3.0.0+incompatible/go.mod h1:qfIpQGGz3d+NmgyPBqv+LSh50emm1pt72EtcX2vKYQk= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg= -github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= -github.com/keegancsmith/rpc v1.1.0 h1:bXVRk3EzbtrEegTGKxNTc+St1lR7t/Z1PAO8misBnCc= -github.com/keegancsmith/rpc v1.1.0/go.mod h1:Xow74TKX34OPPiPCdz6x1o9c0SCxRqGxDuKGk7ZOo8s= -github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f h1:ee+twVCignaZjt7jpbMSLxAeTN/Nfq9W/nm91E7QO1A= -github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f/go.mod h1:hltEC42XzfMNgg0S1v6JTywwra2Mu6F6cLR03debVQ8= -github.com/nicksnyder/go-i18n v2.0.2+incompatible h1:Xt6dluut3s2zBUha8/3sj6atWMQbFioi9OMqUGH9khg= -github.com/ramya-rao-a/go-outline v0.0.0-20181122025142-7182a932836a h1:rJS9v8WlLfIQ/22PlTXc47p5jB8RaY9XnTkX8Uols7w= -github.com/ramya-rao-a/go-outline v0.0.0-20181122025142-7182a932836a/go.mod h1:1WL5IqM+CnRCAbXetRnL1YVoS9KtU2zMhOi/5oAVPo4= -github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518 h1:iD+PFTQwKEmbwSdwfvP5ld2WEI/g7qbdhmHJ2ASfYGs= -github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518/go.mod h1:CKI4AZ4XmGV240rTHfO0hfE83S6/a3/Q1siZJ/vXf7A= -github.com/stamblerre/gocode v0.0.0-20190327203809-810592086997 h1:LF81AGV63kJoxjmSgQPT8FARAMHeY46CYQ4TNoVDWHM= -github.com/stamblerre/gocode v0.0.0-20190327203809-810592086997/go.mod h1:EM2T8YDoTCvGXbEpFHxarbpv7VE26QD1++Cb1Pbh7Gs= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479 h1:lfN2PY/jymfnxkNHlbBF5DwPsUvhqUnrdgfK01iH2s0= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vTxShRUnK60yd8DZU+f95p1zSLj814+5CuEh7NjF2/Y= -gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA= From 5213e4a190d0d4dc0c26bce3de136fdd110fda33 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 26 Aug 2019 11:34:34 -0400 Subject: [PATCH 8/9] use global tmp dir --- src/goInstallTools.ts | 62 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 2d39241de..a07e87032 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -13,7 +13,7 @@ import cp = require('child_process'); import { showGoStatus, hideGoStatus, outputChannel } from './goStatus'; import { getBinPath, getToolsGopath, getGoVersion, SemVersion, isVendorSupported, getCurrentGoPath, - resolvePath, isBelow, rmdirRecursive + resolvePath, isBelow, rmdirRecursive, getTempFilePath } from './util'; import { goLiveErrorsEnabled } from './goLiveErrors'; import { getToolFromToolPath, envPath } from './goPath'; @@ -78,6 +78,7 @@ const importantTools = [ 'dlv' ]; + function getTools(goVersion: SemVersion): string[] { const goConfig = vscode.workspace.getConfiguration('go', vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document.uri : null); const tools: string[] = [ @@ -332,6 +333,12 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< outputChannel.appendLine(''); // Blank line for spacing. + // Install tools in a temporary directory, to avoid altering go.mod files. + const toolsTmpDir = getTempFilePath('go-tools'); + if (!fs.existsSync(toolsTmpDir)) { + fs.mkdirSync(toolsTmpDir); + } + return missing.reduce((res: Promise, tool: string) => { // Disable modules for staticcheck and gotests, // which are installed with the "..." wildcard. @@ -341,6 +348,7 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< } else { envForTools['GO111MODULE'] = 'on'; } + return res.then(sofar => new Promise((resolve) => { const callback = (err: Error, stdout: string, stderr: string) => { if (err) { @@ -387,37 +395,29 @@ export function installTools(missing: string[], goVersion: SemVersion): Promise< resolve([...sofar, null]); return; } - // Install tools in a temporary directory, to avoid altering go.mod files. - fs.mkdtemp(path.join(os.tmpdir(), 'go-tools-'), (err, toolsTmpDir) => { - if (err) { - resolve([...sofar, null]); - return; - } - const args = ['get', '-v']; - // Only get tools at master if we are not using modules. - if (modulesOff) { - args.push('-u'); - } - if (tool.endsWith('-gomod')) { - args.push('-d'); + const args = ['get', '-v']; + // Only get tools at master if we are not using modules. + if (modulesOff) { + args.push('-u'); + } + if (tool.endsWith('-gomod')) { + args.push('-d'); + } + const opts = { + env: envForTools, + cwd: toolsTmpDir, + }; + args.push(getToolImportPath(tool, goVersion)); + cp.execFile(goRuntimePath, args, opts, (err, stdout, stderr) => { + if (stderr.indexOf('unexpected directory layout:') > -1) { + outputChannel.appendLine(`Installing ${tool} failed with error "unexpected directory layout". Retrying...`); + cp.execFile(goRuntimePath, args, opts, callback); + } else if (!err && tool.endsWith('-gomod')) { + const outputFile = path.join(toolsGopath, 'bin', process.platform === 'win32' ? `${tool}.exe` : tool); + cp.execFile(goRuntimePath, ['build', '-o', outputFile, getToolImportPath(tool, goVersion)], opts, callback); + } else { + callback(err, stdout, stderr); } - const opts = { - env: envForTools, - cwd: toolsTmpDir, - }; - args.push(getToolImportPath(tool, goVersion)); - cp.execFile(goRuntimePath, args, opts, (err, stdout, stderr) => { - if (stderr.indexOf('unexpected directory layout:') > -1) { - outputChannel.appendLine(`Installing ${tool} failed with error "unexpected directory layout". Retrying...`); - cp.execFile(goRuntimePath, args, opts, callback); - } else if (!err && tool.endsWith('-gomod')) { - const outputFile = path.join(toolsGopath, 'bin', process.platform === 'win32' ? `${tool}.exe` : tool); - cp.execFile(goRuntimePath, ['build', '-o', outputFile, getToolImportPath(tool, goVersion)], opts, callback); - } else { - callback(err, stdout, stderr); - } - }); - rmdirRecursive(toolsTmpDir); }); }); })); From 3e8ccfc411d661720d37645ded44b207388f261d Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 26 Aug 2019 12:09:05 -0400 Subject: [PATCH 9/9] fix lint errors --- src/goInstallTools.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index a07e87032..d62f7a676 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -78,7 +78,6 @@ const importantTools = [ 'dlv' ]; - function getTools(goVersion: SemVersion): string[] { const goConfig = vscode.workspace.getConfiguration('go', vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document.uri : null); const tools: string[] = [