editorconfig-vscode: Editorconfig should not apply styles to files located outside the root directory
I’ve found that editorconfig changes to tabs as specified in the project’s .editorconfig when I edit my settings.json file which is located away from the root open folder in ~/.config. It should instead not apply the editorconfig settings in this case.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (4 by maintainers)
Commits related to this issue
- take detectIndentation into account - fixes #52 — committed to editorconfig/editorconfig-vscode by SamVerschueren 8 years ago
- take detectIndentation into account - fixes #52 — committed to editorconfig/editorconfig-vscode by SamVerschueren 8 years ago
- Merge pull request #70 from editorconfig/iss52 take detectIndentation into account - fixes #52 — committed to editorconfig/editorconfig-vscode by jedmao 8 years ago
Verified fixed 👍 thanks guys
@Tyriar You are right!
@jedmao It looks like the code wasn’t compiled before releasing a new version.
Source:
DocumentWatcher.tsCode in Extension:
DocumentWatcher.jsTL;DR: I have a solution, will create a PR.
Sorry for this long explanation.
Alright, I started debugging this. Please note that this is on my computer with my setup. I don’t have any
.editorconfigfiles defined in home directories or whatsoever. This is important asEditorConfigwill automatically traverse all the way up to the root untill it finds a.editorconfigfile.Let’s get started!
When I open the global settings, the
DocumentWatcher._onDidOpenTextDocumentkicks in. Because the config was not yet loaded, it will askEditorConfigto parse the path. This is expected as stated before, it could be possible that you have a.editorconfigin your home directory. In my case, that promises just returns an empty object as no.editorconfigfile was found.Then it calls the applyEditorConfigToTextEditor method. The settings for the document are empty, e.g.
{}.sidetrack
The main question we have to ask first, is that behaviour correct? I already opened an issue on the editorconfig-core-js.
The thing is, if
editorconfig.parse()would’ve returnedundefined, it would exit early and we’re all happy.This made me wonder. We already had Paul Irish creating issue #44 for this behaviour and I proposed fix #38 which was rejected in favour of #43. The thing is that #38 would’ve fixed this issue while #43 only made sure the message didn’t get displayed.
So let’s continue where I left. After that, the Utils.fromEditorConfig are called and create an options object based on the
.editorconfigfile (which is{}) and the editor settings.And this is what causes the issue. It will read your workspace settings BUT it doesn’t take the
editor.detectIndentationinto account resulting in the hard fixed settings defined insettings.json.Let me create a PR that solves this issue.
https://github.com/Microsoft/vscode/blob/master/.editorconfig
Are you sure this is because of the EditorConfig plugin? I scanned the code real quick and it shouldn’t do that, so if it is the case, it’s definitely a bug.
I recorded a screen capture and tried editing and saving it. As you can see, I have
trim_trailing_whitespaceset totrueandinsert_final_newlineas well. Neither both of those transformations are being applied.I know it might be a stupid question, but I have to ask 😃. You aren’t editing your workspace defined settings, right? Probably not because key bindings are always global, but you never know.
Care to screen capture the behaviour? Also, what OS are you using?