Git Product home page Git Product logo

Comments (11)

nojaf avatar nojaf commented on May 24, 2024 2

Many thanks for this!

from fantomas-for-vs.

deviousasti avatar deviousasti commented on May 24, 2024 1

With that PR in, I've added support for .editorconfig with bf6eca9f.

from fantomas-for-vs.

deviousasti avatar deviousasti commented on May 24, 2024

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.

nojaf avatar nojaf commented on May 24, 2024

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.

deviousasti avatar deviousasti commented on May 24, 2024

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.

nojaf avatar nojaf commented on May 24, 2024

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.

deviousasti avatar deviousasti commented on May 24, 2024

I did think of this, but it's a false positive when the editor config matches with the defaults.

from fantomas-for-vs.

nojaf avatar nojaf commented on May 24, 2024

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.

deviousasti avatar deviousasti commented on May 24, 2024

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.

nojaf avatar nojaf commented on May 24, 2024

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.

deviousasti avatar deviousasti commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.