From b571b3eab10f7771f48676e35f5b7396d66a4ff8 Mon Sep 17 00:00:00 2001 From: Gabriele Petronella Date: Fri, 12 Apr 2019 18:40:30 +0200 Subject: [PATCH 1/2] Improve version upgrade logic Before this PR we detected when the user was running and old version of Metals, and proposed to upgrade. However the upgrade happened only in the Global (aka User) configuration, meaning that a user that had an outdated version set in the Workspace or Workspace Folder Configuration would see the "Old version detected" message again. This PR fixes by inspecting the chain of configurations and finding the one that is setting the old version, and upgrading it. E.g. if you had Global: 0.4.0 Workspace: 0.4.0 WorkspaceFolder: not set Now we correctly bring you to Global: 0.4.0 Workspace: 0.5.0 WorkspaceFolder: not set If you then open another workspace where there is no specific setting: Global: 0.4.0 Workspace: not set WorkspaceFolder: not set we then propose to upgrade again and bring you to Global: 0.5.0 Workspace: not set WorkspaceFolder: not set --- src/extension.ts | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index d1c530af5..e97baccbe 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,7 +14,8 @@ import { WebviewPanel, ViewColumn, OutputChannel, - ConfigurationTarget + ConfigurationTarget, + WorkspaceConfiguration } from "vscode"; import { LanguageClient, @@ -526,11 +527,40 @@ function detectLaunchConfigurationChanges() { }); } +function serverVersionInfo( + config: WorkspaceConfiguration +): { + serverVersion: string; + latestServerVersion: string; + configurationTarget: ConfigurationTarget; +} { + const computedVersion = config.get("serverVersion")!; + const { defaultValue, workspaceFolderValue, workspaceValue } = config.inspect< + string + >("serverVersion")!; + const configurationTarget = (() => { + if (workspaceFolderValue && workspaceFolderValue !== defaultValue) { + return ConfigurationTarget.WorkspaceFolder; + } + if (workspaceValue && workspaceValue !== defaultValue) { + return ConfigurationTarget.Workspace; + } + return ConfigurationTarget.Workspace; + })(); + return { + serverVersion: computedVersion, + latestServerVersion: defaultValue!, + configurationTarget + }; +} + function checkServerVersion() { const config = workspace.getConfiguration("metals"); - const serverVersion = config.get("serverVersion")!; - const latestServerVersion = config.inspect("serverVersion")! - .defaultValue!; + const { + serverVersion, + latestServerVersion, + configurationTarget + } = serverVersionInfo(config); const isOutdated = (() => { try { return semver.lt(serverVersion, latestServerVersion); @@ -557,7 +587,7 @@ function checkServerVersion() { config.update( "serverVersion", latestServerVersion, - ConfigurationTarget.Global + configurationTarget ); break; case openSettingsAction: From d9b81e6b9415a7502bb17acd6005b14e80b9fb41 Mon Sep 17 00:00:00 2001 From: Gabriele Petronella Date: Fri, 12 Apr 2019 18:48:28 +0200 Subject: [PATCH 2/2] Bump patch version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 52ad9cf17..fd797f2e4 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "language server", "scalameta" ], - "version": "1.3.0", + "version": "1.3.1", "publisher": "scalameta", "contributors": [ {