9
15
Fork
You've already forked zig.vim
2

Slow formatting in neovim #109

Open
opened 2025年01月15日 19:11:50 +01:00 by zoeesilcock · 3 comments
zoeesilcock commented 2025年01月15日 19:11:50 +01:00 (Migrated from github.com)
Copy link

Formatting is very slow when called via zig#fmt#Format() and when using zig_fmt_autosave on neovim. In all of my testing I have found that running zig fmt ****.zig directly in the terminal is instant, so my suspicion is that the shell is too slow at pushing large amounts of data through stdout.

I tested with a file that has 2297 lines and got the following results (two different machines, so they aren't comparable to each other):

  • Windows (PowerShell): 31 seconds
  • Mac: 13 seconds

I really want to use format-on-save, but it really doesn't take long to hit a line count that leads to a pause on every save which is very distracting.

The workaround I am using now is to disable format-on-save and bind a key to run the shell command and reload the file manually: <cmd>!zig fmt %<CR><cmd>:e<CR><cmd>LspRestart<CR>. But it would be more convenient if I could just leave zig_fmt_autosave enabled. It's also problematic for new users as it isn't obvious that neovim includes this plugin and that it has format-on-save enabled by default and could give the impression that zig or zig fmt is slow.

Versions:

PS > nvim -v 
NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info
PS > zig version
0.13.0
Formatting is very slow when called via `zig#fmt#Format()` and when using `zig_fmt_autosave` on neovim. In all of my testing I have found that running `zig fmt ****.zig` directly in the terminal is instant, so my suspicion is that the shell is too slow at pushing large amounts of data through stdout. I tested with a file that has 2297 lines and got the following results (two different machines, so they aren't comparable to each other): * Windows (PowerShell): 31 seconds * Mac: 13 seconds I really want to use format-on-save, but it really doesn't take long to hit a line count that leads to a pause on every save which is very distracting. The workaround I am using now is to disable format-on-save and bind a key to run the shell command and reload the file manually: `<cmd>!zig fmt %<CR><cmd>:e<CR><cmd>LspRestart<CR>`. But it would be more convenient if I could just leave `zig_fmt_autosave` enabled. It's also problematic for new users as it isn't obvious that neovim includes this plugin and that it has format-on-save enabled by default and could give the impression that zig or `zig fmt` is slow. Versions: ``` PS > nvim -v NVIM v0.10.2 Build type: Release LuaJIT 2.1.1713484068 Run "nvim -V1 -v" for more info PS > zig version 0.13.0 ```
zoeesilcock commented 2025年01月28日 14:09:39 +01:00 (Migrated from github.com)
Copy link

It looks like the vim-go plugin that this was originally based on also had this issue. This is the issue: https://github.com/fatih/vim-go/issues/459#issuecomment-112751728 and this appears to be the solution they landed on: https://github.com/fatih/vim-go/pull/476/files. Unfortunately I don't know Vimscript well enough to test this fix myself, but hopefully it can point some one with more experienced in the right direction.

It looks like the vim-go plugin that this was originally based on also had this issue. This is the issue: https://github.com/fatih/vim-go/issues/459#issuecomment-112751728 and this appears to be the solution they landed on: https://github.com/fatih/vim-go/pull/476/files. Unfortunately I don't know Vimscript well enough to test this fix myself, but hopefully it can point some one with more experienced in the right direction.
itsfarseen commented 2025年05月17日 13:19:43 +02:00 (Migrated from github.com)
Copy link
I fixed this by using neovim-lsp to format files through zls. https://github.com/itsfarseen/dotfiles/blob/main/config/nvim/lua/config/lsp-config.lua#L38 https://github.com/itsfarseen/dotfiles/blob/main/config/nvim/lua/format-config.lua
zoeesilcock commented 2025年10月09日 17:05:13 +02:00 (Migrated from github.com)
Copy link

Yeah, I ended up solving it in a similar way via conform.nvim: zoeesilcock/dotfiles@13b9fa1c48/home/.config/nvim/lua/zoee/plugins/formatting.lua (L12)

Yeah, I ended up solving it in a similar way via conform.nvim: https://github.com/zoeesilcock/dotfiles/blob/13b9fa1c48202a6f8c1268fc6b463bce02298bd8/home/.config/nvim/lua/zoee/plugins/formatting.lua#L12
Sign in to join this conversation.
No Branch/Tag specified
master
hb/new-keywords
mikdusan-zir
No results found.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig.vim#109
Reference in a new issue
ziglang/zig.vim
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?