Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Max line length Formatting
Max line length Formatting [message #1746360] Thu, 27 October 2016 09:24 Go to next message
Eclipse UserFriend
How do i configure the formatter to use custom maximum line length?

The default seems to be stored in FormatterPreferenceKeys as 120. I tried to override the IPreferenceValuesProvider implementation and return the default value as 40. But this has no effect on line length when the formatting is called.
Re: Max line length Formatting [message #1746363 is a reply to message #1746360] Thu, 27 October 2016 09:42 Go to previous messageGo to next message
Eclipse UserFriend
How exactly does your binding and impl look like ?
Re: Max line length Formatting [message #1746412 is a reply to message #1746363] Fri, 28 October 2016 07:36 Go to previous messageGo to next message
Eclipse UserFriend
The current exploratory implementation:

in MyDSLRuntimeModile

public void configureFormatterPreferences(com.google.inject.Binder binder) {
			binder.bind(org.eclipse.xtext.preferences.IPreferenceValuesProvider.class).annotatedWith(org.eclipse.xtext.formatting2.FormatterPreferences.class).to(nl.esi.poosl.xtext.formatting2.PooslFormatterPreferenceProvider.class);
		}


public class PooslFormatterPreferenceProvider implements IPreferenceValuesProvider {

	@Inject
	private IWhitespaceInformationProvider whitespaceInfo;

	@Inject
	private IPreferenceValuesProvider valuesProvider;

	@Override
	public IPreferenceValues getPreferenceValues(final Resource resource) {
		final IPreferenceValues preferenceValues = internalGetRawPreferenceValues(resource);
		final String indent = whitespaceInfo.getIndentationInformation(resource.getURI()).getIndentString();
		final String lineSep = whitespaceInfo.getLineSeparatorInformation(resource.getURI()).getLineSeparator();
		
		
		return new IPreferenceValues() {

			@Override
			public String getPreference(PreferenceKey key) {
				if (key == FormatterPreferenceKeys.indentation) {
					return indent;
				}
				if (key == FormatterPreferenceKeys.lineSeparator) {
					return lineSep;
				}				
				if (key == FormatterPreferenceKeys.maxLineWidth) {
					return "40";
				}
				return preferenceValues.getPreference(key);
			}

		};
	}

	protected IPreferenceValues internalGetRawPreferenceValues(final Resource resource) {
		return valuesProvider.getPreferenceValues(resource);
	}

}


The PooslFormatterPreferenceProvider is used by the AbstractFormatter2 but it doenst seem to have any effect.

Re: Max line length Formatting [message #1746413 is a reply to message #1746412] Fri, 28 October 2016 07:55 Go to previous messageGo to next message
Eclipse UserFriend
hmmm can you please file a ticket for that
Re: Max line length Formatting [message #1746414 is a reply to message #1746412] Fri, 28 October 2016 08:01 Go to previous messageGo to next message
Eclipse UserFriend
Looking through the code the maxline length should be handled in FormattableDocument. createReplacements(ITextReplacerContext).

The ITextReplacerContext always returns null on canAutowrap() which seems to prevent xtext from applying the max line length.

Does this mean every Procedure1<IHiddenRegionFormatter> should also apply setautowrap


	final Procedure1<IHiddenRegionFormatter> oneSpace = new Procedure1<IHiddenRegionFormatter>() {
		@Override
		public void apply(final IHiddenRegionFormatter it) {			
			it.oneSpace();
			it.autowrap();
		}
	};


edit: After setting autowrap xtext seems to apply the max line length.

[Updated on: Fri, 28 October 2016 08:05] by Moderator

Re: Max line length Formatting [message #1746416 is a reply to message #1746414] Fri, 28 October 2016 08:32 Go to previous messageGo to next message
Eclipse UserFriend
hmmm sounds more like a feature to me @Moritz what do you think?
Re: Max line length Formatting [message #1746498 is a reply to message #1746416] Mon, 31 October 2016 04:51 Go to previous message
Eclipse UserFriend
Hi Koen,

Quote:
Does this mean every Procedure1<IHiddenRegionFormatter> should also apply setautowrap


yes, exactly, it should.

The formatter only applies autowrap to HiddenRegions that are explicitly marked as such. Otherwise there are too many languages where autowrap would turn a document into a big mess.
If you need to have it enabled for all regions, you may get the first HiddenRegion of the document via

org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess.regionForRootEObject().getPreviousHiddenRegion()


and then iterate from HiddenRegion to HiddenRegion via
getNextHiddenRegion()


hth,
Moritz
Previous Topic:dynamic template proposals in xtext revisited
Next Topic:Error when running MWE2 file
Goto Forum:
  


Current Time: Tue May 13 11:45:48 EDT 2025

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

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

Back to the top