-
Notifications
You must be signed in to change notification settings - Fork 755
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/option delegated properties #616
Refactor/option delegated properties #616
Conversation
While it is conceptually very similar to StringOption, the implementation of list vs not-list operations are very different, and having a separate type will allow us to do more interesting things with overloading when we introduce delegate properties
Also migrates tests to use new properties
Also fixes some incorrect usages of local options as global, e.g. 'ideajoin' and 'scroll'. There are some options that should be local that are only ever accessed at global scope. These need fixing in the future, e.g. 'iskeyword', 'matchpairs' and 'virtualedit'
* Convenience function to get the IntelliJ implementation specific option accessor for the given editor's scope | ||
*/ | ||
@Suppress("UnusedReceiverParameter") | ||
public fun VimInjector.ijOptions(editor: VimEditor): EffectiveIjOptions = getEffectiveIjOptions(editor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too keen on this, but we can't upcast VimOptionGroup
to IntelliJ's OptionGroup
because we re-implement the VimOptionGroup
in tests. An alternative would be to create an IjVimOptionGroup
interface to access IntellIJ specific options, and have the test class also implement this interface. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that we reimplement it by OptionsTracer? If yes, I'd comment out OptionsTracer as this should not affect the architecture decisions.
This looks good to me! But still, I'd love to see some historical notes like:
Also, I'd love to see some small instructions on how to add a new option. Like what classes should be affected by that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is so clean now, thank you!
@AlexPl292 Just pushed some minor updates to address comments |
This PR introduces strongly typed delegated properties to get and set option values. Options of primitive type are implemented as read/write properties with native types, e.g.
String
,Int
andBoolean
, which makes it very easy to get/set an option value from code. String list options are represented as a read only property of typeStringListOptionValue
.E.g.:
The options are accessed via
injector.globalOptions()
andinjector.options(editor)
functions, similar to howOptionsValueAccessor
was used. TheOptionsValueAccessor
class has been removed in favour of the strongly typed properties. TheVimOptionGroup.setOptionValue
function can be used to set an option found at runtime viaVimOptionGroup.getOption
.The
StringListOptionValue
type implementsList<String>
, so the values can be iterated, or a specific item can be checked within
orcontains
. It also implements theappendValue
,prependValue
andremoveValue
helpers to make it easy to modify the string list. The underlying string is available through thevalue
property.String list options can be used like: