-
-
Notifications
You must be signed in to change notification settings - Fork 116
Fix Remove operation for flow mappings and sequences #1020
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
base: main
Are you sure you want to change the base?
Conversation
| // Check if the parent content contains a flow mapping or flow sequence | ||
| if parent_content.contains('{') && parent_content.contains('}') { | ||
| // This is a flow mapping (possibly within a block mapping) | ||
| handle_flow_mapping_removal_in_context( | ||
| document, | ||
| &parent_feature, | ||
| &patch.route, | ||
| content, | ||
| ) | ||
| } else if parent_content.contains('[') && parent_content.contains(']') { | ||
| // This is a flow sequence (possibly within a block mapping) | ||
| handle_flow_sequence_removal_in_context( | ||
| document, | ||
| &parent_feature, | ||
| &patch.route, | ||
| content, | ||
| ) |
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 concerned these kinds of checks aren't sound/won't generalize, e.g. here's a parent context that will pass the first branch here but is actually meant for the second:
{[
foo: bar,
baz: abc,
]}(and same for flow mappings inside of flow arrays, e.g. [{foo: bar}])
Do you have any thoughts on how to generalize these? I don't have a great sense for what would work well here -- I think testing for individual tokens without knowing where they are in the syntax tree will unfortunately be too brittle 😞
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'll have a look tonight.
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 tried to implement this using tree-sitter, but gave up because of complexity. Instead I added two skipped tests to do it in the future (in a separate PR).
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.
Okay, thanks! I'll have another look tomorrow.
|
(Just noting that I haven't forgotten about this, I've just been thinking about it -- the current |
|
Thanks for the update. It is really mind-boggling. I wish we could completely move to tree-sitter for |
Problem
The
Removeoperation used naive line-based removal that broke YAML structure for flow styles:{a: valueA, b: valueB}=> removingbwould delete the entire line, corrupting the document[item1, item2, item3]=> removingitem2would delete the entire lineSolution
block_mapping_pair,flow_pair,block_sequence_item) toFeature::kind()Testing
Added a few tests covering all YAML styles and some corner cases.
Known Limitations
Added two skipped tests to show how brittle nested structure detection is. This is a TODO for future.
xref #876