Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: Set toggle for showInferredType to switch between true,false and minimal #1412

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented Jul 31, 2023

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

Follow up from scalameta/metals#5284 (comment)

Comment on lines +919 to +934
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;
}
Copy link
Member

@dos65 dos65 Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm a bit lost with this logic.
Why false turns into true and minimal into false? 😸

Do I understand it correctly:

  • before launching server we do boolean to string migration in migrateOldSetting
  • then we register a command and perform some additional migration into enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we register a command and perform some additional migration into enum?

That's only for toggle. Previously it was only true-> false and false -> true, but now we have 3 possible options and it's still useful to have a quick option to switch things on and off. So I decided on false -> true -> minimal -> false order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgodzik oh - got it, thanks for explanation!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false -> true -> minimal -> false

That makes sense 👍

Comment on lines +919 to +934
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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false -> true -> minimal -> false

That makes sense 👍

Comment on lines +256 to +258
"false",
"true",
"minimal"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't false and true a bit unclear if value is an enum? Maybe off, minimal, all would be better? Although I guess this will be slightly incompatible change on the server side. I'm not insisting, but I'd like to hear some opinions before merging this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure this would make sense, but we would need to change the configuration on the Metals side first and make sure we take into account the old values. This change is more in line with the current state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it'll be better to set up proper enum on server side with fallback to old boolean behavior. I'm not even talking about changing names "false, "true", "minimal" but to have proper ADT on server side to avoid code like userConfig().showInferredType.contains("true") bur rather write userConfig().showInferredType.contains(ShowInferredTypes.True)

…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
@tgodzik tgodzik merged commit fdb5d15 into scalameta:main Aug 3, 2023
10 checks passed
@tgodzik tgodzik deleted the adjust-toggle branch August 3, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants