Elders/VSE-FormatDocumentOnSave

Per solution settings

jnyrup opened this issue · 12 comments

When I'm working on my own projects, I love this extensions to ensure documents are properly formatted.

However when e.g. contributing to various OSS projects, I turn this extension off, to keep my commits minimal.

So it would be very useful if I could override it from a file.
Similar to settings like .tfignore and '.editorconfig'.

Use cases I can think of:

  • Disabled in general unless overriden in file.
  • Enabled in general unless overriden in file,

This is interesting. How do you think it best fits for your environment?

While it could be a setting in FormatDocumentOnSave extension, the new best practice seems to put the setting into a file that be checked in source control.
This gives a consistent experience across a team using FormatDocumentOnSave.

The logic for finding settings overrides could be to search for a file named .formatconfig which should be located next to the opened .sln file.

In .formatconfig you could then override:

  • Allowed extensions
  • Command
  • Denied extensions

Then I could disallow all extensions per default in the extension and create .formatconfig in my personal projects.

A more fine grained approach to resolve settings would be to adapt the EditorConfig approach

Where are these files stored?
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.

This would be beneficial if you have a solution of multiple projects, where you are interested in only overriding the settings for a single project.

I like the editorconfig path. Do you have an idea for the setting name? I am not aware of the structure spec of editor config.

You mean the name of settings in the settings file?

.formatConfig:

root = true

allowed_extensions = ".*"
command = ""
denied_extensions = ".js, .xml"

Yeah, exactly. Do you have suggestions?

The code snippet above would be my suggestion to the layout

@jnyrup I released a new version and I updated the readme. Please take a look and ping back with feedback. Thank you

@mynkow This is awesome!
I've just poked around with it, and it works quite well.

.formatconfig

root = true

[*.*]
allowed_extensions = .*
denied_extensions = .js .cs

/MyMainSolution.sln
/.formatconfig
/SomeDir/AnotherSolution.sln

Both MyMainSolution and AnotherSolution respects the .formatconfig


Are settings inherited from parent .formatconfig?

/MySolution.sln
/.formatconfig

root = true #<--
allowed_extensions = .*
denied_extensions = .cs .js

/SomeDir/AnotherSolution.sln
/SomeDir/.formatconfig

root = false #<--
denied_extensions = .xml

I would expect that MySolution formats all files except .cs and .js.
That AnotherSolution inherits allowed_extensions = .* from its parent file as it is marked with root = false.

I'm not sure how I would do with overriding allowed_extensions and denied_extensions as they are sets and not a single on/off option.

I think the most consistent way would be to have three operators

denied_extensions = .cs # <-- completely override settings from parent file(s)
denied_extensions -= .cs # <-- settings from parent file(s) except .cs
denied_extensions += .cs # <-- settings from parent file(s) and additionally .cs

I'm not sure if this is a regression, but when in a solution * without* a .formatconfig
and the extension settings is set as follows
allowed_extensions = [blank]
denied_extensions = .*

.cs-files are still formatted on save.
If I set
denied_extensions = .cs
it stops formatting .cs-files

Unfortunately I did not have time to implement the inheritance part. Do you think you could help with that?

Regarding the possible regression. By default if you do not have .formatconfig the configurations in visual studio will be used. Could you please check if you have the same behavior ?

I'll create a separate issue for the inheritance part.
I would like to contribute, but I can't promise it will be anytime soon.

Regarding the other issue.
My settings in VS are as follows:
image

When I then press ctrl + S, the document is formatted.

When I change the extension settings to
image

ctrl + S no longer formats the document.

Thanks a lot jnyrup!, your last comment get me out of the hole. I was crazy trying to remove the extension cause I was sending unwanted changes to the server.

I am closing this. If I an missing something please let me know