Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ISemanticModification problems
ISemanticModification problems [message #1090316] Tue, 20 August 2013 01:28 Go to next message
Chris Ainsley is currently offline Chris AinsleyFriend
Messages: 78
Registered: March 2010
Location: UK
Member
I'm using ISemanticModification for the first time and I'm having 3 issues of varying severity;

1) POSSIBLE BUG : When I insert in a new item, the indents are broken (not enough indents). I don't know why this is, but if I format manually in the document, the formatting works. I think this is perhaps that a modification to the semantic model only performs formatting local to the area of the document that has changed, and that the hierarchical indents for the modification context are not being applied.

I confirmed this bug/issue via selecting the region local to the semantic modification, and hitting CTRL+SHIFT+F and the indenting broke (everything moved to the left). When not selecting any text (whole document), and hitting CTRL+SHIFT+F, the whole document is formatted correctly including the part of the document that lost its indents.

2) USER KNOWLEDGE ISSUE : I read that the ISemanticModel requires a call to manually reformat the source editor due to these bugs (http://www.eclipse.org/forums/index.php/t/376344/), BUT, I don't know how to acquire the SourceViewer from my class which extends org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider. I've debugged into the class but can't find a reference to SourceViewer anywhere.


IXtextDocument xtextDoc = context.getXtextDocument();
SourceViewer sv = null; // Where to get it from?????
sv.doOperation(SourceViewer.FORMAT);


3) USER KNOWLEDGE ISSUE : When I create instances new items via MyDsl.eINSTANCE.createxxx(), I can't seem to control the grammar used for that particular element (there are multiple ways to present the model items).... I worked around this via a flag in the ecore model that I set to true when one particular set of semantics are used. The workaround worked, but I'm wondering if there is a way to specify the semantics of a modification via the generated object without having to set flags in the model itself?
Re: ISemanticModification problems [message #1090624 is a reply to message #1090316] Tue, 20 August 2013 12:15 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
The ISemanticModification is meant to be used for simple cases only.
Note that in general textul changes are much safer and give you far
better control. Quickfixes are often used in the context of (or even to
fix) a broken model, where there is likely no semantic model to rely on.

If you're using Xbase, we ship two helper classes that facilitate the
whitespace handling in textual changes, namely DocumentRewriter
(multiple change regions for the same fix, Xtext 2.4.3) and
ReplacingAppendable (single change region). Both also help you get the
import section right, given you're using XImportSection.

To your questions:
1)+2) You can enable formatting for all semantic changes by binding your
own DefaultTextEditComposer and overriding getSaveOptions()

3) That is not possible. We are using the serializer (unparser) which
automatically chooses the 'best' serialized form. I cannot think of an
clear and easy to understand API to choose the grammar representation of
a semantic element manually. Use textual changes if you require this
degree of freedom.


Am 20.08.13 03:28, schrieb Chris Ainsley:
> I'm using ISemanticModification for the first time and I'm having 3
> issues of varying severity;
>
> 1) POSSIBLE BUG : When I insert in a new item, the indents are broken
> (not enough indents). I don't know why this is, but if I format manually
> in the document, the formatting works. I think this is perhaps that a
> modification to the semantic model only performs formatting local to the
> area of the document that has changed, and that the hierarchical indents
> for the modification context are not being applied.
>
> I confirmed this bug/issue via selecting the region local to the
> semantic modification, and hitting CTRL+SHIFT+F and the indenting broke
> (everything moved to the left). When not selecting any text (whole
> document), and hitting CTRL+SHIFT+F, the whole document is formatted
> correctly including the part of the document that lost its indents.
>
> 2) USER KNOWLEDGE ISSUE : I read that the ISemanticModel requires a call
> to manually reformat the source editor due to these bugs
> (http://www.eclipse.org/forums/index.php/t/376344/), BUT, I don't know
> how to acquire the SourceViewer from my class which extends
> org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider. I've
> debugged into the class but can't find a reference to SourceViewer
> anywhere.
>
>
> IXtextDocument xtextDoc = context.getXtextDocument();
> SourceViewer sv = null; // Where to get it from?????
> sv.doOperation(SourceViewer.FORMAT);
>
>
> 3) USER KNOWLEDGE ISSUE : When I create instances new items via
> MyDsl.eINSTANCE.createxxx(), I can't seem to control the grammar used
> for that particular element (there are multiple ways to present the
> model items).... I worked around this via a flag in the ecore model that
> I set to true when one particular set of semantics are used. The
> workaround worked, but I'm wondering if there is a way to specify the
> semantics of a modification via the generated object without having to
> set flags in the model itself?


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: ISemanticModification problems [message #1090681 is a reply to message #1090624] Tue, 20 August 2013 13:47 Go to previous message
Chris Ainsley is currently offline Chris AinsleyFriend
Messages: 78
Registered: March 2010
Location: UK
Member
Jan Kohnlein wrote on Tue, 20 August 2013 21:15

To your questions:
1)+2) You can enable formatting for all semantic changes by binding your
own DefaultTextEditComposer and overriding getSaveOptions()


Thanks for the reply Jan.

I've overridden the getSaveOptions() in a class extending DefaultTextEditComposer() as follows:

	@Override
	protected SaveOptions getSaveOptions() {
		SaveOptions saveOptions = SaveOptions.newBuilder().format().getOptions();
		return saveOptions;
	}



I also wired it up in the UIModule, and I've confirmed via a breakpoint that it is being called. And yet, it doesn't seem to reformat the document upon a semantic modification (or an explicit save).

Is there something else that I need to wire up?
Previous Topic:Error marker is missing with StyledTextXtextAdapter
Next Topic:Extraneous / mismatched input
Goto Forum:
  


Current Time: Sat Apr 20 04:33:53 GMT 2024

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

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

Back to the top