Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XtextDocument/Node does not update offset ?
XtextDocument/Node does not update offset ? [message #1843178] Mon, 19 July 2021 10:09 Go to next message
Ryana Karaki is currently offline Ryana KarakiFriend
Messages: 19
Registered: May 2021
Junior Member
Hello,

I am working on a debugging plug in and am trying to add comments programmatically in the DSL file.
The comments appear next to an updated variable, and show what changed (just like an IntelliJ
debugger). With the comment, I want to highlight the element like this :
https://zupimages.net/up/21/29/965j.png

However, when I add the comment, I end up with this :
https://zupimages.net/up/21/29/k9cp.png

I add my comments in the current XtextEditor's XtextDocument, with :
document.replace(commentOffset, 0, commentToAdd);
editor.doSave(new NullProgressMonitor());


To highlight my document, I create different StyleRange around my elements of interest. I retrieve my elements' position with :
INode node = NodeModelUtils.getNode(objectToStyle);
node.getOffset();


Then, I provide my editor with a new TextPresentation, that has all of my new style ranges :
	
public void showAllHighlights() {
	Display.getDefault().syncExec(new Runnable() {
	     @Override
	     public void run() {
				XtextEditor editor = EditorUtils.getActiveXtextEditor();
				for(StyleRange s : ranges) {
					TextPresentation textPres = new TextPresentation();
					textPres.addStyleRange(new StyleRange(s.start, s.length, s.foreground, s.background, SWT.BOLD));
					editor.getInternalSourceViewer().changeTextPresentation(textPres, true);
				}
			}
	});
}


It seems that after adding my comment, my file does not consider it exists ? My second node's
offset does not change.

Does anyone now what might be the issue here ?
Re: XtextDocument/Node does not update offset ? [message #1843179 is a reply to message #1843178] Mon, 19 July 2021 10:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
is there any reason you dont use codeminings for this feeature?
can you elaborate on "my file does not consider it exists ? "
i also wonder why you dont use normal semantic highlighting for this
(i would have assumed the highlighting reconciler called after the model change.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XtextDocument/Node does not update offset ? [message #1843180 is a reply to message #1843179] Mon, 19 July 2021 11:23 Go to previous messageGo to next message
Ryana Karaki is currently offline Ryana KarakiFriend
Messages: 19
Registered: May 2021
Junior Member
Hello,

I am sorry, I did not understand your answer. As I said in previous posts, I am a beginner in Xtext, which might be why I do not understand.

What do you mean by "codemining" & "i would have assumed the highlighting reconciler called after the model change" ?

By "my file does not consider it exists", I wondered if my comment did not count as "new characters" in the XtextDocument :
If you look again at the two images I posted, I want to highlight two nodes, and I do so by retrieving their offset first. However,
the second node's offset is wrong. I end up in the comment instead of at the beginning of my node.

About the normal semantic highlight : do you speak about the language's keywords highlighting for instance ?
The highlighting & commenting that I want to do is dynamic : the updated value is highlighted & commented for a certain amount of time.
If the value does not change, the value is not highlighted.

These changes are applied at runtime.

[Updated on: Mon, 19 July 2021 11:24]

Report message to a moderator

Re: XtextDocument/Node does not update offset ? [message #1843181 is a reply to message #1843180] Mon, 19 July 2021 11:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
Xtext has support for eclipse codeminings
https://blogs.itemis.com/en/code-mining-support-in-xtext

and no i mean semantic highlighting as described blow https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#highlighting

regarding offset: i dont see "where" you call this code. i assume you have to wait for the reparse to have happened.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XtextDocument/Node does not update offset ? [message #1843205 is a reply to message #1843181] Tue, 20 July 2021 07:50 Go to previous message
Ryana Karaki is currently offline Ryana KarakiFriend
Messages: 19
Registered: May 2021
Junior Member
Codeminings seem to be a better alternative for what I want to do, I'm looking into it, thanks!

I want to highlight my elements without accessing the DSL's files, so I do not want to edit the DSL's
modules with bindings (the long term objective is to have a DSL-independent plug in). Thus I call
the code at runtime, when the proper actions/triggers are executed.
Previous Topic:Xtext and Java 16
Next Topic:Using LocalDateTime in Xtext Grammar
Goto Forum:
  


Current Time: Wed Jul 28 23:21:30 GMT 2021

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

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

Back to the top