zed
zed copied to clipboard
Hard Tabs Not Working
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
If you chose hard tabs in settings, it still uses spaces over tabs.
I have tried this in an empty folder with no .prettierrc or anything else
https://github.com/zed-industries/zed/assets/6720728/dd04a3b9-4c1c-440f-bd7a-b98120f3d6b3
Environment
Zed: v0.121.7 (Zed) OS: macOS 13.6.4 Memory: 32 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your ~/Library/Logs/Zed/Zed.log
file to this issue.
If you only need the most recent lines, you can run the zed: open log
command palette action to see the last 1000.
No response
I have the same issue and can't use zed right now because of it. I'm surprised this issue has always been there and not fixed yet.
So, as mentioned in #8817, this happens on save. When editing the tabs are inserted properly, and then converted by the auto-formater whenever one saves.
Since this hasn't been fixed still, does that mean that majority of developers are using spaces for indentation?
This issue is probably the sole reason I haven't switched to Zed yet.
Is this really so hard to fix? Now I have to fix indentation with vscode, which is pretty funny.
I seem to be unable to reproduce the issue in Zed 0.136.1:
https://github.com/zed-industries/zed/assets/2690773/cef81683-320e-452f-a199-a8f7bdc466eb
does anybody have it broken still?
Heya, yeap I do:
https://github.com/zed-industries/zed/assets/2993230/96e78350-f9fe-4ef8-9885-6c66f185c758
I just checked and my macOS is 14.4.1 though
Very odd, I seem to have replicated the settings, and also tried doing this on a Java project with tabs, which worked:
https://github.com/zed-industries/zed/assets/2690773/82168447-ad13-4825-9ab8-4b93dbaa9dfd
I would appreciate a project I could try to repro this on, and checking if you have any project-local Zed settings altering the behavior.
hmm, if you have maven, I reproduced it using this:
cd /tmp
mvn archetype:generate \
-DgroupId=random \
-DartifactId=random \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.4 \
-DinteractiveMode=false
cd random
# open /tmp/random in zed 1.36
# manually convert src/main/java/random/App.java to hard tabs
# save, and see the hard tabs turn back into spaces
I'm quite sure there's no additional settings; I'll try upgrade my OS later to see if it makes a difference
I do not think it's OS-dependent.
I have installed openjdk 21.0.3 2024-04-16
and Maven via the homebrew, did the steps said above and still seem to be able to input tabs by pressing tab and having hard_tabs: true
.
I wonder, if your config is somehow malformed? Does not seem to be, but just to rule it out, if you could start from {}
and add only the minimal thing to get the hard tabs in Java working?
https://github.com/zed-industries/zed/assets/2690773/66ef0b43-d9b7-4522-ae6d-cfb276f39da6
The other issue is that Java code is formatted by the Prettier with prettier-plugin-java
by default, and that integration reformats tabs into spaces — Zed should pass the hard_tabs
into Prettier invocation config, when formatting the corresponding language.
Here's the PR fixing that: https://github.com/zed-industries/zed/pull/11958 and a demo: https://github.com/zed-industries/zed/assets/2690773/80345cdd-d4f8-40b2-ab56-dba6b9646c70
Now, we need to find the reason the setting does not seem to work at all in some cases. So far, I've only seen that being caused by the odd config contents.
hm, the issue persists with just this config:
{
"format_on_save": "on",
"hard_tabs": "true",
"show_whitespace": "all"
}
and I tried with:
- only the
Java
extension installed (v0.0.4) - only the
Java with Eclipse JDTLS
extension installed (v0.2.0)
With neither extension installed, it "works", but that's of course because it's not got any language to format the file as.
edit: I'll try building Zed with the prettier fix tomorrow
I am clueless then at this point then, sorry.
Here's the place that reacts on the tab
press and inserts the hard tab for me: https://github.com/zed-industries/zed/blob/42cd1785156f927deb59cabaae892d0e78164748/crates/editor/src/editor.rs#L4961
It is pretty much "tab or spaces, insert them" and I cannot see how that may break.
Might be that there's some special action bound to tab
in the keymap?
I do not see how that's supposed to be replaced by whitespaces, so can only suggest trying building it from source and debugging (printing things with dbg! works too) and checking the logs (~/Library/Logs/Zed/Zed.log) for abnormalities (doubt that anything related will be there though).