-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
add automatic tabsize detection #114
base: main
Are you sure you want to change the base?
Conversation
ah hmm so the idea that I had for this was instead to mark the default tab settings in each language file: asottile/babi-grammars#27 (and probably also solve this at the same time: asottile/babi-grammars#26) and then use that when opening files this of course wouldn't handle people breaking convention (google using 2-space python for example) but would provide a decent baseline later when configuration is implemented, an override per language could be done this better solves the "I create an empty file" problem since auto-detection doesn't really work there what are your thoughts on this? |
you mean using hard tabs which are expected to expanded to length two?
year this would help -- maybe my proposed implementation might still be able to act as a fallback for unknown languages in this case?
yes, I agree for an empty file it would still just use the current default of 4 spaces... |
I think it would be something like
ah yeah that's a good point so it would still be useful there |
though hmm, maybe "unknown" should always default to 4-spaces which puts incentive to add language support |
yes I think your language specific approach is definitely the proper way to go and will be right in more cases. The only case where my solution would be helpful with added language support would be opening an existing file with an unknown language -- which is obviously a rare case and defaulting to 4 spaces would probably be right a similiar amount. I don't think I am able to implement the language specific part though since it will include the proper grammar parsing and I have no idea about this. |
I think vs code chooses the indent size per language, but stored external to the grammars -- I haven't found any code for this though my thought was to augment the grammars with our own information 🤷 |
I had a bit of a look into vscode but did not actually find a complete answer. For me it looks like they guess the indentation from the file also without taking the language into account I found this test and the editor default settings as well as a class called Seems like this is a much more complex problem than I initially though. I might take a deeper look into this later and come up with a new approach, but since I am not familiar with this at all atm, it might take quite some time which I unfortunatelly don't have during my semester. |
I think it's fine to leave this open while we investigate! Hopefully we can figure this out together |
just to add one more idea for now: "[Python]": {
"editor.detectIndentation": false,
"editor.tabSize": 4,
"editor.insertSpaces": true
} so we could add a per language default (for all languages currently supported with I am not sure if we can get any other information other than the file types from the grammar? |
yeah I want to have some sort of user configuration eventually, I don't think we need to implement it yet though:
|
Hi,
I tried implementing an automatic
tabsize
detection when opening a file.test_dedent_selection
test, because the tab size was detected as 2 tabs. I think it actually wants to test that lines are properly dedented, even if the indentation is smaller than the currently settab_size
right? I think the test still does this now?I am not sure if this detection will fit all different kinds of files or if the file type has to be taken into consideration...