Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Compute offset from position (line,col)
Compute offset from position (line,col) [message #1840283] Sun, 11 April 2021 11:54 Go to next message
Denis Kuniß is currently offline Denis KunißFriend
Messages: 15
Registered: March 2015
Junior Member
Hi folks,

I need to compute the offset from an external provided line and column based position in the context of a validator.

Does anybody has a hint for me how to achieve this?

I know the org.eclipse.xtext.ide.server.Document#getOffSet() can do this. However, how can I obtain the Document object from the context of the validator.
Any hint is highly appreciated.

What I want to achieve is to add error and warning markers from an externally done compilation and provide this via Language Server and Eclipse Plugin interfaces.

Re: Compute offset from position (line,col) [message #1840287 is a reply to message #1840283] Sun, 11 April 2021 16:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14497
Registered: July 2009
Senior Member
hi, i have no idea for that. maybe you can recycle InternalNodeModelUtils like

public class X extends InternalNodeModelUtils {

	public static int doit(String text, int line, int column) {
		//TODO test and zero baseing etc
		int[] linebreaks = computeLineBreaks(text);
		return linebreaks[line] + column;
	public static void main(String[] args) {
		String model = "a\n" +
				"bb\n" +
				"ccc\n" +
		int doit = doit(model, 3-1,2);

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Re: Compute offset from position (line,col) [message #1840290 is a reply to message #1840287] Sun, 11 April 2021 18:20 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7595
Registered: July 2009
Senior Member

When you start the validator you can put as many interesrting objects as you like in the validation context. e.g

validationContext.put(XtextDocument.class, xtextDocument)


Ed Willink
Previous Topic:SecurityException in Maven build
Next Topic:Supressing content assist auto activation in DSL comments
Goto Forum:

Current Time: Wed Jun 07 01:36:26 GMT 2023

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

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

Back to the top