Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Folding swallowed newlines (..and preview box)
Folding swallowed newlines [message #717718] Mon, 22 August 2011 07:32 Go to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hello developers.

I started to improve the look and feel of my language abit and come along to some folding behaviors. Two questions:

1. My grammar contains a C# #region like element:
terminal REGION_START: '#region' !('\n'|'\r')* ('\r'? '\n')?;
terminal REGION_END: '#endregion' !('\n'|'\r')* ('\r'? '\n')?;
Group:
    start = REGION_START 
    declarations += Declaration* 
    end = REGION_END
;

I created an ILocationInFileProvider which provides the start assignment as identifier feature. This enabled folding for this element. The problem: The first newline after the region is swallowed by the folding.

#region Unfolded
...
#endregion

CONST = 1;
//-------------
#region [...]
CONST = 1;


Is there a possibility to adjust how many newlines are rendered after the group?

2. Can I adjust the text which is displayed during the folding? By default '..' is displayed in the small box. For groups I want to display the start text.

I hope this is possible

Cheers
Daniel
Re: Folding swallowed newlines [message #717744 is a reply to message #717718] Mon, 22 August 2011 08:39 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

have you debugged into the DefaultFoldingRegionProvider? I am not sure what you mean by "swallowed", but if I guess correctly the behavior is caused by the new line actually belonging to the REGION_END terminal.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Folding swallowed newlines [message #717771 is a reply to message #717744] Mon, 22 August 2011 09:39 Go to previous messageGo to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hi.

Oh yes, I forgot to mention that the 'swallowed' newline belongs to the REGION_END terminal. I thought that would be clear because of the grammar sample I posted.

I could override the getFullTextRegion method of the ILocationInFileProvider in order to remove the last newline, but as the calculation is done viá the NodeModel it is not that easy to simply remove a trailing newline. I tried to play around with the node model and calculate the region myself but I couldn't find a clean way to detect where the text ends.

I thought it would be easier if there was some kind of "display an additional line if collapses" - feature.

[edit]
I just found a solution. (Everytime after I post my problems I find solutions Laughing )

I simply use getText of my node and trim it to get the length. This length seems to work fine on each usecase.


  protected ITextRegion getTextRegion(EObject obj, boolean isSignificant) {
    
    if(obj instanceof Group && !isSignificant) {
      
      ICompositeNode node = NodeModelUtils.findActualNodeFor(obj);
      if (node == null) {
        if (obj.eContainer() == null)
          return ITextRegion.EMPTY_REGION;
        return getTextRegion(obj.eContainer(), isSignificant);
      }

      return new TextRegion(node.getOffset(), node.getText().trim().length());
    }
    return super.getTextRegion(obj, isSignificant);
  }



Now only the second part is open.

[Updated on: Mon, 22 August 2011 09:43]

Report message to a moderator

Re: Folding swallowed newlines [message #718120 is a reply to message #717771] Tue, 23 August 2011 10:13 Go to previous message
Michael Clay is currently offline Michael ClayFriend
Messages: 9
Registered: July 2009
Junior Member
2. Can I adjust the text which is displayed during the folding? By default '..' is displayed in the small box. For groups I want to display the start text.

-> yes its configurable by simply injecting your implementation of interface org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy into
org.eclipse.xtext.ui.editor.XtextEditor#projectionAnnotationDrawingStrategy (i.e. you have to adapt/extend your ui-module)
Previous Topic:Xpand/Xtend editor errors
Next Topic:Model instance( derived from the metamodel .ecore) to Java code using xtend2
Goto Forum:
  


Current Time: Fri Mar 29 15:03:45 GMT 2024

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

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

Back to the top