Configuration for formatter #987
Comments
The formatter already reads the (You can also read other config files, so we could use an IDE-specific config… but I really don’t see the point in that.) |
Now, the formatter will use configuration from the .ceylon/config file, just like the command-line formatter.
Now, the formatter will use configuration from the .ceylon/config file, just like the command-line formatter.
Now, the formatter will use configuration from the .ceylon/config file, just like the command-line formatter.
You can also put global configuration into the user Ceylon config file - IIRC it cascades just like Git config: options from the project config file override options from the user config file. In fact, AFAIK, you can put a config file on any directory level, so you could get a workspace-specific config in $workspace/.ceylon/config. But I haven't tested that. (Sent from phone, sorry for the lack of formatting.) |
However you do it, I would like Eclipse to store its formatter prefs in some place where the commandline formatter can see them. |
Well you could, but that would only work when your projects are subfolders (at some level) inside the workspace. If that's not the case the command line version would not know about it. I do think that if both Eclipse and the CLI version need to use the same settings that the only real option we have is using our own config file. And in that case I also think that it should be the same format we already use for the configuration. But my suggestion would be to just use a separate file within the Ceylon folder, let's say I'm not certain how to deal with the workspace settings though. I think the only solution would be to always copy the workspace settings to the format config file and apply the project settings on top of them. The problem is to figure out afterwards which settings were made as part of the project and which were part of the workspace. None of the things I can come up with will win any beauty prizes. We could either store them as a separate Eclipse specific section in the file, a section that gets ignored by the CLI tool. Or we could store them in a separate file |
Damn, you’re right, that’s not necessarily the case.
Why not just a |
Since all the infrastructure for the config file is already implemented, I don't see why it shouldn't go in there. |
Well, for configuration syncing there's a conflict of locations where it makes sense to sync:
Let's not pretend that the Ceylon CLI can read config from a workspace, this is not a notion that exists on the File System. For project-specific settings there's no question. For the rest, what we can do is either:
|
Honestly this sounds fine to me. |
First of all, there's almost no work involved, the code doesn't care from which file the information comes. So why not in that file? Because to me the The formatting on the other hand is completely personal, to be honest I do not want your blooming formatting settings in my project! So a team of people might just say: "please add your format file to your .gitignore, we don't want one person's settings to conflict with somebody else's". If we put them in the normal config file suddenly people can't even share their important setting s anymore. That's why I think it should be in a separate file, at least. |
Fine with me too. We can just call them "user-specific" and forget that they're workspace-specific in JDT :) ----- Ursprüngliche Nachricht ----- Store the workspace settings in the user config with a big fat warning and both can use it, but it's not workspace-specific |
I don't know about user-project specificity. It depends on several things:
IMO if you have a project formatting settings, it should apply to the whole project, and override any user setting for formatting. |
I see how that's correct. There should be one canonical set of formatting standards for the project. The whole point of a formatter is to avoid "format wars". |
Let's just let people decide that for themselves, shall we? |
imo it's far more likely people will just add the whole |
Well, I'm not sure if there are any nasty side effects, but yes it should be documented of course. We already do this btw : http://www.ceylon-lang.org/documentation/1.0/reference/tool/config/ Btw, another good reason IMHO to use separate files is that you can easily copy them around. You could have different "formatting profiles" lying around and the only thing you'd have to do to apply it to another project is to copy it. On top of that in the CLI tool you could easily point to a different one saying "format the code with this particular style". |
Btw, I just made some changes to the Config API that will make using a separate file even simpler. |
I’m inclined to agree with @quintesse. Even though I’ve previously argued that having user-specific formatting settings is evil, his arguments make a lot of sense :) But then I remembered that the formatter also supports “include” configuration with This also allows you to keep different “formatting profiles” – e. g. in And now I’m not sure if it’s better to read from a specific config file by default. @quintesse does the new Config API support something like “look in |
I'd not use includes, they are also notoriously fragile across multiple OSes, you show I too would think more along the lines of having "profiles", stored in Then if you run the formatter without any profile name, and none its otherwise specified, it could look for @lucaswerkmeister right now the API supports only looking into a single file. Although that could possibly be changed. But yes, I think it's a bit crazy :) If we'd go for this idea of profiles we could get rid of this Point is I'm still not sure how I feel about having it in |
Great points. To summarize:
As such,
Do we need to read or store a formatter version in the settings? Formatting options are done once in a while and then almost forgotten. Any changes to default built-in settings in the future will cause annoyance. With a settings version, it will give future versions of the formatter a chance to adapt current settings to new defaults. |
I think the best thing to do is to not leave things open to interpretation and always write all the formatting options to the file. So unlike preferences that are merged, styles would always be complete (which is also how Eclipse works, you don't just set single style options on a project, you either take the workspace settings or you choose a completely different style, even if that style differs by just a single setting). That way if a new formatter is released with new defaults you will still have your old behavior. And any new settings will just get their default value because they would be missing from the style file. |
@akberc are you actively working on this? We plan a release in a month, and it would be nice to have this in. WDYT? |
Apparently, for |
Ah, no, it is actually related to inline annotations – because the preference is updated after creation, when a listener is registered, which then wants to update the preview, which doesn’t exist yet because we’re still initializing. |
Okay, fixed as well. There’s still a small problem – if you check “all” (annotations) and reopen the config, it’s unchecked and the annotations string pref now contains |
Whew, that was a hairy fix, including a runtime subtyping check bug :( but now it works! |
Yes, I was stuck on this last night. Great stuff!! You take the lead and let me know what you want me to add or change. Update the sample code? Unrelated to formatter, but I will add hooks to the new module wizard for author name and version number (variables just to fill in the Style tab that makes room for formatter tab under it.. |
Okay, I think I’m done for now! The only two remaining problems I have:
|
How about we take out the main Style tab (with the author version) and the @lucaswerkmeister , @quintesse What should the nesting structure for project properties?
-- OR --
|
Yeah, that might be better for now.
Java / JDT has four toplevel property “pages”(?), but I don’t see why that would be an advantage… toplevel Ceylon seems more natural to me. |
I think @gavinking might have a stronger opinion on that than I do. Personally I'd probably copy Java's example, but I have no strong feelings about it. |
I took the liberty of calling the top-level 'Ceylon Configuration' for that is literally what the four tabs do - update the Ceylon configuration for the project. Please change text in plugin.xml if needed. I think we are ready to merge with master. |
Bug: does not switch config value for profile back to default. Looking into it. But go ahead with merge. |
@akberc I think I’ve found the bug: public boolean performApply() {
try {
if (fFormatterProfileManager.getSelected() != null
&& fFormatterProfileManager.getSelected().getName() != "default"
&& fFormatterProfileManager.getSelected().getName() != "unnamed") {
CeylonStyle.writeProfileToFile(fFormatterProfileManager
.getSelected(), project.getLocation().toFile());
CeylonStyle.setFormatterProfile(project,
fFormatterProfileManager.getSelected().getName());
} You still need to set the formatter profile even if it’s the default. (But it’s probably correct that you don’t have to write it.) |
Yes, please get rid of it. We don't want a page with one text field on it. |
@lucaswerkmeister Bug fixed - and made the values constants for safety |
Works great now, thanks a lot @akberc! |
Support for creating, switching between and editing formatting profiles. Completely compatible with the command-line formatting tool. Done mostly by @akberc with a few minor fixes by @lucaswerkmeister. Implements and closes #987. CC #385 which is now completely done.
Done!! Thanks a lot @akberc for all your work here! |
No worries. Thank you for testing, input and making the options variable! Sorry for being a bit late on this. On another note, Github Windows client seem to have clobbered the I will delete branch |
Alright, so thanks so much, @akberc and @lucaswerkmeister, this is overall actually really well done. I've cleaned the presentation of some of the options a little, but those were really very small changes. Great work! |
Support for creating, switching between and editing formatting profiles. Completely compatible with the command-line formatting tool. Done mostly by @akberc with a few minor fixes by @lucaswerkmeister. Implements and closes #987. CC #385 which is now completely done.
We need a way to configure the formatter.
So a properties file type thing would be a great start, though I suppose we will eventually want a GUI for it.
The text was updated successfully, but these errors were encountered: