Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » AbstractFormatter2
AbstractFormatter2 [message #1851241] Thu, 31 March 2022 15:09 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
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 17:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 31 March 2022 17:18]

Report message to a moderator

Re: AbstractFormatter2 [message #1851247 is a reply to message #1851246] Thu, 31 March 2022 17:25 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
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 18:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
so you do not call formatter explicitely?
if no how do you create textual model?!?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: AbstractFormatter2 [message #1851251 is a reply to message #1851250] Thu, 31 March 2022 18:38 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
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 19:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You can do a rightklick format on the dsl editor?
How do you expect the formatter to be executed ?!?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 31 March 2022 19:20]

Report message to a moderator

Re: AbstractFormatter2 [message #1851256 is a reply to message #1851255] Thu, 31 March 2022 19:21 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Reference Epackage
Next Topic:Update language server UI in non UI thread
Goto Forum:
  


Current Time: Fri Apr 26 06:51:51 GMT 2024

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

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

Back to the top