Skip to main content



      Home
Home » Modeling » TMF (Xtext) » AbstractFormatter2
AbstractFormatter2 [message #1851241] Thu, 31 March 2022 11:09 Go to next message
Eclipse UserFriend
Hi,

I am trying to rewrite the formatter for a dsl. I have made the change in MyDslFormatter.xtend, I have generated Xtext artefacts, ran a new runtime instance, and there I have made change to the grammar via the tree editor, to see if the formatter would work, but nothing. The formatter file looks fine. Could there be any intermediate step that I am not aware of?

Thank you,
John
Re: AbstractFormatter2 [message #1851246 is a reply to message #1851241] Thu, 31 March 2022 13:16 Go to previous messageGo to next message
Eclipse UserFriend
did you check the formatter examples + tests in example projects shipped with xtext?
is your formatter called?
did you just create it or did you tell the workflow to create it?
formatter = {
generateStub=true
generateXtendStub=true
}

this will also add bindings to abstractyourdsl module

[Updated on: Thu, 31 March 2022 13:18] by Moderator

Re: AbstractFormatter2 [message #1851247 is a reply to message #1851246] Thu, 31 March 2022 13:25 Go to previous messageGo to next message
Eclipse UserFriend
Yes, I did it according to the DomainModel Example. I added these lines that you have mentioned here in the mwe I ran it, got the formatter, and made the changes there. Then I generated Xtext artefacts, ran a runtime instance, made changes in the tree editor, but they were not reflected in the textual file.
Re: AbstractFormatter2 [message #1851250 is a reply to message #1851247] Thu, 31 March 2022 14:04 Go to previous messageGo to next message
Eclipse UserFriend
so you do not call formatter explicitely?
if no how do you create textual model?!?
Re: AbstractFormatter2 [message #1851251 is a reply to message #1851250] Thu, 31 March 2022 14:38 Go to previous messageGo to next message
Eclipse UserFriend
No, all I do is add this to the mwe
 formatter = {
	generateStub = true
	generateXtendStub = true
}

I run it and then in the MyDslFormatter.xtend

I write something similar to this:

package org.xtext.example.mydsl.formatting2

import com.google.inject.Inject

import org.eclipse.xtext.formatting2.AbstractFormatter2
import org.eclipse.xtext.formatting2.IFormattableDocument
import org.xtext.example.mydsl.mydsl.Root
import org.xtext.example.mydsl.services.MyDslGrammarAccess

class MyDslFormatter extends AbstractFormatter2 {
	
	@Inject extension MyDslGrammarAccess

	def dispatch void format(Root root, extension IFormattableDocument document) {
	root.regionFor.keyword("this").prepend[newLine]
	root.regionFor.keyword("{").prepend[newLine]
}


Generate Xtext artefacts, open the runtime instance, New-> Other->MyDsl Model

Should I call the formatter somewhere explicitly?
Re: AbstractFormatter2 [message #1851255 is a reply to message #1851251] Thu, 31 March 2022 15:20 Go to previous messageGo to next message
Eclipse UserFriend
You can do a rightklick format on the dsl editor?
How do you expect the formatter to be executed ?!?

[Updated on: Thu, 31 March 2022 15:20] by Moderator

Re: AbstractFormatter2 [message #1851256 is a reply to message #1851255] Thu, 31 March 2022 15:21 Go to previous message
Eclipse UserFriend
And of course you might need to traverse to the object that has the keywords you mention
Debug the region for calls
They should not return null
Previous Topic:Reference Epackage
Next Topic:Update language server UI in non UI thread
Goto Forum:
  


Current Time: Fri Jun 13 16:23:01 EDT 2025

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

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

Back to the top