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

keep with_prototype when switching contexts with set #177

Merged
merged 6 commits into from
Jun 12, 2018

Conversation

keith-hall
Copy link
Collaborator

This implements @robinst's fix from #166 (comment) with a minimal test case, to keep the with_prototype context active when a context is set - only when a pop occurs at that layer should the with_prototype be removed.

@@ -613,7 +613,9 @@ impl ParseState {
// top most on the stack after all the contexts are pushed - this is also
// referred to as the "target" of the push by sublimehq - see
// https://forum.sublimetext.com/t/dev-build-3111/19240/17 for more info
let proto = if i == ctx_refs.len() - 1 {
let proto = if i == 0 && pat.with_prototype.is_none() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a comment here, and move the existing comment into the if?

Also, I wasn't sure what ST does with a set with multiple contexts, have you tested that?

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 have, it is the same behavior as with push - the with_prototype only applies to the last context (that will be at the top of the stack after the set/push operation).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant when we keep the existing with_prototype. In that case, should the code not use i == ctx_refs.len() - 1 instead of i == 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you're quite right, thanks @robinst - I've corrected it and added some extra test cases for this.

@robinst
Copy link
Collaborator

robinst commented Jun 11, 2018

LGTM.

We could put both of the cases in a single if i == ctx_refs.len() - 1 now, and then do something like pat.with_prototype.or(old_prototype). But that would make it harder to put in the comments, not sure what @trishume thinks.

Copy link
Owner

@trishume trishume 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, I like @robinst's suggestion though so if you have time making that change would be good, just join the comments together. If you don't have time it's fine as is and I'm happy to merge.

// if a with_prototype was specified, and multiple contexts were pushed,
// then the with_prototype applies only to the last context pushed, i.e.
// top most on the stack after all the contexts are pushed - this is also
// referred to as the "target" of the push by sublimehq - see
// https://forum.sublimetext.com/t/dev-build-3111/19240/17 for more info
pat.with_prototype.clone()
pat.with_prototype.clone().or(old_proto.clone())
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure if this is actually a hot spot or not, but I hadn't realized that or would need a clone. Maybe use or_else here.

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'm having trouble with that, maybe you could take a quick go at this please:

the trait `std::ops::FnOnce<()>` is not implemented for `std::option::Option<std::rc::Rc<std::cell::RefCell<parsing::syntax_definition::Context>>>`

Copy link
Owner

Choose a reason for hiding this comment

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

Oh it takes a closure not a value, that's why it's more efficient, it only clones the value when necessary. So it would look like .or_else(|| old_proto.clone())

@trishume trishume merged commit 9374fe9 into trishume:master Jun 12, 2018
@keith-hall keith-hall deleted the set_with_prototype branch June 12, 2018 13:51
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