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

Disable built-in formatting for zig #28878

Closed
flexagoon opened this issue May 20, 2024 · 11 comments · Fixed by #28904
Closed

Disable built-in formatting for zig #28878

flexagoon opened this issue May 20, 2024 · 11 comments · Fixed by #28904
Labels
has:vim-patch issue is fixed in vim and patch needs to be ported runtime funtime

Comments

@flexagoon
Copy link

flexagoon commented May 20, 2024

Problem

By default, nvim's Zig ftplugin will format zig files on save:

autocmd BufWritePre <buffer> if get(g:, 'zig_fmt_autosave', 1) | call zig#fmt#Format() | endif

This is very confusing, since this behavior is not documented anywhere, and users expect nvim not to format anything unless they configure it to do so.

Steps to reproduce

Have zig installed

nvim --clean test.zig

pub const Test= enum { Foo,
    Bar};

Save the file and it will be automatically formatted

Expected behavior

Nvim should not do any automatic formatting by default which requires an undocumented global variable to disable.

At least the default value should be changed to 0 to disable this setting by default.

Neovim version (nvim -v)

NVIM v0.11.0-dev+18-g63e3a63d2

Vim (not Nvim) behaves the same?

Yes, vim 9.1

Operating system/version

Fedora Silverblue 40

Terminal name/version

Wezterm

$TERM environment variable

xterm-256color

Installation

Occurs with any installation method

@flexagoon flexagoon added the bug issues reporting wrong behavior label May 20, 2024
@zeertzjq
Copy link
Member

It seems that this only documented in the README of https://github.com/ziglang/zig.vim

@flexagoon
Copy link
Author

@zeertzjq it is absolutely not clear that you have to look in a readme of some third-party repo for a solution to the issue. If this behavior is to be kept, it should at least be added as a :h file. Though I still think that it should not be on by default.

@zeertzjq
Copy link
Member

@zeertzjq zeertzjq added runtime funtime needs:vim-patch upstream issue that must be fixed in Vim first and removed bug issues reporting wrong behavior labels May 20, 2024
@flexagoon
Copy link
Author

@zeertzjq the ziglang/zig.vim#51 issue was closed due to not enough interest, but since then, many people have commented on it saying that this behavior is annoying. I think even if this change won't be made in upstream zig.vim, it should be made in Neovim to have better defaults.

@i3ima
Copy link

i3ima commented May 20, 2024

I also stumbled upon this behavior and I support opinion that this should not be on by default. In fact if you’ll look at zig_fmt_autosave in other Vim/Neovim distributions, dotfiles and so on — you’ll see that everybody is aware of this thing

@clason
Copy link
Member

clason commented May 21, 2024

We do not maintain these files; please contact the maintainer listed at the top of the file and propose the change; if there is no response, you may raise an issue at vim/vim directly. If they make the change, we will port it; otherwise not.

@flexagoon
Copy link
Author

@clason why can't nvim change ftplugins independently of vim? Is that for compatibility reasons?

@clason
Copy link
Member

clason commented May 21, 2024

Yes (and to make sure that any improvements benefit both projects). This is an ironclad project policy.

@gpanders
Copy link
Member

I've opened a PR with Vim to change the default vim/vim#14820.

@flexagoon
Copy link
Author

@gpanders perhaps you could continue the work in the existing PR?

vim/vim#13803

It is a full refactor of the zig ftplugin, so I think it'd be better to merge that, seems like the only thing it misses is documentation for one variable.

@flexagoon
Copy link
Author

@clason vim merged the PR with the fix. Will it be downstreamed into nvim automatically?

@zeertzjq zeertzjq added has:vim-patch issue is fixed in vim and patch needs to be ported and removed needs:vim-patch upstream issue that must be fixed in Vim first labels May 21, 2024
@neovim neovim deleted a comment from neovim-discourse Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has:vim-patch issue is fixed in vim and patch needs to be ported runtime funtime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants