Closed DaveNay closed 7 months ago
Moving the setting into .csharpierrc would force it on all users. At work I have a few team members that prefer to not have it enabled. Ideally this could be done in a way that was opt in.
There is nothing that prevents someone from committing .idea/.idea.[Project]/.idea/CSharpierPlugin.xml
or .vs/[Project]/v17/csharpier.json
to source control if they wish to share the settings within VS or Rider, although it isn't super obvious which files need to be committed.
Rider has the concept of sln.DotSettings
vs sln.DotSettings.user
for the problem, but it seems specific to resharper. A rider plugin can contain a ReSharper component, so it may be possible to make that work - https://www.jetbrains.com/help/resharper/sdk/AddSettingsToOptions.html
And settings in VS is kind of a mess. There didn't seem to be any standard or built in way to implement the persistance for them.
VSCode does allow any setting to be tied to the workspace, which shares it across the team - https://code.visualstudio.com/docs/getstarted/settings#_workspace-settings - and the Format on Save setting is a generic one, not specific to csharpier.
Moving the setting into .csharpierrc would force it on all users.
Exactly :smile:
What if the settings in .csharpierrc
and csharpier.json
were hierarchical? If the ReformatOnSave
setting is missing or null in .csharpierrc
, then the value from csharpier.json
is applied. If the setting is not null in .csharpierrc
, then it takes precedence. This would also preserve backwards compatibility for everyone that is using the setting from csharpier.json
.
The trickiest part would be having the VS UI reflect the correct value depending on what is defined and what isn't.
edit: Hmmmm....I might have that relationship backwards. csharpier.json
might need to take priority to accommodate your scenario of "some team members that prefer to not have it enabled."
We have them same need, our developers are jumping between repos with different formatting solutions, so a solution that allows format on save to be turned on at a repo/directory level is ideal.
@belav would you be ok with the solution @DaveNay suggested where a default value can be pulled from the .csharpierrc/.editorconfig and can be overridden using the global and/or solution VS settings?
I am keen to create a PR for this, but it would mean that the config loading code would need to be shared between cli and visualstudio extension. Also since VSCode already has a great way to do this with workspaces as you mentioned, the options would likely be named something like VsFormatOnSaveDefault.
I don't think it makes sense to add a VS specific setting to the CSharpier configuration files. It adds confusion to the documentation and the UI for the current settings in VS.
As I mentioned above, you can add .vs/[Project]/v17/csharpier.json
if you want all team members to have format on save turned on.
The only thing I'd like to do is find a solution that allows the rider setting to be defined system wide.
Currently, it appears that the VS plugin saves the ReformatOnSave to the csharpier.json file in the .vs directory. Since this directory is typically excluded from source control, this means that all users must enable ReformatOnSave in their local environment. Additionally, if the .vs directory is deleted (e.g. running git clean on the repo) then the ReformatOnSave setting is lost.
Ideally, I think it would be nice if this setting were part of the .csharpierrc file and could be tracked by source control, thus enabling ReformatOnSave for all users reliably. I have not explored the VS Code plugin, but it should behave in the same manner as I describe.