zed icon indicating copy to clipboard operation
zed copied to clipboard

Hard Tabs Not Working

Open codebykenny opened this issue 5 months ago • 8 comments

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

codebykenny avatar Feb 10 '24 13:02 codebykenny

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.

hacking-robot avatar Mar 01 '24 08:03 hacking-robot

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.

pygy avatar Mar 04 '24 23:03 pygy

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.

pyronaur avatar Mar 31 '24 04:03 pyronaur

Is this really so hard to fix? Now I have to fix indentation with vscode, which is pretty funny.

barkely128 avatar May 09 '24 07:05 barkely128

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?

SomeoneToIgnore avatar May 16 '24 19:05 SomeoneToIgnore

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

azriel91 avatar May 16 '24 21:05 azriel91

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.

SomeoneToIgnore avatar May 16 '24 21:05 SomeoneToIgnore

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

azriel91 avatar May 16 '24 21:05 azriel91

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.

SomeoneToIgnore avatar May 17 '24 07:05 SomeoneToIgnore

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

azriel91 avatar May 17 '24 08:05 azriel91

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).

SomeoneToIgnore avatar May 17 '24 08:05 SomeoneToIgnore