Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to implement nested conditional formatting?
How to implement nested conditional formatting? [message #1840213] Thu, 08 April 2021 20:04 Go to next message
Dimo Petroff is currently offline Dimo PetroffFriend
Messages: 16
Registered: November 2018
Junior Member
I have this exception in my formatter:
org.eclipse.xtext.formatting2.internal.ConflictingRegionsException: Conflicting Regions.
{{{}}}: ConditionalReplacer at offset=3063 length=33
[[[]]]: ConditionalReplacer at offset=3050 length=47
------------------------------- document snippet -------------------------------

	call
	[
	thing|something or another . chained] - too    .
	long    [[[[     for
	| {{{the
	.previous (
	line=     -1
	)}}}]]]] < same
	.
	thing
	[
--------------------------------------------------------------------------------

What I'm trying to achieve is an Xtend-style lambda function, which should be conditionally formatted on multiple lines if it's too long, and the expressions in the lambda might include a feature call with arguments, which are also conditionally formatted on individual lines if they do not fit on one line. I would have expected nested conditional formatting regions to be the solution, but that results in the exception above.
Re: How to implement nested conditional formatting? [message #1860507 is a reply to message #1840213] Thu, 10 August 2023 14:25 Go to previous messageGo to next message
Oscar Ablinger is currently offline Oscar AblingerFriend
Messages: 6
Registered: August 2023
Junior Member
Hey Dimo, did you ever figure out how to do this?
Re: How to implement nested conditional formatting? [message #1860525 is a reply to message #1860507] Sat, 12 August 2023 05:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14720
Registered: July 2009
Senior Member
In all cases a reproducer would help

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to implement nested conditional formatting? [message #1860541 is a reply to message #1860525] Mon, 14 August 2023 15:00 Go to previous message
Oscar Ablinger is currently offline Oscar AblingerFriend
Messages: 6
Registered: August 2023
Junior Member
So I figured out what the problem was on my end. For those coming from google, the problem is most likely that you're using the wrong document at some point.

For me it happened in these cases:

1. You use the outside document in the "formatConditionally" sub formatters.

ISubFormatter subFormatter = (subDoc) -> {
  document.append(...); // this will produce this error. Use subDoc instead
};

document.formatConditionally(obj, subFormatter);


2. You use the same document that you called "requireFitsInLine" on.

This was the one that caught me: That method returns another "IFormattableSubDocument" and any other formatting that you want to do in the range of the original document now has to be done over that returned document.

// wrong
document.requireFitsInLine();
document.append(...); // this will produce this error. requireFitsInLine already reserves the entirety of document so no other formatters can touch it

// correct
document = document.requireFitsInLine();
document.append(...);

Previous Topic:Efficiently getting EObjects of a particular type given only their parent Xtext+Sirius IProject
Next Topic:Formatting: Best practices around ownership of surrounding hidden regions
Goto Forum:
  


Current Time: Thu Oct 03 11:26:43 GMT 2024

Powered by FUDForum. Page generated in 0.03390 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top