Skip to content

Commit

Permalink
improvement: Set toggle for showInferredType to switch between true, …
Browse files Browse the repository at this point in the history
…false and minimal

Previously, showInferredType could only be true or false. Now it is a string value that can be also of value "minimal". Because of that I switched the setting to string enum, added an automigration part and switch toggle to go through all the options
  • Loading branch information
tgodzik committed Aug 1, 2023
1 parent 00bebd9 commit 76b8f05
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
12 changes: 9 additions & 3 deletions packages/metals-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"properties": {
"metals.serverVersion": {
"type": "string",
"default": "1.0.0",
"default": "1.0.0+20-46905735-SNAPSHOT",
"markdownDescription": "The version of the Metals server artifact. Requires reloading the window. \n\n**VS Code extension version is guaranteed to work only with the default version, change if you know what you're doing**"
},
"metals.serverProperties": {
Expand Down Expand Up @@ -250,8 +250,14 @@
"markdownDescription": "List of packages you'd like to be left out of completions, symbol searches, and code actions.\n\nEx. `akka.actor.typed.javadsl` will ensure nothing in the `javadsl` package gets recommended to you.\n\nYou can find the list of default exclusions [here on the Metals website](https://scalameta.org/metals/docs/editors/user-configuration/#excluded-packages).\n\nIf you need to remove one of the defaults, you can simply include it and preface it with `--`."
},
"metals.showInferredType": {
"type": "boolean",
"markdownDescription": "When this option is enabled, for each method that have inferred types that are not explicitely specified they are displayed as additional decorations."
"type": "string",
"default": "false",
"enum": [
"false",
"true",
"minimal"
],
"markdownDescription": "When this option is set to true inferred type in all possible places will be shown. This includes types for values, definitions, cases, type parameters. With 'minimal' option Metals will not show inferred type for type parameters and more complicated pattern matches."
},
"metals.showImplicitArguments": {
"type": "boolean",
Expand Down
31 changes: 29 additions & 2 deletions packages/metals-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
detectLaunchConfigurationChanges();
configureSettingsDefaults();
registerDebugEventListener(context);

migrateOldSettings();
await window.withProgress(
{
location: ProgressLocation.Window,
Expand All @@ -157,6 +157,17 @@ export async function activate(context: ExtensionContext): Promise<void> {
);
}

function migrateOldSettings(): void {
const setting = "showInferredType";
const oldBooleanProperty = config.inspect<boolean>(setting)?.workspaceValue;
if (oldBooleanProperty !== undefined) {
config.update(
setting,
`${oldBooleanProperty}`,
ConfigurationTarget.Workspace
);
}
}
export function deactivate(): Thenable<void> | undefined {
return currentClient?.stop();
}
Expand Down Expand Up @@ -905,7 +916,23 @@ function launchMetals(
});

registerCommand("metals.toggle-show-inferred-type", () => {
toggleBooleanWorkspaceSetting("showInferredType");
const setting = "showInferredType";
const config = workspace.getConfiguration("metals");
const configProperty = config.inspect<string>(setting);
const currentValue = configProperty?.workspaceValue ?? "false";
let newValue = "true";
switch (currentValue) {
case "true":
newValue = "minimal";
break;
case "minimal":
newValue = "false";
break;
case "false":
newValue = "true";
break;
}
config.update(setting, newValue, ConfigurationTarget.Workspace);
});

registerCommand(
Expand Down

0 comments on commit 76b8f05

Please sign in to comment.