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

Warn on Unhandled commands #1533

Merged
merged 6 commits into from
Jan 29, 2021
Merged

Conversation

maan2003
Copy link
Collaborator

No description provided.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Interesting.

I don't dislike this, but it doesn't totally fit how I use commands myself.

Basically: is_handled is way to optionally suppress the continued delivery of an event. I do not expect that all events are handled; and I wouldn't expect a widget to bother calling 'set_handled' in a situation where it was the only target of a command, for instance.

It's possible that we might want to rethink this, though? I'm certainly open to discussing, and this patch seems reasonable on its own...

@maan2003
Copy link
Collaborator Author

Yeah, I also intended this for more of a discussion but patch was simple enough that I submitted the PR.

I wouldn't expect a widget to bother calling 'set_handled' in a situation where it was the only target of a command, for instance.

I agree but do you think it is a good practice to set_handled if a widget is a sole target.

I have also thought of making warning opt in, i.e. replace @@can-ignore which will be @@must-use. So that it is less annoying. It is a logic error to ignore OPEN_FILE, for example

@rjwittams
Copy link
Collaborator

I feel like if we are going to have options on the selector to control them they should be proper fields and not bits of a string?

@cmyr
Copy link
Member

cmyr commented Jan 15, 2021

I think that having this be opt-in instead of opt-out does definitely make sense, I could see really wanting to log if certain events aren't handled.

I agree that stringly-typing here isn't great; a reasonable alternative would be adding a field to Command? Although if this is for internal use only I don't mind it being part of the string 🤷

@maan2003
Copy link
Collaborator Author

a reasonable alternative would be adding a field to Command?

maybe adding field to Selector or SelectorSymbol(making it a struct).

@maan2003 maan2003 added the discussion needs feedback and ideas label Jan 16, 2021
@cmyr
Copy link
Member

cmyr commented Jan 18, 2021

I guess it feels like, semantically, whether or not a given command needs to be handled is something related to the command, not to the selector? As in I could at least theoretically imagine a situation where I want the same selector to be used in cases where it is both expected to be handled and not. Although when I actually write this it sounds bad, so maybe not!

@rjwittams
Copy link
Collaborator

I guess this is a use site vs declaration site dichotomy. I'd normally go for declaration site so most users don't have to worry about it.

@maan2003
Copy link
Collaborator Author

Ready for Review

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Looks good, a couple little comments inline :)

@@ -384,6 +405,11 @@ impl Command {
.default_to(Target::Global)
}

/// Checks if this command must be used.
pub fn is_must_use(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

hmm, I find this name awkward, but the name I'd propose ("must_use") is used by the constructor. We could call the construct new_must_use, maybe, although that doesn't feel great either? We could also call this must_be_used which at least flows a bit better grammatically. I don't love any of these ideas... 😕

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I followed the second one because I expect Selector::must_use("..") to used much more than Command::must_be_used

selector.symbol(),
self.symbol
selector.symbol().str,
self.symbol.str
Copy link
Member

@cmyr cmyr Jan 28, 2021

Choose a reason for hiding this comment

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

instead of these changes I would manually implement Display for SelectorSymbol. Something like,

fn fmt(&self, f: Formatter) -> Result<_, _> {
    let must_use = if self.must_use {" (must use" } else { "" };
    write!(f, "{}{}", self.str, must_use)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I manually implemented Debug now. This output is not meant for end user

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@cmyr cmyr merged commit dc4e573 into linebender:master Jan 29, 2021
@maan2003 maan2003 deleted the unhandled-command-warn branch May 29, 2021 15:22
maan2003 added a commit to maan2003/druid that referenced this pull request May 30, 2021
If more than one widgets have to handle, you can not `set_handled`
because it will stop the propogation of the command. So this still
shows the warning, which is incorrect.
maan2003 added a commit to maan2003/druid that referenced this pull request May 30, 2021
If more than one widgets have to handle, you can not `set_handled`
because it will stop the propogation of the command. So this still
shows the warning, which is incorrect.
maan2003 added a commit that referenced this pull request May 31, 2021
If more than one widgets have to handle, you can not `set_handled`
because it will stop the propogation of the command. So this still
shows the warning, which is incorrect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion needs feedback and ideas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants