XtextDocument/Node does not update offset ? [message #1843178] |
Mon, 19 July 2021 10:09 |
Ryana Karaki 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 :
However, when I add the comment, I end up with this :
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 #1843180 is a reply to message #1843179] |
Mon, 19 July 2021 11:23 |
Ryana Karaki 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03930 seconds