Comments (11)
Many thanks for this!
from fantomas-for-vs.
With that PR in, I've added support for .editorconfig
with bf6eca9f.
from fantomas-for-vs.
I've added Fantomas as a submodule and made it build against fantomas/master.
Would still need some kind of fallback if there's no .editorconfig
for the project, so maybe keep the VS settings as is?
Should I wait for it to stabilize before implementing?
From the spec:
When opening a file, EditorConfig plugins look for a file named .editorconfig in the directory of the opened file and in every parent directory. A search for .editorconfig files will stop if the root filepath is reached or an EditorConfig file with root=true is found.
EditorConfig files are read top to bottom and the most recent rules found take precedence. Properties from matching EditorConfig sections are applied in the order they were read, so properties in closer files take precedence.
The config files are supposed to cascade. The API seems to load from a single file.
Will this be handled by the ReadConfiguration
in the future?
from fantomas-for-vs.
The only thing that could still somewhat change is some setting names when it comes to .editorconfig.
The public API should be stable but I understand if you'd like to wait sometime before implementing this.
If you have no editor config files in your project using ReadConfiguration will fallback to the default config.
Internally we use https://github.com/editorconfig/editorconfig-core-net to collect the settings.
When you pass any file there, it will look for editorconfig files (in the same folder and parent folders) until the root file is detected.
Within an editorconfig file you can have certain glob expressions and filter files. (For example only apply settings to *.fsi or !ignoreThisFile.fsx)
That is why you start looking from the point of view of the target file and not from the configuration file.
from fantomas-for-vs.
Thanks. That makes a lot of sense.
It would be nice to know if there were any editor config settings to be found to use the user-profile defaults.
Is something like this acceptable?
let readConfiguration (fsharpFile:string) : FormatConfig option =
let editorConfigSettings: Fantomas.EditorConfig.Core.FileConfiguration = editorConfigParser.Parse(fileName = fsharpFile)
if editorConfigSettings.Properties.Count = 0 then
None
else
Some <| EditorConfig.parseOptionsFromEditorConfig editorConfigSettings
from fantomas-for-vs.
I think you could just check if something changed by comparing to the default settings.
let userSettings = CodeFormatter.ReadConfig("someFile.fs")
let hasChanges = userSettings <> FormatConfig.Default
from fantomas-for-vs.
I did think of this, but it's a false positive when the editor config matches with the defaults.
from fantomas-for-vs.
Ah I see, you would like to detect whether the editorconfig or the UI settings should be used by this check?
Yeah then returning a FormatConfig option makes sense.
Hmm, maybe it could be useful to have this as part of the public API to return the option.
from fantomas-for-vs.
I'm trying to make the experience a familiar one to C# devs, so we can get more converts. 😈
If you don't want a surface change, what about
static member ReadConfiguration : string -> FormatConfig
static member TryReadConfiguration : string -> FormatConfig option
I can submit a PR based on what you decide.
from fantomas-for-vs.
Since Fantomas is still in alpha it ok to have breaking api changes.
I like your suggestion, best of both worlds.
from fantomas-for-vs.
https://twitter.com/jordan_n_marr/status/1285225997911183361
Keeping formatting settings in was worth the effort. :)
I guess it's the first point of discovery.
from fantomas-for-vs.
Related Issues (20)
- Move to fsprojects/fantomas-for-vs? HOT 5
- Microsoft.VisualStudio.Shell.15.0 not found when loading extension HOT 8
- Missing Options: Fantomas Visual Studio 2022 Community Options Menu HOT 3
- Formatting doesn't work with WSL2 hosted files in VS2022 HOT 31
- Fantomas' package name changed from `fantomas-tool` to `fantomas` HOT 3
- Fantomas does not work in Visual Studio 2022 HOT 6
- Reformating on selection messes text following selection HOT 5
- Fantomas scrambled up a huge script file HOT 8
- Inconsistent version numbers
- Settings page looks different from screenshot and is missing many options HOT 2
- Broken "read the documentation" link HOT 2
- Enable or disable "Format on save" per repo
- The extension stopped working after upgrading Visual Studio 2022 to the latest version 17.4 HOT 2
- Unable to install the extension to VS 2022 on ARM64 HOT 2
- Extension does not load when a folder is opened in VS instead of a solution HOT 1
- Fantomas < 5.0 breaks nested lists HOT 16
- fsharp_multiline_bracket_style setting is not applied HOT 9
- Error in format files inside Visual Studio after updating fantomas to 6.0.0-alpha-010 HOT 7
- [Live buffers] Extension does not work with the new live buffers HOT 3
- Error: "Creating the Fantomas Deamon failed" when saving a file or trying to format in VS HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fantomas-for-vs.