code icon indicating copy to clipboard operation
code copied to clipboard

Editorconfig is no longer respected

Open danirabbit opened this issue 3 years ago • 4 comments

What Happened?

This is probably a regression due to #1145

Tab width is assumed to be global for the editor when different document types can have different tab widths (such as vala vs xml)

Steps to Reproduce

  1. Open a project with an .editorconfig file that specifies tab width for a certain file type (like 2 spaces for xml)
  2. Open an xml file and see that the header says 4 spaces
  3. Hit tab in the view and see that you get 4 spaces instead of 2

Expected Behavior

For projects with editorconfig, we should always follow the editorconfig file.

Probably the most user friendly behavior would be to write to the .editorconfig file if a user changes a setting in the UI.

But the simplest solution would be to make any options overruled by .editorconfig insensitive (such as tab width and insert spaces options)

OS Version

7.x (Early Access)

Software Version

Compiled from git

Log Output

No response

Hardware Info

No response

danirabbit avatar Aug 11 '22 18:08 danirabbit

Hmm, yes - the global setting (in Preferences) potentially competes with that in Editorconfig. It is ambiguous what the tab width in the FormatBar setting is supposed to follow and what it means if the user changes it. As a first step at least the EditorConfig should be applied to the document. Do we need to be able to alter the setting with the FormatBar or should it just show what the current setting is? The global setting is set already in the Preferences dialog and the EditorConfig file is edited manually at the moment. I guess the Preferences dialog could be expanded to allow generation of an EditorConfig file but that is outside the scope of this issue.

jeremypw avatar Aug 11 '22 19:08 jeremypw

The global setting should be considered the default for all documents. I would look at it like a fallback .editorconfig for when one isn't present in the project. I agree that in the future perhaps we could change this to be its own tab where it actually is backed by an .editorconfig file and can have per-document-type settings etc. But I would always prefer the .editorconfig in the project over this fallback setting.

The formatbar should indicate what the current document's settings are and allow quickly changing them in the event that they're incorrect. For example say you have a project without an .editorconfig, so we're using the default global setting of 4 spaces, but you're editing an XML file and you want to use 2 spaces while editing this document. The formatbar allows you to override the global setting for the current document while you're editing it.

In the event that you do have an .editorconfig, the formatbar will make that more apparent when you switch between document types that the format is intentionally different. So we should make sure that the formatbar always matches what is actually happening in the document and it should be updated when we switch between documents.

I think in an ideal world the format bar settings are always writable and we save an editorconfig for the project based on how this is changed. But that's obviously a more complicated solution, so I think the simplest way to not cause issues would be to:

  • make the tab width and insert spaces instead of tabs items insensitive when there is an .editorconfig file already present or
  • we could have the document prefer the format bar's setting always and then make sure we update the formatbar to match either .editorconfig or gsettings when we navigate between documents.

danirabbit avatar Aug 11 '22 19:08 danirabbit

Just to clarify, when you say "The formatbar allows you to override the global setting for the current document while you're editing it.", do you mean the setting should change for that particular document or for that particular type of document? As you say, the simple initial solution is to disallow changing the setting when an .editorconfig file is present.

jeremypw avatar Aug 12 '22 09:08 jeremypw

Presumably though, a .editorconfig file could exist but not specify a global or specific tab-width? May need to move EditorConfig plugin code into the main code in order to integrate it fully with the UI.

jeremypw avatar Aug 12 '22 10:08 jeremypw