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

Refactor options service #602

Merged
merged 24 commits into from
Mar 10, 2023

Conversation

citizenmatt
Copy link
Member

This PR is a set of refactorings on the options service:

  • Mark old code that is still in use by (current and previous versions of) extensions as deprecated, e.g. OptionsManager.
  • Move options related code to options package (e.g. com.maddyhome.idea.vim.vimscript.services.OptionValueAccessor to com.maddyhome.idea.vim.options.OptionValueAccessor. Some code still used by extensions is left in place, marked as deprecated, but with enough functionality forwarded to new code, e.g. ToggleOption, replaced with a new instance of ToggleOption in the correct package.
  • Introduce VimOptionGroup and expose on injector. Can no longer use OptionsService as this is still used by external code, and now marked as deprecated.
  • Simplify the options service interface (VimOptionGroup)
    • Push :set command specific validation out of the interface and into the implementation of SetCommand. Internal callers no longer need to pass in a "token" used for user facing exception messages when getting or setting option values
    • Extract helper setter functions from interface into extension methods. The interface is now more focussed on managing options, with a single setter and a single getter function. Helper methods for toggling options, resetting defaults, appending/remove values, etc. are now handled as extension functions.

@AlexPl292 AlexPl292 requested review from lippfi and AlexPl292 and removed request for lippfi February 23, 2023 07:42
Comment on lines 99 to 104
) {
(injector.optionGroup.getOption(IjOptionConstants.ideajoin) as? ToggleOption)?.let { option ->
injector.optionGroup.setToggleOption(option, OptionScope.GLOBAL)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Now it has become more complicated and requires more letters. It would be nice to have something more compact for more comfortable interaction with options.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've made some changes to make it a little easier to set options - specifically, introduced getKnownOption, GetKnownStringOption and GetKnownToggleOption. These return an Option, do not return null, and can be passed straight to the helper functions to set the option value, set/unset toggles, etc. They must be called with a known option name or they will fail/throw.

It's a little more work than passing a string name in, but not by much. Using a name based API requires an extra parameter to make the validation error messages work for user facing functionality, and most code that sets options wouldn't have an appropriate value available. And since there are very few places that need to set options, compared to reading options, it's not worth adding an extra set of name based extension functions/overloads to fetch the option and then fetch the value of the option. We can let the caller do this, and it can either do validation of the returned option if it wants, or use the getKnownOption functions to show intent and fetch a well-known option that it knows is always available, such as the options listed in OptionConstants.

Cast succeeds, but only due to erasure
Moves ToggleOption to the proper package, leaving behind a skeleton class to keep ideavim-sneak and IdeaVim-EasyMotion happy.

Removes NumberOption and related number OptionsManager properties which are only used by which-key 0.6.2, because this plugin is already broken due to a separate API change. (The plugin is expecting the command trie to use `CommandPartNode<ActionBeanClass>`, but it's actually using `CommandPartNode<VimActionsInitiator>`). Also removes `ToggleOption.value`, used by which-key
Leaves a skeleton, deprecated implementation of OptionService for existing external use by plugins
Moves functions that require validation parameters to extension functions. Core interface should not require additional user facing paramter
The interface now has a simple setter and getter, as well as other functions for managing options. More friendly functions for getting and setting values are available as extension functions
@citizenmatt citizenmatt force-pushed the refactor/options-obsolete-api branch from 6755cb0 to 2de7d72 Compare March 8, 2023 01:39
@citizenmatt
Copy link
Member Author

Force pushed rebased against current master

@lippfi lippfi merged commit c192f31 into JetBrains:master Mar 10, 2023
@lippfi
Copy link
Contributor

lippfi commented Mar 10, 2023

Thanks a lot for your work with this PR!

@citizenmatt citizenmatt deleted the refactor/options-obsolete-api branch March 15, 2023 01:03
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.

3 participants