Changing Formatter2 Indentation Preferences from Tab to Spaces? [message #1821314] |
Mon, 10 February 2020 18:20 |
Brandon Lewis Messages: 268 Registered: May 2012 |
Senior Member |
|
|
This came up at the end of another long thread of mine, so I'm starting a new thread for more clear tracking.
I'm still too stupid to be able to figure out something that seems like it should be simple and seems like someone on planet earth has run into this before. But I've yet to find an example set of code outside of Xtext that has an example.
Trouble:
I have a whitespace language that uses indentation for blocking. I programmatically create an object and save it and the formatter takes over to serialize the object in my DSL.
Trouble is, the formatter ALWAYS uses tabs on indentation. So if the user has their editor settings set to "insert spaces for tabs", my DSL parser starts to die if the user makes any hand edits. The end user can only debug if they are displaying whitespace in their editor, they have no idea why the parser is dying. As the author of the language, this has made me curse out loud on multiple occasions when I can't figure out why I can't get a file to compile.
The user can ask the editor to re-format the file, and THEN AND ONLY THEN, will the formatter honor the user's "insert spaces for tabs" setting. But 1) there's no way to ask a user to remember to do this and 2) it doesn't work when using my tool in command line mode
In my formatter, getting the preference value is easy:
def dispatch void format(ComponentType comp, extension IFormattableDocument document) {
var indentation= preferences.getPreference(FormatterPreferenceKeys.indentation)
// debugger says indentation is equal to "\t"
Setting it is confusing the hell out of me. The API docs say:
"To set a values for one of these keys, use FormatterRequest.setPreferences(ITypedPreferenceValues)."
// How do I do this equivalent pseudo code?
//preferences.setPreference(FormatterPreferenceKeys.indentation, " ")
// Or better
//preferences.setPreferences(FormatterPreferenceKeys.indentation, <whatever the user has set to their editor setting>)
It was previously mentioned to search on IWhitespaceInformationProvider, but I've found even fewer examples of that in the code base and web examples.
I've spent a couple days on this problem. It's strange that it's so elusive. How do people not run into this all the time?
[Updated on: Mon, 10 February 2020 18:22] Report message to a moderator
|
|
|
Re: Changing Formatter2 Indentation Preferences from Tab to Spaces? [message #1821321 is a reply to message #1821314] |
Mon, 10 February 2020 19:01 |
|
sorry. i dont have time to setup and example
org.eclipse.xtext.ui.editor.formatting2.ContentFormatter.initRequest(IXtextDocument, IRegion, XtextResource, FormatterRequest)
this one calls the method. it uses FormatterPreferenceValuesProvider which is usually bound in abstractyourdsluimodule
public void configureFormatterPreferences(Binder binder) {
binder.bind(IPreferenceValuesProvider.class).annotatedWith(FormatterPreferences.class).to(FormatterPreferenceValuesProvider.class);
}
FormatterPreferenceValuesProvider delegates to IWhitespaceInformationProvider which is bound in eclipse to
PreferenceStoreWhitespaceInformationProvider by default.
which again delegates to PreferenceStoreIndentationInformation
which reads spaces for tabs.
with the information you have i have no idea where you stuck
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04047 seconds