From 053cd9398743d2cd18579f2bf1860e8f661ca239 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Tue, 31 Oct 2023 21:10:25 -0400 Subject: [PATCH] src/goToolsInformation: delete legacy tools Fixes golang/vscode-go#2799 For golang/vscode-go#1652 Change-Id: Ib7e046a1df0a63bd3babcf2019851bdcfe7e6726 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/538762 TryBot-Result: kokoro Commit-Queue: Hyang-Ah Hana Kim Reviewed-by: Suzy Mueller --- docs/tools.md | 47 ---------------- src/goInstallTools.ts | 91 ++----------------------------- src/goTools.ts | 42 +-------------- src/goToolsInformation.ts | 109 ++------------------------------------ tools/allTools.ts.in | 103 +---------------------------------- 5 files changed, 13 insertions(+), 379 deletions(-) diff --git a/docs/tools.md b/docs/tools.md index 4bcc3760e5..fcec3abc73 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -35,13 +35,6 @@ This extension uses Delve for its debug/test functionalities. The extension curr For a comprehensive overview of how to debug your Go programs, please see the [debugging guide](./debugging.md). -### [`dlv-dap`](https://github.com/go-delve/delve) -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. - -### [`go-outline`](https://pkg.go.dev/github.com/ramya-rao-a/go-outline?tab=overview) - -This tool provides the information needed to compute the various test code lenses. It will be replaced with [`gopls`]. - ### [`goplay`](https://pkg.go.dev/github.com/haya14busa/goplay?tab=overview) 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 ] ``` -### Misc tools used in the legacy mode - -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. - -* [`go-outline`](https://pkg.go.dev/github.com/ramya-rao-a/go-outline?tab=overview): -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. - -* `gocode`: code completion in the legacy mode is provided by `gocode`. Different versions of `gocode` are used depending on your version of Go. - * Go 1.9 and above: [mdempsky/gocode](https://github.com/mdempsky/gocode) - * Go 1.11 and above, with modules enabled: [stamblerre/gocode](https://github.com/stamblerre/gocode), named `gocode-gomod` internally. - -* [`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. - -* [`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. -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. - -* [`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 - -* [`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)). - -* [`fillstruct`](https://github.com/davidrjenni/reftools/tree/master/cmd/fillstruct): provides support the [`Go: Fill struct`](features.md#fill-struct-literals) command. - -* [`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. - -* [`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. - - * [`gofmt`] only formats the file, without import organization or filling in return values - * [`goformat`] is a configurable version of [`gofmt`] - * [`goreturns`] fills in default return values for functions, in addition to applying `goimports`-style formatting. This tool does not have support for Go modules. - -* 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. - - - -[`gogetdoc`]: https://pkg.go.dev/github.com/zmb3/gogetdoc?tab=overview -[`godef`]: https://pkg.go.dev/github.com/rogpeppe/godef?tab=doc -[`godoc`]: https://pkg.go.dev/golang.org/x/tools/godoc?tab=doc -[`goreturns`]: https://pkg.go.dev/github.com/sqs/goreturns?tab=overview [`goimports`]: https://pkg.go.dev/golang.org/x/tools/cmd/goimports?tab=doc [`gofmt`]: https://golang.org/cmd/gofmt/ -[`goformat`]: https://pkg.go.dev/winterdrache.de/goformat?tab=overview -[`gotype-live`]: https://pkg.go.dev/github.com/tylerb/gotype-live?tab=doc [`golint`]: https://pkg.go.dev/golang.org/x/lint/golint?tab=overview [`staticcheck`]: https://pkg.go.dev/honnef.co/go/tools/staticcheck?tab=overview [`golangci-lint`]: https://golangci-lint.run/ diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index a00fcd83d2..09be365e8e 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -19,16 +19,7 @@ import { addGoRuntimeBaseToPATH, clearGoRuntimeBaseFromPATH } from './goEnvironm import { logVerbose, logError } from './goLogging'; import { GoExtensionContext } from './context'; import { addGoStatus, initGoStatusBar, outputChannel, removeGoStatus } from './goStatus'; -import { - containsTool, - getConfiguredTools, - getImportPath, - getImportPathWithVersion, - getTool, - hasModSuffix, - Tool, - ToolAtVersion -} from './goTools'; +import { containsTool, getConfiguredTools, getImportPathWithVersion, getTool, Tool, ToolAtVersion } from './goTools'; import { getBinPath, getBinPathWithExplanation, @@ -39,7 +30,7 @@ import { GoVersion, rmdirRecursive } from './util'; -import { correctBinname, getEnvPath, getCurrentGoRoot, setCurrentGoRoot } from './utils/pathUtils'; +import { getEnvPath, getCurrentGoRoot, setCurrentGoRoot } from './utils/pathUtils'; import util = require('util'); import vscode = require('vscode'); import { RestartReason } from './language/goLanguageServer'; @@ -256,11 +247,7 @@ async function installToolWithGo( const importPath = getImportPathWithVersion(tool, version, goVersion); try { - if (hasModSuffix(tool)) { - await installToolWithGoGet(tool, goVersion, env, importPath); - } else { - await installToolWithGoInstall(goVersion, env, importPath); - } + await installToolWithGoInstall(goVersion, env, importPath); const toolInstallPath = getBinPath(tool.name); outputChannel.appendLine(`Installing ${importPath} (${toolInstallPath}) SUCCEEDED`); } catch (e) { @@ -284,76 +271,6 @@ async function installToolWithGoInstall(goVersion: GoVersion, env: NodeJS.Dict, - importPath: string -) { - // Some users use direnv-like setup where the choice of go is affected by - // the current directory path. In order to avoid choosing a different go, - // we will explicitly use `GOROOT/bin/go` instead of goVersion.binaryPath - // (which can be a wrapper script that switches 'go'). - const goBinary = getCurrentGoRoot() - ? path.join(getCurrentGoRoot(), 'bin', correctBinname('go')) - : goVersion?.binaryPath; - if (!goBinary) { - vscode.window.showErrorMessage('Go binary not found.'); - return; - } - - // Build the arguments list for the tool installation. - const args = ['get', '-x']; - // tools with a "mod" suffix can't be installed with - // simple `go install` or `go get`. We need to get, build, and rename them. - if (hasModSuffix(tool)) { - args.push('-d'); // get the version, but don't build. - } - args.push(importPath); - - let toolsTmpDir = ''; - try { - toolsTmpDir = await tmpDirForToolInstallation(); - } catch (e) { - throw new Error(`Failed to create a temp directory: ${e}`); - } - - const opts = { - env, - cwd: toolsTmpDir - }; - - try { - const execFile = util.promisify(cp.execFile); - logVerbose(`$ ${goBinary} ${args.join(' ')} (cwd: ${opts.cwd})`); - await execFile(goBinary, args, opts); - - if (hasModSuffix(tool)) { - // Actual installation of the -gomod tool is done by running go build. - let destDir = env['GOBIN']; - if (!destDir) { - const gopath0 = env['GOPATH']?.split(path.delimiter)[0]; - destDir = gopath0 ? path.join(gopath0, 'bin') : undefined; - } - if (!destDir) { - throw new Error('GOBIN/GOPATH not configured in environment'); - } - const outputFile = path.join(destDir, correctBinname(tool.name)); - - // go build does not take @version suffix yet. - const importPathWithoutVersion = getImportPath(tool, goVersion); - logVerbose(`$ ${goBinary} build -o ${outputFile} ${importPathWithoutVersion} (cwd: ${opts.cwd})`); - await execFile(goBinary, ['build', '-o', outputFile, importPathWithoutVersion], opts); - } - } catch (e) { - logVerbose(`FAILED: ${JSON.stringify(e, null, 1)}`); - throw e; - } finally { - // Delete the temporary installation directory. - rmdirRecursive(toolsTmpDir); - } -} - export function declinedToolInstall(toolName: string) { const tool = getTool(toolName); @@ -773,7 +690,7 @@ export async function shouldUpdateTool(tool: Tool, toolPath: string): Promise): Promise => { - const toolBinPath = getBinPath('gocode'); - if (!path.isAbsolute(toolBinPath)) { - return ''; - } - try { - const execFile = util.promisify(cp.execFile); - const { stderr } = await execFile(toolBinPath, ['close'], { env, timeout: 10000 }); // give 10sec. - if (stderr.indexOf("rpc: can't find service Server.") > -1) { - return 'Installing gocode aborted as existing process cannot be closed. Please kill the running process for gocode and try again.'; - } - } catch (err) { - // This may fail if gocode isn't already running. - console.log(`gocode close failed: ${err}`); - } - return ''; -}; diff --git a/src/goToolsInformation.ts b/src/goToolsInformation.ts index 6230519e7b..8171316980 100644 --- a/src/goToolsInformation.ts +++ b/src/goToolsInformation.ts @@ -2,63 +2,9 @@ import moment = require('moment'); import semver = require('semver'); -import { gocodeClose, Tool } from './goTools'; +import { Tool } from './goTools'; export const allToolsInformation: { [key: string]: Tool } = { - 'gocode': { - name: 'gocode', - importPath: 'github.com/mdempsky/gocode', - modulePath: 'github.com/mdempsky/gocode', - isImportant: true, - replacedByGopls: true, - description: 'Auto-completion, does not work with modules', - close: gocodeClose, - defaultVersion: 'v0.0.0-20200405233807-4acdcbdea79d' - }, - 'gocode-gomod': { - name: 'gocode-gomod', - importPath: 'github.com/stamblerre/gocode', - modulePath: 'github.com/stamblerre/gocode', - isImportant: true, - replacedByGopls: true, - description: 'Auto-completion, works with modules', - minimumGoVersion: semver.coerce('1.11'), - defaultVersion: 'v1.0.0' - }, - 'go-outline': { - name: 'go-outline', - importPath: 'github.com/ramya-rao-a/go-outline', - modulePath: 'github.com/ramya-rao-a/go-outline', - replacedByGopls: true, - isImportant: true, - description: 'Go to symbol in file', // GoDocumentSymbolProvider, used by 'run test' codelens - defaultVersion: 'v0.0.0-20210608161538-9736a4bde949' - }, - 'go-symbols': { - name: 'go-symbols', - importPath: 'github.com/acroca/go-symbols', - modulePath: 'github.com/acroca/go-symbols', - replacedByGopls: true, - isImportant: false, - description: 'Go to symbol in workspace', - defaultVersion: 'v0.1.1' - }, - 'guru': { - name: 'guru', - importPath: 'golang.org/x/tools/cmd/guru', - modulePath: 'golang.org/x/tools', - replacedByGopls: true, - isImportant: false, - description: 'Find all references and Go to implementation of symbols' - }, - 'gorename': { - name: 'gorename', - importPath: 'golang.org/x/tools/cmd/gorename', - modulePath: 'golang.org/x/tools', - replacedByGopls: true, - isImportant: false, - description: 'Rename symbols' - }, 'gomodifytags': { name: 'gomodifytags', importPath: 'github.com/fatih/gomodifytags', @@ -86,33 +32,6 @@ export const allToolsInformation: { [key: string]: Tool } = { description: 'Stubs for interfaces', defaultVersion: 'v1.1.0' }, - 'gotype-live': { - name: 'gotype-live', - importPath: 'github.com/tylerb/gotype-live', - modulePath: 'github.com/tylerb/gotype-live', - replacedByGopls: true, // TODO(github.com/golang/vscode-go/issues/1021): recommend users to turn off. - isImportant: false, - description: 'Show errors as you type', - defaultVersion: 'v0.0.0-20200426224044-fc0b594a8b09' - }, - 'godef': { - name: 'godef', - importPath: 'github.com/rogpeppe/godef', - modulePath: 'github.com/rogpeppe/godef', - replacedByGopls: true, - isImportant: true, - description: 'Go to definition', - defaultVersion: 'v1.1.2' - }, - 'gogetdoc': { - name: 'gogetdoc', - importPath: 'github.com/zmb3/gogetdoc', - modulePath: 'github.com/zmb3/gogetdoc', - replacedByGopls: true, - isImportant: true, - description: 'Go to definition & text shown on hover', - defaultVersion: 'v0.0.0-20190228002656-b37376c5da6a' - }, 'gofumports': { name: 'gofumports', importPath: 'mvdan.cc/gofumpt/gofumports', @@ -139,24 +58,6 @@ export const allToolsInformation: { [key: string]: Tool } = { isImportant: true, description: 'Formatter' }, - 'goreturns': { - name: 'goreturns', - importPath: 'github.com/sqs/goreturns', - modulePath: 'github.com/sqs/goreturns', - replacedByGopls: true, - isImportant: true, - description: 'Formatter', - defaultVersion: 'v0.0.0-20181028201513-538ac6014518' - }, - 'goformat': { - name: 'goformat', - importPath: 'winterdrache.de/goformat/goformat', - modulePath: 'winterdrache.de/goformat/goformat', - replacedByGopls: true, - isImportant: false, - description: 'Formatter', - defaultVersion: 'v0.0.0-20180512004123-256ef38c4271' - }, 'gotests': { name: 'gotests', importPath: 'github.com/cweill/gotests/gotests', @@ -210,10 +111,10 @@ export const allToolsInformation: { [key: string]: Tool } = { description: 'Language Server from Google', usePrereleaseInPreviewMode: true, minimumGoVersion: semver.coerce('1.13'), - latestVersion: semver.parse('v0.12.2'), - latestVersionTimestamp: moment('2023-06-01', 'YYYY-MM-DD'), - latestPrereleaseVersion: semver.parse('v0.12.2'), - latestPrereleaseVersionTimestamp: moment('2023-06-01', 'YYYY-MM-DD') + latestVersion: semver.parse('v0.14.1'), + latestVersionTimestamp: moment('2023-10-26', 'YYYY-MM-DD'), + latestPrereleaseVersion: semver.parse('v0.14.1'), + latestPrereleaseVersionTimestamp: moment('2023-10-26', 'YYYY-MM-DD') }, 'dlv': { name: 'dlv', diff --git a/tools/allTools.ts.in b/tools/allTools.ts.in index e166c89a13..dcc2dd3037 100644 --- a/tools/allTools.ts.in +++ b/tools/allTools.ts.in @@ -1,62 +1,8 @@ import moment = require('moment'); import semver = require('semver'); -import { gocodeClose, Tool } from './goTools'; +import { Tool } from './goTools'; export const allToolsInformation: { [key: string]: Tool } = { - 'gocode': { - name: 'gocode', - importPath: 'github.com/mdempsky/gocode', - modulePath: 'github.com/mdempsky/gocode', - isImportant: true, - replacedByGopls: true, - description: 'Auto-completion, does not work with modules', - close: gocodeClose, - defaultVersion: 'v0.0.0-20200405233807-4acdcbdea79d' - }, - 'gocode-gomod': { - name: 'gocode-gomod', - importPath: 'github.com/stamblerre/gocode', - modulePath: 'github.com/stamblerre/gocode', - isImportant: true, - replacedByGopls: true, - description: 'Auto-completion, works with modules', - minimumGoVersion: semver.coerce('1.11'), - defaultVersion: 'v1.0.0' - }, - 'go-outline': { - name: 'go-outline', - importPath: 'github.com/ramya-rao-a/go-outline', - modulePath: 'github.com/ramya-rao-a/go-outline', - replacedByGopls: true, - isImportant: true, - description: 'Go to symbol in file', // GoDocumentSymbolProvider, used by 'run test' codelens - defaultVersion: 'v0.0.0-20210608161538-9736a4bde949' - }, - 'go-symbols': { - name: 'go-symbols', - importPath: 'github.com/acroca/go-symbols', - modulePath: 'github.com/acroca/go-symbols', - replacedByGopls: true, - isImportant: false, - description: 'Go to symbol in workspace', - defaultVersion: 'v0.1.1' - }, - 'guru': { - name: 'guru', - importPath: 'golang.org/x/tools/cmd/guru', - modulePath: 'golang.org/x/tools', - replacedByGopls: true, - isImportant: false, - description: 'Find all references and Go to implementation of symbols' - }, - 'gorename': { - name: 'gorename', - importPath: 'golang.org/x/tools/cmd/gorename', - modulePath: 'golang.org/x/tools', - replacedByGopls: true, - isImportant: false, - description: 'Rename symbols' - }, 'gomodifytags': { name: 'gomodifytags', importPath: 'github.com/fatih/gomodifytags', @@ -84,33 +30,6 @@ export const allToolsInformation: { [key: string]: Tool } = { description: 'Stubs for interfaces', defaultVersion: 'v1.1.0' }, - 'gotype-live': { - name: 'gotype-live', - importPath: 'github.com/tylerb/gotype-live', - modulePath: 'github.com/tylerb/gotype-live', - replacedByGopls: true, // TODO(github.com/golang/vscode-go/issues/1021): recommend users to turn off. - isImportant: false, - description: 'Show errors as you type', - defaultVersion: 'v0.0.0-20200426224044-fc0b594a8b09' - }, - 'godef': { - name: 'godef', - importPath: 'github.com/rogpeppe/godef', - modulePath: 'github.com/rogpeppe/godef', - replacedByGopls: true, - isImportant: true, - description: 'Go to definition', - defaultVersion: 'v1.1.2' - }, - 'gogetdoc': { - name: 'gogetdoc', - importPath: 'github.com/zmb3/gogetdoc', - modulePath: 'github.com/zmb3/gogetdoc', - replacedByGopls: true, - isImportant: true, - description: 'Go to definition & text shown on hover', - defaultVersion: 'v0.0.0-20190228002656-b37376c5da6a' - }, 'gofumports': { name: 'gofumports', importPath: 'mvdan.cc/gofumpt/gofumports', @@ -137,24 +56,6 @@ export const allToolsInformation: { [key: string]: Tool } = { isImportant: true, description: 'Formatter' }, - 'goreturns': { - name: 'goreturns', - importPath: 'github.com/sqs/goreturns', - modulePath: 'github.com/sqs/goreturns', - replacedByGopls: true, - isImportant: true, - description: 'Formatter', - defaultVersion: 'v0.0.0-20181028201513-538ac6014518' - }, - 'goformat': { - name: 'goformat', - importPath: 'winterdrache.de/goformat/goformat', - modulePath: 'winterdrache.de/goformat/goformat', - replacedByGopls: true, - isImportant: false, - description: 'Formatter', - defaultVersion: 'v0.0.0-20180512004123-256ef38c4271' - }, 'gotests': { name: 'gotests', importPath: 'github.com/cweill/gotests/gotests', @@ -189,7 +90,7 @@ export const allToolsInformation: { [key: string]: Tool } = { modulePath: 'github.com/golangci/golangci-lint', replacedByGopls: false, isImportant: true, - description: 'Linter', + description: 'Linter' }, 'revive': { name: 'revive',