Skip to content

Commit

Permalink
Merge pull request #96 from gabro/upgrade-version-fix
Browse files Browse the repository at this point in the history
Improve version upgrade logic
  • Loading branch information
gabro authored Apr 12, 2019
2 parents a9cbc6e + d9b81e6 commit 83a874f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"language server",
"scalameta"
],
"version": "1.3.0",
"version": "1.3.1",
"publisher": "scalameta",
"contributors": [
{
Expand Down
40 changes: 35 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
WebviewPanel,
ViewColumn,
OutputChannel,
ConfigurationTarget
ConfigurationTarget,
WorkspaceConfiguration
} from "vscode";
import {
LanguageClient,
Expand Down Expand Up @@ -526,11 +527,40 @@ function detectLaunchConfigurationChanges() {
});
}

function serverVersionInfo(
config: WorkspaceConfiguration
): {
serverVersion: string;
latestServerVersion: string;
configurationTarget: ConfigurationTarget;
} {
const computedVersion = config.get<string>("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<string>("serverVersion")!;
const latestServerVersion = config.inspect<string>("serverVersion")!
.defaultValue!;
const {
serverVersion,
latestServerVersion,
configurationTarget
} = serverVersionInfo(config);
const isOutdated = (() => {
try {
return semver.lt(serverVersion, latestServerVersion);
Expand All @@ -557,7 +587,7 @@ function checkServerVersion() {
config.update(
"serverVersion",
latestServerVersion,
ConfigurationTarget.Global
configurationTarget
);
break;
case openSettingsAction:
Expand Down

0 comments on commit 83a874f

Please sign in to comment.