Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read .editorconfig properties in other .NET languages' analyzers and formatters? #41225

Closed
xperiandri opened this issue Jan 26, 2020 · 7 comments

Comments

@xperiandri
Copy link

xperiandri commented Jan 26, 2020

I discuss with @nojaf usage of .edtiorconfig in F# formatter fsprojects/fantomas#650
Regarding that I want to ask:

  1. How to read common .NET Coding Conventions and Naming Conventions from .editorconfig using existing Roslyn code regardless Visual Studio instance?
  2. How to read common .NET Coding Conventions and Naming Conventions from .editorconfig using Roslyn classes within Visual Studio?
  3. How to reuse existing Roslyn code to read custom F# specific conventions?
  4. How to provide custom F# specific conventions to consumers in Visual Studio (i. e. F# language formatter)?
@CyrusNajmabadi
Copy link
Member

How to read common .NET Coding Conventions and Naming Conventions from .editorconfig using existing Roslyn code regardless Visual Studio instance?

This isn't exposed publicly. But you can see our code for that here: https://github.com/dotnet/roslyn/blob/master/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser.cs

How to read common .NET Coding Conventions and Naming Conventions from .editorconfig using Roslyn classes within Visual Studio?

See above.

How to reuse existing Roslyn code to read custom F# specific conventions

I don't believe you would be able to.

How to provide custom F# specific conventions to consumers in Visual Studio (i. e. F# language formatter)?

That question would have to go to the F# team: https://github.com/dotnet/fsharp/

@xperiandri
Copy link
Author

@CyrusNajmabadi, thank you very much!
Could you also point to the place where you discover .editorconfig files and calculate effective having several files?

@jmarolf
Copy link
Contributor

jmarolf commented Jan 26, 2020

@xperiandri here is where we use reflection to get the editorconfig options from the workspace. I don't know what exactly you need. Do you want something to help find and parse the editorconfig? do you want to just pull whatever the naming styles are?

@xperiandri
Copy link
Author

@nojaf knows better.
I think he needs:

  1. Code that recursively discovers .editorconfigs until the file marked as the root
  2. Parses all discovered .editorconfigs and returns a filterable dictionary of settings for a particular directory. This includes filtering out options enabled for files other than .fs, fsx and fsi

@nojaf
Copy link

nojaf commented Jan 27, 2020

Hello, I'm a bit confused in regards to this issue.
Fantomas does not use Rosyln in any way, shape or form.

We already have code in Fantomas that does 1.
As for 2 we also have some code that uses reflection to construct our configuration object, so main thing left there is doing some parsing of the .editorconfig file itself.

@jmarolf
Copy link
Contributor

jmarolf commented Jan 27, 2020

here is the parser for editorconfig that the compiler uses. Its a public type so you can use that if its helpful or re-use any of the logic/tests. nuget package that contains that type is here

@nojaf
Copy link

nojaf commented Jan 27, 2020

Thanks for the pointer @jmarolf , I think this issue can be closed.

@jmarolf jmarolf closed this as completed Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants