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.

Denis
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: 14665
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);
		System.out.println(linebreaks[line]);
		return linebreaks[line] + column;
	}
	
	public static void main(String[] args) {
		String model = "a\n" +
				"bb\n" +
				"ccc\n" +
				"dddd\n";
		int doit = doit(model, 3-1,2);
		System.out.println(doit);
		System.out.println(model.charAt(doit));
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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: 7655
Registered: July 2009
Senior Member
Hi

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)

Regards

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


Current Time: Thu Apr 18 19:19:27 GMT 2024

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

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

Back to the top