-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Only complete appropriate arguments for typed commands. #5966
Only complete appropriate arguments for typed commands. #5966
Conversation
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.
This is a nice UX Improvement and has potential for even netter followup improvements. I like that this is quite small in scope. The diff is only a bit larger because you and to.change the comlleteres for all typable commands 👍
helix-term/src/commands/typed.rs
Outdated
} | ||
|
||
#[derive(Clone)] | ||
pub enum CompletionConfig<'a> { |
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 don't think an enum is an amazing fit here. NoComoletions is just a subset of positional and this approach doesn't allow commands which have a couple positional arguments followed by varags. Instead you should simply use a list of positional arguments followed by an optional vararg completed:
strict CommandSignature{
postional_args: &'static [Option<Completer>],
var_arcs: Option<Completer>
}
You can get the compler for field n with:
self.positional_arts.get(n).unwrap_or(self.var_args)
Note that my suggestion uses a 'ststic
slice. Tgis removes the lifetime argument you were unaopy with and is a good fit here because currently all tupable commands are static anyway and if we move away from that we need to heap allocate anyway for that cade a cow would be used)
helix-term/src/commands/typed.rs
Outdated
}, | ||
TypableCommand { | ||
name: "encoding", | ||
aliases: &[], | ||
doc: "Set encoding. Based on `https://encoding.spec.whatwg.org`.", | ||
fun: set_encoding, | ||
completer: None, | ||
completer: CompletionConfig::NoCompletion, |
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.
Probably not in this this PR but in the future having an enum completer would be nice for cases like this. An autoamtic way to do that would also be useful for #4411 but I am not sure if serde allows 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.
Yeah I want to have more metadata about options in general, some discussion in #5939.
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.
Yeah that should be left to future work, just something that came to mind while reviewing
Thanks for the tips @pascalkuthe, pushed up some updates. I think your suggestion is much cleaner, especially using 'static scope. |
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 had a couple more ideas to make the API even more compact
helix-term/src/commands/typed.rs
Outdated
positional_args: &'static [Option<Completer>], | ||
|
||
// All remaining arguments will use this completion method, if set. | ||
var_args: Option<Completer>, |
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.
Actually thinking about it more I don't think we need to use Option<Completer>
here we can just use ui::completers::none
instead.
This will allow creating some utility functions (see below) to make the API a bit cleaner.
helix-term/src/commands/typed.rs
Outdated
const fn none() -> Self { | ||
Self { | ||
positional_args: &[], | ||
var_args: None, | ||
} | ||
} |
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 think adding a couple more utility constructs will go a long way towards keeping the command list short and readable.
const fn none() -> Self { | |
Self { | |
positional_args: &[], | |
var_args: None, | |
} | |
} | |
const fn none() -> Self { | |
Self { | |
positional_args: &[], | |
var_args: completers::none, | |
} | |
} | |
const fn single(completer: &'static Completer) -> Self { | |
Self { | |
positional_args: slice::from_ref(completer), | |
var_args: completers::none, | |
} | |
} | |
const fn repeat(completer: Completer) -> Self { | |
Self { | |
positional_args: &[], | |
var_args: completer, | |
} | |
} |
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.
You know it's funny I actually wrote basically the same thing first and wasn't sure if people would be comfortable with the layers of indirection. I agree and will put it back! :-)
@pascalkuthe Updates ready! :) |
Ah I actually mean that the |
Ooh, yeah. Will do.
…On Sat, Feb 18, 2023, 4:37 PM Pascal Kuthe ***@***.***> wrote:
@pascalkuthe <https://github.com/pascalkuthe> Updates ready! :)
Ah I actually mean that the positional_arguments should also be just a
Completer instead of Option<Completer> would remove all the Some(..)
wrapping (and you can always use completers:;none instead of None)
—
Reply to this email directly, view it on GitHub
<#5966 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFB2KESYNMV6MOLEHE6NKDWYE6LJANCNFSM6AAAAAAU2I5EUE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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.
LGTM now 👍
4a23125
to
09e210b
Compare
Edit: This doesn't fix #2772, it does enable the fix. It fixes my issue that was closed as duplicate, though.
I think there's a bigger change we can make here to address some other code duplication that looks something like setting argument types of commands within the TypableCommand struct and using that data both for completion and for verification of the number of arguments. Currently, some commands have checks for argument length and emit errors while others silently ignore trailing arguments.
I'm not thrilled about having variadic length completers represented as different enum variants but as we statically allocate all the command configuration I couldn't use a dynamic container.I've also left the implementation of arity 2 completers forset-option
, even though I haven't implemented a completer for option values (I've got another patch I'm working on that will dive into option metadata for #5939 and can tie that in).Edit: I realized after reading my own PR that I didn't need different variants for variadic completers, but I do need lifetime annotations to use slices. I'm probably irrationally allergic to lifetime annotations, but this does seem a bit cleaner.