eclipse-xtext / eclipse-xtext/xtext
[formatting2] Conditional formatting branches influence each other
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Description
I stumbled upon an issue where branches of IFormattableDocument::formatConditionally actually modify the text replacers of the parent document, leading to leftover formatting in the other branches.
I managed to track down the code responsible for modifying the IHiddenRegionFormatters to this method in the class HiddenRegionFormattingMerger:
public IHiddenRegionFormatting merge(List<? extends IHiddenRegionFormatting> conflicting) {
// If there are only 2 conflicts,
// usages of this method expect the second value to be updated to the merge result
// TODO: Fix those usages so they no longer expect this method to edit its input
> if (conflicting.size() == 2) {
> conflicting.get(1).mergeValuesFrom(conflicting.get(0));
> return conflicting.get(1);
> }
IHiddenRegionFormatting result = formatter.createHiddenRegionFormatting();
// Reversed so the merging order is consistent with the special case above
for (IHiddenRegionFormatting conflict : Lists.reverse(conflicting))
result.mergeValuesFrom(conflict);
return result;
}
See the scary TODO comment.
Removing those first lines solves my issue. As a workaround I'm now using a custom IMerger<IHiddenRegionFormatting>.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with org.eclipse.xtext/src/org/eclipse/xtext/formatting2/internal/HiddenRegionFormattingMerger.java and inspect usages of merge that expect it to edit an input. Trace formatConditionally and its branch formatting to understand the shared state, then add or update regression coverage. Done means conditional-formatting branches no longer leave formatting in sibling branches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100