Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Compute offset from position (line,col)
Compute offset from position (line,col) [message #1840283] Sun, 11 April 2021 07:54 Go to next message
Eclipse UserFriend
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 12:05 Go to previous messageGo to next message
Eclipse UserFriend
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));
	}
	
}
Re: Compute offset from position (line,col) [message #1840290 is a reply to message #1840287] Sun, 11 April 2021 14:20 Go to previous message
Eclipse UserFriend
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 May 15 21:43:30 EDT 2025

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

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

Back to the top