Skip to content
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

Doesn't understand the difference between tab_width and indent_size in editorconfig #24108

Open
tbodt opened this issue Feb 2, 2025 · 1 comment

Comments

@tbodt
Copy link

tbodt commented Feb 2, 2025

Summary

tab_width is the width a tab character should be rendered as. indent_size is the size of an indent level. In many projects (e.g. every project in GNU C style) they are not the same. But zed seems to pick one and use it for both.

.editorconfig

[*]
indent_style = tab
tab_width = 8
indent_size = 4

test.c

int main() {
    if (1) { // four spaces
	return 0; // one tab
    }
}

This should show the return 0 line with 8 spaces worth of indentation. But it should still use four space indents for editor commands that adjust indentation. (And, because indent_style = tab, also needs to replace n space indent with n/8 tabs and n%8 spaces)

Zed Version and System Specs

Zed: v0.171.6 (Zed)
OS: macOS 15.1.1
Memory: 16 GiB
Architecture: aarch64

@tbodt tbodt changed the title Doesn't seem to understand the difference between tab_width and indent_size in editorconfig Doesn't understand the difference between tab_width and indent_size in editorconfig Feb 2, 2025
@SomeoneToIgnore
Copy link
Contributor

let tab_size = cfg.get::<IndentSize>().ok().and_then(|v| match v {
IndentSize::Value(u) => NonZeroU32::new(u as u32),
IndentSize::UseTabWidth => cfg.get::<TabWidth>().ok().and_then(|w| match w {
TabWidth::Value(u) => NonZeroU32::new(u as u32),
}),
});
let hard_tabs = cfg
.get::<IndentStyle>()
.map(|v| v.eq(&IndentStyle::Tabs))
.ok();

The faulty conversion logic is here and it's caused by the fact, that Zed settings has only one concept for "indentation size":

/// How many columns a tab should occupy.
pub tab_size: NonZeroU32,

instead of two, as .editorconfig wants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants