Skip to content

Commit 053cd93

Browse files
committed
src/goToolsInformation: delete legacy tools
Fixes #2799 For #1652 Change-Id: Ib7e046a1df0a63bd3babcf2019851bdcfe7e6726 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/538762 TryBot-Result: kokoro <[email protected]> Commit-Queue: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Suzy Mueller <[email protected]>
1 parent 324992b commit 053cd93

File tree

5 files changed

+13
-379
lines changed

5 files changed

+13
-379
lines changed

docs/tools.md

-47
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ This extension uses Delve for its debug/test functionalities. The extension curr
3535

3636
For a comprehensive overview of how to debug your Go programs, please see the [debugging guide](./debugging.md).
3737

38-
### [`dlv-dap`](https://github.com/go-delve/delve)
39-
This extension requires an unstable version of [`dlv`](#dlv) when users opt in to use Delve's native DAP implementation. `dlv-dap` is a `dlv` built from the master, which includes unreleased features. Please see the documentation about [Dlv DAP - Delve's Native DAP implementation](./dlv-dap.md) for details.
40-
41-
### [`go-outline`](https://pkg.go.dev/github.com/ramya-rao-a/go-outline?tab=overview)
42-
43-
This tool provides the information needed to compute the various test code lenses. It will be replaced with [`gopls`]. <!--TODO: reference to the issue-->
44-
4538
### [`goplay`](https://pkg.go.dev/github.com/haya14busa/goplay?tab=overview)
4639

4740
This tool provides support for the [`Go: Run on Go Playground`](features.md#go-playground) command.
@@ -90,48 +83,8 @@ Configure `revive` to exclude `vendor` directories and apply extra configuration
9083
]
9184
```
9285

93-
### Misc tools used in the legacy mode
94-
95-
When `gopls` cannot be used, the extension falls back to the legacy mode. Be aware that many of these tools may be incompatible with the recent versions of Go or do not work in Modules mode.
96-
97-
* [`go-outline`](https://pkg.go.dev/github.com/ramya-rao-a/go-outline?tab=overview):
98-
In the legacy mode, this tool provides the `[document outline](features.md#document-outline) feature` and the [go to symbol](features.md#go-to-symbol) in the current file feature.
99-
100-
* `gocode`: code completion in the legacy mode is provided by `gocode`. Different versions of `gocode` are used depending on your version of Go.
101-
* Go 1.9 and above: [mdempsky/gocode](https://github.com/mdempsky/gocode)
102-
* Go 1.11 and above, with modules enabled: [stamblerre/gocode](https://github.com/stamblerre/gocode), named `gocode-gomod` internally.
103-
104-
* [`go-symbols`](https://pkg.go.dev/github.com/acroca/go-symbols?tab=overview): provides the [go to symbol](features.md#go-to-symbol) in workspace feature.
105-
106-
* [`guru`](https://pkg.go.dev/golang.org/x/tools/cmd/guru?tab=doc): provides the [find references](features.md#find-references) and [find interface implementations](features.md#find-interface-implementations) features.
107-
It can also be used to provide the [go to definition](features.md#go-to-definition) via the [`"go.docsTool"`](settings.md#go.docsTool) setting. `guru` does not support Go modules.
108-
109-
* [`gorename`](https://pkg.go.dev/golang.org/x/tools/cmd/gorename?tab=doc): provides the [rename symbol](features.md#rename-symbol) feature. `gorename` does not have support for Go modules
110-
111-
* [`godoctor`](https://github.com/godoctor/godoctor): provides the [refactoring](features.md#refactor) features. It does not support Go modules, and we expect that [`gopls`] will provide this feature instead ([golang/go#37170](https://github.com/golang/go/issues/37170)).
112-
113-
* [`fillstruct`](https://github.com/davidrjenni/reftools/tree/master/cmd/fillstruct): provides support the [`Go: Fill struct`](features.md#fill-struct-literals) command.
114-
115-
* [`gogetdoc`], [`godef`], [`godoc`]: these are documentation tools used for the [go to definition](features.md#go-to-definition), [signature help](features.md#signature-help), and [quick info on hover](features.md#quick-info-on-hover) in the legacy mode. [`guru`](#guru) can also be used, but only for the [go to definition](features.md#go-to-definition) behavior. Configure this via the [`"go.docsTool"`](settings.md#go.docsTool) setting.
116-
117-
* [`goimports`], [`gofmt`]: Formatting tools are used by the [formatting and import organization](features.md#format-and-organize-imports) features. [`goreturns`] is used by default in the legacy mode. It formats the file according to the industry standard [`gofmt`] style, organizes imports, and fills in default return values for functions. Other tools can be used for formatting instead; this can be configured with the [`"go.go.formatTool"`](settings.md#formatTool) setting.
118-
119-
* [`gofmt`] only formats the file, without import organization or filling in return values
120-
* [`goformat`] is a configurable version of [`gofmt`]
121-
* [`goreturns`] fills in default return values for functions, in addition to applying `goimports`-style formatting. This tool does not have support for Go modules.
122-
123-
* Diagnostics tools: By default, [`gotype-live`], [`go vet`], and [`golint`] are used to provide [build](features.md#build-errors), [vet](features.md#vet-errors), and [lint](features.md#lint-errors) errors. [`gotype-live`] provides build errors as you type, while `go build` can be used to show build errors only on save. [`gotype-live`] does not work with modules.
124-
125-
126-
127-
[`gogetdoc`]: https://pkg.go.dev/github.com/zmb3/gogetdoc?tab=overview
128-
[`godef`]: https://pkg.go.dev/github.com/rogpeppe/godef?tab=doc
129-
[`godoc`]: https://pkg.go.dev/golang.org/x/tools/godoc?tab=doc
130-
[`goreturns`]: https://pkg.go.dev/github.com/sqs/goreturns?tab=overview
13186
[`goimports`]: https://pkg.go.dev/golang.org/x/tools/cmd/goimports?tab=doc
13287
[`gofmt`]: https://golang.org/cmd/gofmt/
133-
[`goformat`]: https://pkg.go.dev/winterdrache.de/goformat?tab=overview
134-
[`gotype-live`]: https://pkg.go.dev/github.com/tylerb/gotype-live?tab=doc
13588
[`golint`]: https://pkg.go.dev/golang.org/x/lint/golint?tab=overview
13689
[`staticcheck`]: https://pkg.go.dev/honnef.co/go/tools/staticcheck?tab=overview
13790
[`golangci-lint`]: https://golangci-lint.run/

src/goInstallTools.ts

+4-87
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,7 @@ import { addGoRuntimeBaseToPATH, clearGoRuntimeBaseFromPATH } from './goEnvironm
1919
import { logVerbose, logError } from './goLogging';
2020
import { GoExtensionContext } from './context';
2121
import { addGoStatus, initGoStatusBar, outputChannel, removeGoStatus } from './goStatus';
22-
import {
23-
containsTool,
24-
getConfiguredTools,
25-
getImportPath,
26-
getImportPathWithVersion,
27-
getTool,
28-
hasModSuffix,
29-
Tool,
30-
ToolAtVersion
31-
} from './goTools';
22+
import { containsTool, getConfiguredTools, getImportPathWithVersion, getTool, Tool, ToolAtVersion } from './goTools';
3223
import {
3324
getBinPath,
3425
getBinPathWithExplanation,
@@ -39,7 +30,7 @@ import {
3930
GoVersion,
4031
rmdirRecursive
4132
} from './util';
42-
import { correctBinname, getEnvPath, getCurrentGoRoot, setCurrentGoRoot } from './utils/pathUtils';
33+
import { getEnvPath, getCurrentGoRoot, setCurrentGoRoot } from './utils/pathUtils';
4334
import util = require('util');
4435
import vscode = require('vscode');
4536
import { RestartReason } from './language/goLanguageServer';
@@ -256,11 +247,7 @@ async function installToolWithGo(
256247
const importPath = getImportPathWithVersion(tool, version, goVersion);
257248

258249
try {
259-
if (hasModSuffix(tool)) {
260-
await installToolWithGoGet(tool, goVersion, env, importPath);
261-
} else {
262-
await installToolWithGoInstall(goVersion, env, importPath);
263-
}
250+
await installToolWithGoInstall(goVersion, env, importPath);
264251
const toolInstallPath = getBinPath(tool.name);
265252
outputChannel.appendLine(`Installing ${importPath} (${toolInstallPath}) SUCCEEDED`);
266253
} catch (e) {
@@ -284,76 +271,6 @@ async function installToolWithGoInstall(goVersion: GoVersion, env: NodeJS.Dict<s
284271
await execFile(goBinary, ['install', '-v', importPath], opts);
285272
}
286273

287-
async function installToolWithGoGet(
288-
tool: ToolAtVersion,
289-
goVersion: GoVersion,
290-
env: NodeJS.Dict<string>,
291-
importPath: string
292-
) {
293-
// Some users use direnv-like setup where the choice of go is affected by
294-
// the current directory path. In order to avoid choosing a different go,
295-
// we will explicitly use `GOROOT/bin/go` instead of goVersion.binaryPath
296-
// (which can be a wrapper script that switches 'go').
297-
const goBinary = getCurrentGoRoot()
298-
? path.join(getCurrentGoRoot(), 'bin', correctBinname('go'))
299-
: goVersion?.binaryPath;
300-
if (!goBinary) {
301-
vscode.window.showErrorMessage('Go binary not found.');
302-
return;
303-
}
304-
305-
// Build the arguments list for the tool installation.
306-
const args = ['get', '-x'];
307-
// tools with a "mod" suffix can't be installed with
308-
// simple `go install` or `go get`. We need to get, build, and rename them.
309-
if (hasModSuffix(tool)) {
310-
args.push('-d'); // get the version, but don't build.
311-
}
312-
args.push(importPath);
313-
314-
let toolsTmpDir = '';
315-
try {
316-
toolsTmpDir = await tmpDirForToolInstallation();
317-
} catch (e) {
318-
throw new Error(`Failed to create a temp directory: ${e}`);
319-
}
320-
321-
const opts = {
322-
env,
323-
cwd: toolsTmpDir
324-
};
325-
326-
try {
327-
const execFile = util.promisify(cp.execFile);
328-
logVerbose(`$ ${goBinary} ${args.join(' ')} (cwd: ${opts.cwd})`);
329-
await execFile(goBinary, args, opts);
330-
331-
if (hasModSuffix(tool)) {
332-
// Actual installation of the -gomod tool is done by running go build.
333-
let destDir = env['GOBIN'];
334-
if (!destDir) {
335-
const gopath0 = env['GOPATH']?.split(path.delimiter)[0];
336-
destDir = gopath0 ? path.join(gopath0, 'bin') : undefined;
337-
}
338-
if (!destDir) {
339-
throw new Error('GOBIN/GOPATH not configured in environment');
340-
}
341-
const outputFile = path.join(destDir, correctBinname(tool.name));
342-
343-
// go build does not take @version suffix yet.
344-
const importPathWithoutVersion = getImportPath(tool, goVersion);
345-
logVerbose(`$ ${goBinary} build -o ${outputFile} ${importPathWithoutVersion} (cwd: ${opts.cwd})`);
346-
await execFile(goBinary, ['build', '-o', outputFile, importPathWithoutVersion], opts);
347-
}
348-
} catch (e) {
349-
logVerbose(`FAILED: ${JSON.stringify(e, null, 1)}`);
350-
throw e;
351-
} finally {
352-
// Delete the temporary installation directory.
353-
rmdirRecursive(toolsTmpDir);
354-
}
355-
}
356-
357274
export function declinedToolInstall(toolName: string) {
358275
const tool = getTool(toolName);
359276

@@ -773,7 +690,7 @@ export async function shouldUpdateTool(tool: Tool, toolPath: string): Promise<bo
773690

774691
export async function suggestUpdates() {
775692
const configuredGoVersion = await getGoVersion();
776-
if (!configuredGoVersion || configuredGoVersion.lt('1.12')) {
693+
if (!configuredGoVersion || configuredGoVersion.lt('1.16')) {
777694
// User is using an ancient or a dev version of go. Don't suggest updates -
778695
// user should know what they are doing.
779696
return;

src/goTools.ts

+2-40
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
'use strict';
88

9-
import cp = require('child_process');
109
import moment = require('moment');
11-
import path = require('path');
1210
import semver = require('semver');
13-
import util = require('util');
1411
import { getFormatTool, usingCustomFormatTool } from './language/legacy/goFormat';
1512
import { allToolsInformation } from './goToolsInformation';
16-
import { getBinPath, GoVersion } from './util';
13+
import { GoVersion } from './util';
1714

1815
export interface Tool {
1916
name: string;
@@ -59,25 +56,12 @@ export interface ToolAtVersion extends Tool {
5956
version?: semver.SemVer;
6057
}
6158

62-
/**
63-
* Returns the import path for a given tool, at a given Go version.
64-
* @param tool Object of type `Tool` for the Go tool.
65-
* @param goVersion The current Go version.
66-
*/
67-
export function getImportPath(tool: Tool, goVersion: GoVersion): string {
68-
// For older versions of Go, install the older version of gocode.
69-
if (tool.name === 'gocode' && goVersion?.lt('1.10')) {
70-
return 'github.com/nsf/gocode';
71-
}
72-
return tool.importPath;
73-
}
74-
7559
export function getImportPathWithVersion(
7660
tool: Tool,
7761
version: semver.SemVer | string | undefined | null,
7862
goVersion: GoVersion
7963
): string {
80-
const importPath = getImportPath(tool, goVersion);
64+
const importPath = tool.importPath;
8165
if (version) {
8266
if (version instanceof semver.SemVer) {
8367
return importPath + '@v' + version;
@@ -125,10 +109,6 @@ export function hasModSuffix(tool: Tool): boolean {
125109
return tool.name.endsWith('-gomod');
126110
}
127111

128-
export function isGocode(tool: Tool): boolean {
129-
return tool.name === 'gocode' || tool.name === 'gocode-gomod';
130-
}
131-
132112
export function getConfiguredTools(goConfig: { [key: string]: any }, goplsConfig: { [key: string]: any }): Tool[] {
133113
// If language server is enabled, don't suggest tools that are replaced by gopls.
134114
// TODO(github.com/golang/vscode-go/issues/388): decide what to do when
@@ -190,21 +170,3 @@ export function goplsStaticcheckEnabled(
190170
}
191171
return true;
192172
}
193-
194-
export const gocodeClose = async (env: NodeJS.Dict<string>): Promise<string> => {
195-
const toolBinPath = getBinPath('gocode');
196-
if (!path.isAbsolute(toolBinPath)) {
197-
return '';
198-
}
199-
try {
200-
const execFile = util.promisify(cp.execFile);
201-
const { stderr } = await execFile(toolBinPath, ['close'], { env, timeout: 10000 }); // give 10sec.
202-
if (stderr.indexOf("rpc: can't find service Server.") > -1) {
203-
return 'Installing gocode aborted as existing process cannot be closed. Please kill the running process for gocode and try again.';
204-
}
205-
} catch (err) {
206-
// This may fail if gocode isn't already running.
207-
console.log(`gocode close failed: ${err}`);
208-
}
209-
return '';
210-
};

0 commit comments

Comments
 (0)