You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use .editorconfig to define Fantomas settings #650
.editorconfig is a common solution to define all code related rules including formatting and code analysis.
It would be the right option for Fantomas to read settings from it.
Reacted by Andreas Vilinski, Eugene Auduchinok, Andrii Chebukin, Thecentury, Sean G. Wright and Friedrich von Never
Hey @xperiandri , this issue came just in time ;)
I'm about to release to 3.2 stable and that would mark fantomas-config.json as public api so glad we can discuss other options before that.
I'm a bit less familiar with .editorconfig so my main question would be: how does this work with custom settings? Can we just write anything we want in the file and parse it as we want?
How would our current default look like in .editorconfig?
@madskristensen could you explain what is the source of Editor Config Language autocomplete? How can Fantomas provide F# specific settings to a service?
fsharp_space_around_coma = after #"SpaceAfterComma" :true
fsharp_space_around_colon = none #"SpaceBeforeColon" :false
fsharp_space_around_semicolon = after #"SpaceAfterSemicolon" :true
And why not use boolean for
fsharp_space_around_coma = after #"SpaceAfterComma" :true
fsharp_space_around_semicolon = after #"SpaceAfterSemicolon" :true
fsharp_space_around_delimiter = before_and_after #"SpaceAroundDelimiter" :true
To be clear, the only thing I'm considering here is swapping the JSON config file to .editorconfig format.
Different names for the settings might eventually be being discussed but for now, I would like to keep the same names in the CLI tool as in the configuration file. Changing names is something that I would only do in the next major version.
Why are you changing the names of settings?
And why not use boolean for
Because I would prefer having option to set spaces not only after colons and semicolons but before them too.
Different names for the settings might eventually be being discussed but for now, I would like to keep the same names in the CLI tool as in the configuration file. Changing names is something that I would only do in the next major version.
I'm OK with that.
Anyway these features are not implemented as far as I know.
This is where you specify the properties in the .json file and you also have to add a few things in some of the other files since you're introducing a new language. It should be simple enough when you see the code in those files
Hello @xperiandri , I've refactored the code a bit so that the only thing remaining here is the implementation of parsing the file to settings.
I won't pursuit this myself for the time being, there are other priorities and this can easily be picked up by someone else it doesn't really involve any knowledge about Fantomas.
To whoever that wants to pick this up, keep the following rules in mind:
Don't introduce any new NuGet or other dependencies. Fantomas should only have the FSharp.Compiler.Service package as dependency.
Each Fantomas specific setting should snake-cased and prefixed with fsharp-.
Example: SpaceAfterComma becomes fsharp_space_after_comma. These things should be transformed to back to the Pascalcase style when returning them as key of the return value of parseOptionsFromEditorConfig.
I thought about finishing the feature as prepared by @nojaf. However I found out that the code is not quite ready yet. The editorconfig format supports two features, that fantomas-config does not:
root property. It's a special property that, when set to true, prevents searching for more .editorconfig files in parent directories.
Different properties for different files. While Fantomas applies the same configuration to all F# files, editorconfig allows to set a global configuration for all files, and also specific configurations based on file wildcards (called globs). For example I may create this .editorconfig file:
[*]
indent_size = 4
[*.fs]
indent_size = 2
This sets indentation for .fs files to 2, but for other files (including .fsx and .fsi) the indentation is 4.
Now how to implement that? The root property should be easy; it may be covered by tweaking the CodeFormatterImpl.readConfiguration function. On the other hand, the different file configurations are going to require some design changes.
I see three possible solutions:
Fully implement the file configurations. This would be a breaking change to the Fantomas API. The configuration type would change from FormatConfig to something like Map<Glob, FormatConfig>.
Assume that there is only one configuration for F# in a .editorconfig file and merge any * and *.fs* sections into one. So for the example above, the resulting FormatConfig would have just IndentSpaceNum = 2. This would
Implement solution 2 now and solution 1 with in the next major version. Speaking of phased changes, we could also now read just the common properties like the tab size, and add custom F#-specific properties later.
What do you think?
Ad custom settings in editorconfig. Currently the editorconfig format defines only a limited set of universal properties (like tab settings, charset, newlines etc.). The file can contain any custom properties. There is a prefix-based convention for naming the file format specific properties. E.g. Visual Studio uses properties with dotnet_, csharp_, visual_basic_ prefixes to configure its code analyzers.
This means we are free to come up with any fsharp_ properties, preferably synced with other related F# projects (like the mentioned FSharpLint).
There is a discussion (see editorconfig/editorconfig#415) in the editorconfig project itself regarding its future extensions and custom namespaces. However there is no definite conclusion yet.
Hello @josefblaha, thanks for this thorough remark.
We are currently working on the next major version of Fantomas so I feel like option 1 should be on the table.
As for the custom settings, if we can use fsharp_whatever_we_want_setting, we might only need to align with FSharpLint and write out how we can move forward. As mentioned, we are working on the next major version, so we can rename some settings if necessary.
Lastly, thinking out loud at this point, perhaps we should consider of having only the .editorconfig solution.
The initial idea of the JSON schema was nice but ever since I implemented the copy your settings from the tool button, I feel like that is the way to go to configure Fantomas. The copy button would make up for the lack of intellisense in the editor I think.
I've talked with @jindraivanek about this behind the scenes and we would move forward on this.
I'm already working on this so expect it to drop in the weeks to come.
The idea would be to replace the JSON format with editor config.
Once I have something, I'll reach out to FSharpLint to see if we can consolidate some settings.
Next attempt I had in mind was to use ILRepack and move the C# project to this repository and merge it into the Fantomas dll.
This works but well, pro's and cons there as well.
How is your attempt going @josefblaha? Biggest challenge seems the glob thing. Any fork I can take a look at maybe?
So far I've been playing with editorconfig-core-net. It provides not only parsing the .editorconfig itself, but resolving the right settings as well. There is EditorConfigParser.Parse (misleading name IMHO) method which, given source file name, returns the list of settings applicable to that file. With this, integration to Fantomas should be easy, as all the directory traversing and glob matching can be offloaded to the library.... if only we're able to merge the library in.
Why do you think it's necessary to move the library to this repository? Wouldn't referencing it as a regular NuGet package and merging it to Fantomas DLL as part of the build process be enough?
What are the cons of merging the library to Fantomas DLL? If there is a requirement for a single DLL output, it seems like a good solution.
Yes, I experimented there a bit as well. Using that method it is rather easy indeed.
Reason for going with a fork was to have an netstandard2.0 only thing. I didn't like the msbuild warnings I guess. Maybe I missed something in Paket configuration there.
What are the cons of merging the library to Fantomas DLL?
Never really used any ilmerge like thing, so has that black alchemy vibe to it.
I'm just a bit worried if that goes wrong in a couple of months, I have no idea what to do about it.
What about custom settings? I feel like the list of 'agreed' settings is very limited so to support Fantomas we would need special sharp specific settings. Are we allowed to invent these settings? What prefix do we use here? How could we best align with other F# tools like F# lint?
Custom settings are totally fine! Namespacing is an active discussion but given the prevalence of existing prefixes I reckon reserved prefixes will end up in the spec at some point. fsharp_ makes the most sense to me too here. It'd be awesome if fslint picks these up as well.
Any idea how editorconfig and language server work together? Might be less relevant here but just out of curiosity ;)
Activity
nojaf commentedon Jan 26, 2020
Hey @xperiandri , this issue came just in time ;)
I'm about to release to 3.2 stable and that would mark
fantomas-config.jsonas public api so glad we can discuss other options before that.I'm a bit less familiar with .editorconfig so my main question would be: how does this work with custom settings? Can we just write anything we want in the file and parse it as we want?
How would our current default look like in .editorconfig?
{ "IndentSpaceNum":4, "PageWidth":120, "SemicolonAtEndOfLine":false, "SpaceBeforeArgument":true , "SpaceBeforeColon":false, "SpaceAfterComma":true , "SpaceAfterSemicolon":true , "IndentOnTryWith":false, "ReorderOpenDeclaration":false, "SpaceAroundDelimiter":true , "KeepNewlineAfter":false, "MaxIfThenElseShortWidth":40, "StrictMode":false }One advantage of using a JSON file is that we have listed a JSON schema. Would there be something similar for editorconfig?
xperiandri commentedon Jan 26, 2020
@madskristensen could you explain what is the source of Editor Config Language autocomplete? How can Fantomas provide F# specific settings to a service?
xperiandri commentedon Jan 26, 2020
nojaf commentedon Jan 26, 2020
Why are you changing the names of settings?
And why not use boolean for
To be clear, the only thing I'm considering here is swapping the JSON config file to .editorconfig format.
Different names for the settings might eventually be being discussed but for now, I would like to keep the same names in the CLI tool as in the configuration file. Changing names is something that I would only do in the next major version.
xperiandri commentedon Jan 26, 2020
@nojaf, could you show me an excerpt of the code, that matches your settings that I have changed?
Or show them on my excerpt
Or any from here https://github.com/SfSync/Bayeux/tree/master/src/Bayeux.Client
These are how I prefer to format my code.
xperiandri commentedon Jan 26, 2020
Because I would prefer having option to set spaces not only after colons and semicolons but before them too.
I'm OK with that.
Anyway these features are not implemented as far as I know.
nojaf commentedon Jan 26, 2020
Please create another issue for these kinds of requests 😉, otherwise, this issue is getting a bit derailed.
Check out the current options at our documentation.
So to get back on track, I will see if I can come up with a PR to get the settings from an .editorconfig file instead of our JSON format.
madskristensen commentedon Jan 27, 2020
@xperiandri See these files: https://github.com/madskristensen/EditorConfigLanguage/tree/master/src/Schema
This is where you specify the properties in the .json file and you also have to add a few things in some of the other files since you're introducing a new language. It should be simple enough when you see the code in those files
nojaf commentedon Feb 3, 2020
Hello @xperiandri , I've refactored the code a bit so that the only thing remaining here is the implementation of parsing the file to settings.
I won't pursuit this myself for the time being, there are other priorities and this can easily be picked up by someone else it doesn't really involve any knowledge about Fantomas.
To whoever that wants to pick this up, keep the following rules in mind:
fsharp-.Example:
SpaceAfterCommabecomesfsharp_space_after_comma. These things should be transformed to back to the Pascalcase style when returning them as key of the return value ofparseOptionsFromEditorConfig.xperiandri commentedon Feb 3, 2020
Why don't got want to reference Roslyn package that already has that logic?
nojaf commentedon Feb 3, 2020
nojaf commentedon Feb 3, 2020
Fantomas is being used by Rider, FSAutocomplete , FSAst and maybe even other projects.
I don't want to introduce an additional dependency for the consumers of Fantomas.
xperiandri commentedon Feb 3, 2020
I don't see any benefit copying already implemented code even as source especially if it is from official MS package used by all IDEs
Mpdreamz commentedon Jun 5, 2020
There is also: https://github.com/editorconfig/editorconfig-core-net which I maintain and is itself dependency free. Rider already uses it as well.
1 remaining item
josefblaha commentedon Jun 24, 2020
I thought about finishing the feature as prepared by @nojaf. However I found out that the code is not quite ready yet. The editorconfig format supports two features, that fantomas-config does not:
rootproperty. It's a special property that, when set to true, prevents searching for more.editorconfigfiles in parent directories..editorconfigfile:This sets indentation for
.fsfiles to 2, but for other files (including.fsxand.fsi) the indentation is 4.Now how to implement that? The
rootproperty should be easy; it may be covered by tweaking theCodeFormatterImpl.readConfigurationfunction. On the other hand, the different file configurations are going to require some design changes.I see three possible solutions:
FormatConfigto something likeMap<Glob, FormatConfig>..editorconfigfile and merge any*and*.fs*sections into one. So for the example above, the resultingFormatConfigwould have justIndentSpaceNum = 2. This wouldWhat do you think?
Ad custom settings in editorconfig. Currently the editorconfig format defines only a limited set of universal properties (like tab settings, charset, newlines etc.). The file can contain any custom properties. There is a prefix-based convention for naming the file format specific properties. E.g. Visual Studio uses properties with
dotnet_,csharp_,visual_basic_prefixes to configure its code analyzers.This means we are free to come up with any
fsharp_properties, preferably synced with other related F# projects (like the mentioned FSharpLint).There is a discussion (see editorconfig/editorconfig#415) in the editorconfig project itself regarding its future extensions and custom namespaces. However there is no definite conclusion yet.
nojaf commentedon Jun 25, 2020
Hello @josefblaha, thanks for this thorough remark.
We are currently working on the next major version of Fantomas so I feel like option 1 should be on the table.
As for the custom settings, if we can use
fsharp_whatever_we_want_setting, we might only need to align with FSharpLint and write out how we can move forward. As mentioned, we are working on the next major version, so we can rename some settings if necessary.As @Mpdreamz mentioned https://github.com/editorconfig/editorconfig-core-net also seems interesting. Perhaps we can combine this with some sort of assembly weaving. So from a Nuget point of view, we still don't have the extra dependency.
Lastly, thinking out loud at this point, perhaps we should consider of having only the .editorconfig solution.
The initial idea of the JSON schema was nice but ever since I implemented the copy your settings from the tool button, I feel like that is the way to go to configure Fantomas. The copy button would make up for the lack of intellisense in the editor I think.
baronfel commentedon Jun 30, 2020
I would definitely be in favor of standardizing on .editorconfig, personally.
nojaf commentedon Jun 30, 2020
I've talked with @jindraivanek about this behind the scenes and we would move forward on this.
I'm already working on this so expect it to drop in the weeks to come.
The idea would be to replace the JSON format with editor config.
Once I have something, I'll reach out to FSharpLint to see if we can consolidate some settings.
josefblaha commentedon Jul 1, 2020
Oh :-/ Have you made much progress yet? I'm working on it too. I thought this would be a good starter issue for me.
nojaf commentedon Jul 1, 2020
Hey, I've trying to port https://github.com/editorconfig/editorconfig-core-net to F#. The further I get there, the more obvious it becomes that this is a bad idea so I'm abandoning that train of thought.
Next attempt I had in mind was to use ILRepack and move the C# project to this repository and merge it into the Fantomas dll.
This works but well, pro's and cons there as well.
How is your attempt going @josefblaha? Biggest challenge seems the glob thing. Any fork I can take a look at maybe?
josefblaha commentedon Jul 1, 2020
So far I've been playing with editorconfig-core-net. It provides not only parsing the
.editorconfigitself, but resolving the right settings as well. There isEditorConfigParser.Parse(misleading name IMHO) method which, given source file name, returns the list of settings applicable to that file. With this, integration to Fantomas should be easy, as all the directory traversing and glob matching can be offloaded to the library.... if only we're able to merge the library in.Why do you think it's necessary to move the library to this repository? Wouldn't referencing it as a regular NuGet package and merging it to Fantomas DLL as part of the build process be enough?
What are the cons of merging the library to Fantomas DLL? If there is a requirement for a single DLL output, it seems like a good solution.
nojaf commentedon Jul 1, 2020
Yes, I experimented there a bit as well. Using that method it is rather easy indeed.
Reason for going with a fork was to have an netstandard2.0 only thing. I didn't like the msbuild warnings I guess. Maybe I missed something in Paket configuration there.
Never really used any ilmerge like thing, so has that black alchemy vibe to it.
I'm just a bit worried if that goes wrong in a couple of months, I have no idea what to do about it.
baronfel commentedon Jul 1, 2020
I wouldn't worry too much about ilmerging, paket has been doing it from the beginning with several dependencies and it hasn't been an issue there.
nojaf commentedon Jul 6, 2020
I released a new alpha to try this out: https://www.nuget.org/packages/fantomas-tool/4.0.0-alpha-012
Please give this a spin, it worked for me on fantomas-tools.
For the settings names, see the docs.
Also, I just noticed that the docs still mention
--config, this is not necessary anymore.Mpdreamz commentedon Jul 6, 2020
Custom settings are totally fine! Namespacing is an active discussion but given the prevalence of existing prefixes I reckon reserved prefixes will end up in the spec at some point.
fsharp_makes the most sense to me too here. It'd be awesome if fslint picks these up as well.Some LSP's support it and some don't. I don't think the LSP protocol exposes it explicitly although there is this: https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#workspace_configuration
I'm keen to get y'all of the fork, I will look at getting the compiler errors to go away when building on a non Windows machine.
There is a dotnet tool I help maintain that could be run before IL merge:
https://github.com/nullean/assembly-rewriter
To rewrite the namespaces to
Fantomas.EditorConfig.*.Let me know how I can help further in any way. You should be able to find me on the fsharp slack too.