Skip to main content



      Home
Home » Modeling » TMF (Xtext) » How to autowrap comments
How to autowrap comments [message #1785976] Mon, 23 April 2018 13:43 Go to next message
Eclipse UserFriend
Hello,

I would like to have the XText formatter of my language auto-wrap multi-line comments, and maybe even single-line comments (by joining together successive single-line comments).

So far I have been able to perform auto-wrapping for semantic elements by calling "autowrap" before or after certain keywords of the grammar. However comments are handled by MultilineCommentReplacer and SinglelineDocCommentReplacer.

I know that I can provide my own implementations of these classes by overriding AbstractFormatter2::createCommentReplacer() but I have no idea what I should do in the implementations that I provide.

Any hints? :)

Thanks!

--
Elie
Re: How to autowrap comments [message #1785978 is a reply to message #1785976] Mon, 23 April 2018 14:14 Go to previous messageGo to next message
Eclipse UserFriend
i have no idea how to properly implement it or elegantly but if you move to logic completely to your code you could try something like (just a starting point

if(ruleName.startsWith("ML")) return new MultilineCommentReplacer(comment, Character.valueOf('*').charValue) {
				
				override createReplacements(ITextReplacerContext context) {
					var ITextRegionAccess access = comment.getTextRegionAccess();
					val region = access.regionForOffset(comment.offset, comment.length)
					context.addReplacement(region.replaceWith("/* TODO */"))
					context
				}
				
			}
Re: How to autowrap comments [message #1786051 is a reply to message #1785978] Tue, 24 April 2018 17:19 Go to previous message
Eclipse UserFriend
Great, thanks for the pointer Christian! I managed to hack a small wrapping algorithm to produce the replacement with your code snippet.
Previous Topic:Formatter is discarding empty lines between comments
Next Topic:Breakpoint in xtext dsl editor
Goto Forum:
  


Current Time: Sun Jun 15 01:25:30 EDT 2025

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

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

Back to the top