From 4c1fb9132c06de2a9d3a856091da0145c5807f73 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 9 Nov 2023 18:37:47 +0800 Subject: [PATCH 01/10] change gopls => gopls.proxy for debug --- src/goToolsInformation.ts | 6 +++--- src/language/goLanguageServer.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/goToolsInformation.ts b/src/goToolsInformation.ts index 5d632e5b60..323795f977 100644 --- a/src/goToolsInformation.ts +++ b/src/goToolsInformation.ts @@ -202,9 +202,9 @@ export const allToolsInformation: { [key: string]: Tool } = { defaultVersion: 'v1.3.2' }, 'gopls': { - name: 'gopls', - importPath: 'github.com/goplus/tools/goxls', // goxls: Go+ - modulePath: 'github.com/goplus/tools/goxls', + name: 'goxls', // goxls: Go+ + importPath: 'github.com/goplus/goxls', + modulePath: 'github.com/goplus/goxls', replacedByGopls: false, // lol isImportant: true, description: 'Go+ Language Server', diff --git a/src/language/goLanguageServer.ts b/src/language/goLanguageServer.ts index 8da4d2e5ae..47b25e0724 100644 --- a/src/language/goLanguageServer.ts +++ b/src/language/goLanguageServer.ts @@ -1027,7 +1027,9 @@ export function getLanguageServerToolPath(): string | undefined { return; } // Get the path to gopls (getBinPath checks for alternate tools). - const goplsBinaryPath = getBinPath('gopls'); + // goxls: use gopls.proxy for debug + // const goplsBinaryPath = getBinPath('gopls'); + const goplsBinaryPath = getBinPath('gopls.proxy'); if (path.isAbsolute(goplsBinaryPath)) { return goplsBinaryPath; } From e494a3d25d4a45572e471b647975caea30753bf7 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 00:01:19 +0800 Subject: [PATCH 02/10] install github.com/goplus/goxls --- tools/installtools/main.go | 25 +++++++++++++++++++------ tools/installtools/main_test.go | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/installtools/main.go b/tools/installtools/main.go index f72d468b2f..22e9384e86 100644 --- a/tools/installtools/main.go +++ b/tools/installtools/main.go @@ -16,6 +16,10 @@ import ( "strings" ) +const ( + gopVer = 0 // use `gop` instead of `go` +) + // finalVersion encodes the fact that the specified tool version // is the known last version that can be buildable with goMinorVersion. type finalVersion struct { @@ -35,7 +39,9 @@ var tools = []struct { versions []finalVersion }{ // TODO: auto-generate based on allTools.ts.in. - {"golang.org/x/tools/gopls", "", true, nil}, + // goxls: use goxls instead of gopls + // {"golang.org/x/tools/gopls", "", true, nil}, + {"github.com/goplus/goxls", "", false, []finalVersion{{gopVer, "v1.13.2"}}}, {"github.com/acroca/go-symbols", "", false, nil}, {"github.com/cweill/gotests/gotests", "", false, nil}, {"github.com/davidrjenni/reftools/cmd/fillstruct", "", false, nil}, @@ -55,13 +61,16 @@ var tools = []struct { // pickVersion returns the version to install based on the supported // version list. -func pickVersion(goMinorVersion int, versions []finalVersion, defaultVersion string) string { +func pickVersion(goMinorVersion int, versions []finalVersion, defaultVersion string) (string, bool) { for _, v := range versions { + if v.goMinorVersion == gopVer { + return v.version, true // use gop + } if goMinorVersion <= v.goMinorVersion { - return v.version + return v.version, false } } - return defaultVersion + return defaultVersion, false } func main() { @@ -140,9 +149,13 @@ func installTools(binDir string, goMinorVersion int) error { } env := append(os.Environ(), "GO111MODULE=on") for _, tool := range tools { - ver := pickVersion(goMinorVersion, tool.versions, pickLatest(tool.path, tool.preferPreview)) + ver, useGop := pickVersion(goMinorVersion, tool.versions, pickLatest(tool.path, tool.preferPreview)) path := tool.path + "@" + ver - cmd := exec.Command("go", installCmd, path) + goCmd, install := "go", installCmd + if useGop { + goCmd, install = "gop", "install" + } + cmd := exec.Command(goCmd, install, path) cmd.Env = env cmd.Dir = dir fmt.Println("go", installCmd, path) diff --git a/tools/installtools/main_test.go b/tools/installtools/main_test.go index d8b3d8de2d..98f75f0cea 100644 --- a/tools/installtools/main_test.go +++ b/tools/installtools/main_test.go @@ -37,7 +37,7 @@ func Test_pickVersion(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { for goMinorVersion, want := range tt.want { - if got := pickVersion(goMinorVersion, tt.versions, "latest"); got != want { + if got, _ := pickVersion(goMinorVersion, tt.versions, "latest"); got != want { t.Errorf("pickVersion(go 1.%v) = %v, want %v", goMinorVersion, got, want) } } From 8134eaa4e138bfe4f94b9514e95005c659a75c75 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 00:04:40 +0800 Subject: [PATCH 03/10] typo fix --- tools/installtools/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/installtools/main.go b/tools/installtools/main.go index 22e9384e86..2a9f856450 100644 --- a/tools/installtools/main.go +++ b/tools/installtools/main.go @@ -41,7 +41,7 @@ var tools = []struct { // TODO: auto-generate based on allTools.ts.in. // goxls: use goxls instead of gopls // {"golang.org/x/tools/gopls", "", true, nil}, - {"github.com/goplus/goxls", "", false, []finalVersion{{gopVer, "v1.13.2"}}}, + {"github.com/goplus/goxls", "", false, []finalVersion{{gopVer, "v0.13.2"}}}, {"github.com/acroca/go-symbols", "", false, nil}, {"github.com/cweill/gotests/gotests", "", false, nil}, {"github.com/davidrjenni/reftools/cmd/fillstruct", "", false, nil}, @@ -158,7 +158,7 @@ func installTools(binDir string, goMinorVersion int) error { cmd := exec.Command(goCmd, install, path) cmd.Env = env cmd.Dir = dir - fmt.Println("go", installCmd, path) + fmt.Println(goCmd, install, path) if out, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("installing %v: %s\n%v", path, out, err) } From f02d424529805f4f022b8407797cb303dc923d55 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 00:06:49 +0800 Subject: [PATCH 04/10] gopls.proxy => goxls --- src/language/goLanguageServer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/language/goLanguageServer.ts b/src/language/goLanguageServer.ts index 47b25e0724..dab1d419eb 100644 --- a/src/language/goLanguageServer.ts +++ b/src/language/goLanguageServer.ts @@ -1027,9 +1027,9 @@ export function getLanguageServerToolPath(): string | undefined { return; } // Get the path to gopls (getBinPath checks for alternate tools). - // goxls: use gopls.proxy for debug + // goxls: use goxls instead of gopls // const goplsBinaryPath = getBinPath('gopls'); - const goplsBinaryPath = getBinPath('gopls.proxy'); + const goplsBinaryPath = getBinPath('goxls'); if (path.isAbsolute(goplsBinaryPath)) { return goplsBinaryPath; } From 7ef4c298b732ca293ae3131c97945f33ef343a04 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 00:59:32 +0800 Subject: [PATCH 05/10] gop install -debug --- tools/installtools/main.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/installtools/main.go b/tools/installtools/main.go index 2a9f856450..d176c721b7 100644 --- a/tools/installtools/main.go +++ b/tools/installtools/main.go @@ -151,14 +151,13 @@ func installTools(binDir string, goMinorVersion int) error { for _, tool := range tools { ver, useGop := pickVersion(goMinorVersion, tool.versions, pickLatest(tool.path, tool.preferPreview)) path := tool.path + "@" + ver - goCmd, install := "go", installCmd + cmd := exec.Command("go", installCmd, path) if useGop { - goCmd, install = "gop", "install" + cmd = exec.Command("gop", "install", "-debug", path) } - cmd := exec.Command(goCmd, install, path) cmd.Env = env cmd.Dir = dir - fmt.Println(goCmd, install, path) + fmt.Println(cmd) if out, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("installing %v: %s\n%v", path, out, err) } From 79e609f375839fb96ffb818fe96fdcc696b3b668 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 01:12:32 +0800 Subject: [PATCH 06/10] don't run in vscode-gop package --- .github/workflows/test-smoke.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-smoke.yml b/.github/workflows/test-smoke.yml index 7c908e1822..8a7c37e2c8 100644 --- a/.github/workflows/test-smoke.yml +++ b/.github/workflows/test-smoke.yml @@ -43,8 +43,9 @@ jobs: - name: Install Go tools (Modules mode) run: | - go version - go run ./tools/installtools/main.go + cd .. + go version + go run ./vscode-gop/tools/installtools/main.go env: GO111MODULE: on EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}" From 604aa83b7a328ee6c2b2a6fe5e843c11df17e182 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 01:21:22 +0800 Subject: [PATCH 07/10] rm: gop install -debug --- tools/installtools/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/installtools/main.go b/tools/installtools/main.go index d176c721b7..8a7a422a7f 100644 --- a/tools/installtools/main.go +++ b/tools/installtools/main.go @@ -153,7 +153,7 @@ func installTools(binDir string, goMinorVersion int) error { path := tool.path + "@" + ver cmd := exec.Command("go", installCmd, path) if useGop { - cmd = exec.Command("gop", "install", "-debug", path) + cmd = exec.Command("gop", "install", path) } cmd.Env = env cmd.Dir = dir From 617ec0d3d825e45d056f7cca055127a39810cc6a Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 17:58:35 +0800 Subject: [PATCH 08/10] use gopls to test --- src/commands/startLanguageServer.ts | 3 ++- src/goInstallTools.ts | 10 +++++++--- src/goToolsInformation.ts | 24 +++++++++++++++++++----- src/language/goLanguageServer.ts | 18 +++++++++++------- test/gopls/index.ts | 3 +++ 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/commands/startLanguageServer.ts b/src/commands/startLanguageServer.ts index 7239167f4a..5c93287a05 100644 --- a/src/commands/startLanguageServer.ts +++ b/src/commands/startLanguageServer.ts @@ -11,6 +11,7 @@ import { GoExtensionContext } from '../context'; import { outputChannel, updateLanguageServerIconGoStatusBar } from '../goStatus'; import { getTool } from '../goTools'; import { + conf, buildLanguageClient, buildLanguageClientOption, buildLanguageServerConfig, @@ -75,7 +76,7 @@ export const startLanguageServer: CommandFactory = (ctx, goCtx) => { // If the language server is gopls, we enable a few additional features. if (cfg.serverName === 'gopls') { - const tool = getTool(cfg.serverName); + const tool = getTool(conf.lsName); if (tool) { // If the language server is turned on because it is enabled by default, // make sure that the user is using a new enough version. diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index d49cc242e1..7f8bf7b8aa 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -196,7 +196,7 @@ export async function installTools( const failed = await installToolWithGo(tool, goForInstall, envForTools); if (failed) { failures.push({ tool, reason: failed }); - } else if (tool.name === 'gopls') { + } else if (tool.name === 'goxls' || tool.name === 'gopls') { // Restart the language server if a new binary has been installed. vscode.commands.executeCommand('gop.languageserver.restart', RestartReason.INSTALLATION); } @@ -416,7 +416,11 @@ export async function promptForMissingTool(toolName: string) { // Offer the option to install all tools. installOptions.push('Install All'); } - const cmd = `go install -v ${getImportPathWithVersion(tool, undefined, goVersion)}`; + let goCmd = 'go' + if (tool.name == 'goxls') { + goCmd = 'gop' + } + const cmd = `${goCmd} install -v ${getImportPathWithVersion(tool, undefined, goVersion)}`; const selected = await vscode.window.showErrorMessage( `The "${tool.name}" command is not available. Run "${cmd}" to install.`, ...installOptions @@ -466,7 +470,7 @@ export async function promptForUpdatingTool( } let choices: string[] = ['Update']; - if (toolName === 'gopls') { + if (toolName === 'goxls' || toolName === 'gopls') { choices = ['Always Update', 'Update Once', 'Release Notes']; } if (toolName === 'dlv') { diff --git a/src/goToolsInformation.ts b/src/goToolsInformation.ts index 323795f977..7d7bbd65b0 100644 --- a/src/goToolsInformation.ts +++ b/src/goToolsInformation.ts @@ -201,7 +201,7 @@ export const allToolsInformation: { [key: string]: Tool } = { description: 'Linter', defaultVersion: 'v1.3.2' }, - 'gopls': { + 'goxls': { name: 'goxls', // goxls: Go+ importPath: 'github.com/goplus/goxls', modulePath: 'github.com/goplus/goxls', @@ -210,10 +210,24 @@ export const allToolsInformation: { [key: string]: Tool } = { description: 'Go+ Language Server', usePrereleaseInPreviewMode: true, minimumGoVersion: semver.coerce('1.18'), - latestVersion: semver.parse('v0.1.0'), - latestVersionTimestamp: moment('2023-10-11', 'YYYY-MM-DD'), - latestPrereleaseVersion: semver.parse('v0.1.0'), - latestPrereleaseVersionTimestamp: moment('2023-10-11', 'YYYY-MM-DD') + latestVersion: semver.parse('v0.13.2'), + latestVersionTimestamp: moment('2023-11-10', 'YYYY-MM-DD'), + latestPrereleaseVersion: semver.parse('v0.13.2'), + latestPrereleaseVersionTimestamp: moment('2023-11-10', 'YYYY-MM-DD') + }, + 'gopls': { + name: 'gopls', + importPath: 'golang.org/x/tools/gopls', + modulePath: 'golang.org/x/tools/gopls', + replacedByGopls: false, // lol + isImportant: true, + description: 'Language Server from Google', + usePrereleaseInPreviewMode: true, + minimumGoVersion: semver.coerce('1.18'), + 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/src/language/goLanguageServer.ts b/src/language/goLanguageServer.ts index dab1d419eb..6ec755fda3 100644 --- a/src/language/goLanguageServer.ts +++ b/src/language/goLanguageServer.ts @@ -170,7 +170,7 @@ export function scheduleGoplsSuggestions(goCtx: GoExtensionContext) { }; */ const installGopls = async (cfg: LanguageServerConfig) => { - const tool = getTool('gopls'); + const tool = getTool(conf.lsName); const versionToUpdate = await shouldUpdateLanguageServer(tool, cfg); if (!versionToUpdate) { return; @@ -184,7 +184,7 @@ export function scheduleGoplsSuggestions(goCtx: GoExtensionContext) { const toolVersion = { ...tool, version: versionToUpdate }; // ToolWithVersion await installTools([toolVersion], goVersion, true); } else { - console.log(`gopls ${versionToUpdate} is too new, try to update later`); + console.log(`goxls ${versionToUpdate} is too new, try to update later`); } } else { promptForUpdatingTool(tool.name, versionToUpdate); @@ -1029,7 +1029,7 @@ export function getLanguageServerToolPath(): string | undefined { // Get the path to gopls (getBinPath checks for alternate tools). // goxls: use goxls instead of gopls // const goplsBinaryPath = getBinPath('gopls'); - const goplsBinaryPath = getBinPath('goxls'); + const goplsBinaryPath = getBinPath(conf.lsName); if (path.isAbsolute(goplsBinaryPath)) { return goplsBinaryPath; } @@ -1074,8 +1074,8 @@ export async function shouldUpdateLanguageServer( if (!cfg) { return null; } - // Only support updating gopls for now. - if (tool.name !== 'gopls' || (!mustCheck && (cfg.checkForUpdates === 'off' || extensionInfo.isInCloudIDE))) { + // Only support updating gopls/goxls for now. + if ((tool.name !== 'gopls' && tool.name !== 'goxls') || (!mustCheck && (cfg.checkForUpdates === 'off' || extensionInfo.isInCloudIDE))) { return null; } if (!cfg.enabled) { @@ -1137,6 +1137,10 @@ export async function shouldUpdateLanguageServer( return semver.lt(usersVersionSemver!, latestVersion!) ? latestVersion : null; } +export const conf = { + lsName: 'goxls' +} + /** * suggestUpdateGopls will make sure the user is using the latest version of `gopls`, * when go.useLanguageServer is changed to true by default. @@ -1165,7 +1169,7 @@ export async function suggestUpdateGopls(tool: Tool, cfg: LanguageServerConfig): } const updateMsg = - "'gopls' is now enabled by default and you are using an old version. Please [update 'gopls'](https://github.com/golang/tools/blob/master/gopls/README.md#installation) for the best experience."; + "'goxls' is now enabled by default and you are using an old version. Please [update 'goxls'](https://github.com/goplus/goxls/blob/main/README.md#installation) for the best experience."; promptForUpdatingTool(tool.name, latestVersion, false, updateMsg); } @@ -1364,7 +1368,7 @@ export async function suggestGoplsIssueReport( // The user may have an outdated version of gopls, in which case we should // just prompt them to update, not file an issue. - const tool = getTool('gopls'); + const tool = getTool(conf.lsName); if (tool) { const versionToUpdate = await shouldUpdateLanguageServer(tool, goCtx.latestConfig, true); if (versionToUpdate) { diff --git a/test/gopls/index.ts b/test/gopls/index.ts index 4e5cf073c9..cac595ad68 100644 --- a/test/gopls/index.ts +++ b/test/gopls/index.ts @@ -7,6 +7,8 @@ import glob from 'glob'; import Mocha from 'mocha'; import * as path from 'path'; +import { conf } from '../../src/language/goLanguageServer'; + export function run(): Promise { // Create the mocha test const mocha = new Mocha({ @@ -20,6 +22,7 @@ export function run(): Promise { const testsRoot = path.resolve(__dirname, '..'); return new Promise((c, e) => { + conf.lsName = 'gopls' glob('gopls/**.test.js', { cwd: testsRoot }, (err, files) => { if (err) { return e(err); From e8f0e767bdca89b89b1a7b640538548d3cd82391 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 18:00:40 +0800 Subject: [PATCH 09/10] install gopls --- tools/installtools/main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/installtools/main.go b/tools/installtools/main.go index 8a7a422a7f..2c0f67b62d 100644 --- a/tools/installtools/main.go +++ b/tools/installtools/main.go @@ -39,8 +39,7 @@ var tools = []struct { versions []finalVersion }{ // TODO: auto-generate based on allTools.ts.in. - // goxls: use goxls instead of gopls - // {"golang.org/x/tools/gopls", "", true, nil}, + {"golang.org/x/tools/gopls", "", true, nil}, {"github.com/goplus/goxls", "", false, []finalVersion{{gopVer, "v0.13.2"}}}, {"github.com/acroca/go-symbols", "", false, nil}, {"github.com/cweill/gotests/gotests", "", false, nil}, From a7ab5edd83a863a3c74b0315f0eb71f50efc3211 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 10 Nov 2023 18:11:43 +0800 Subject: [PATCH 10/10] ts format --- src/goInstallTools.ts | 4 ++-- src/language/goLanguageServer.ts | 7 +++++-- test/gopls/index.ts | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 7f8bf7b8aa..f13756dc4f 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -416,9 +416,9 @@ export async function promptForMissingTool(toolName: string) { // Offer the option to install all tools. installOptions.push('Install All'); } - let goCmd = 'go' + let goCmd = 'go'; if (tool.name == 'goxls') { - goCmd = 'gop' + goCmd = 'gop'; } const cmd = `${goCmd} install -v ${getImportPathWithVersion(tool, undefined, goVersion)}`; const selected = await vscode.window.showErrorMessage( diff --git a/src/language/goLanguageServer.ts b/src/language/goLanguageServer.ts index 6ec755fda3..6fb1c42886 100644 --- a/src/language/goLanguageServer.ts +++ b/src/language/goLanguageServer.ts @@ -1075,7 +1075,10 @@ export async function shouldUpdateLanguageServer( return null; } // Only support updating gopls/goxls for now. - if ((tool.name !== 'gopls' && tool.name !== 'goxls') || (!mustCheck && (cfg.checkForUpdates === 'off' || extensionInfo.isInCloudIDE))) { + if ( + (tool.name !== 'gopls' && tool.name !== 'goxls') || + (!mustCheck && (cfg.checkForUpdates === 'off' || extensionInfo.isInCloudIDE)) + ) { return null; } if (!cfg.enabled) { @@ -1139,7 +1142,7 @@ export async function shouldUpdateLanguageServer( export const conf = { lsName: 'goxls' -} +}; /** * suggestUpdateGopls will make sure the user is using the latest version of `gopls`, diff --git a/test/gopls/index.ts b/test/gopls/index.ts index cac595ad68..c7fcf35307 100644 --- a/test/gopls/index.ts +++ b/test/gopls/index.ts @@ -22,7 +22,7 @@ export function run(): Promise { const testsRoot = path.resolve(__dirname, '..'); return new Promise((c, e) => { - conf.lsName = 'gopls' + conf.lsName = 'gopls'; glob('gopls/**.test.js', { cwd: testsRoot }, (err, files) => { if (err) { return e(err);