Compiling appends directory content to file

Hey everyone, so I am pretty new to Zig, but really trying to get into it, unfortunately everytime I save a zig file, it appends the contents of the directory that the zig program is in to the top of the program file. I use neovim, and I thought it may be a plugin acting up or something similar, so I tried Neovim without a config, and without any plugins, and it’s still doing it. Has anyone had any similar issues? I’m using the latest zig version as well.

OS: Pop-Os
Architecture: x86_64

Never seen that, but I noticed that somehow a neovim plugin is automatically installed which runs zig fmt on save, and I have no idea how that happend :smiley: …I’m definitely not a fan of any software automatically installing neovim plugins though.

…interesting, when I run brew uninstall neovim followed by brew install neovim the Zig plugins are already there:

runtime ➤ fd zig                                                                        git:stable
autoload/zig/
compiler/zig.vim
compiler/zig_build.vim
compiler/zig_build_exe.vim
compiler/zig_test.vim
ftplugin/zig.vim
indent/zig.vim
syntax/zig.vim

…are those somehow part of a default neovim installation?

yes:

I do remember seeing someh were that the Neovim Core team was looking at zig to improve the build system for neovim, and even possibly adopting it.

Ha yes! Automation and Neovim = awesomeness!

Ya, it’s super weird, super weird i’ve tried everything, I don’t know if i could even code outside of Neovim, so it’s definitely stunk because I’m super interested in Zig, and i feel helpless, and i’ve tried everything I feel like! ><

I code in neovim with zig regularly and have never seen this. Do you have your config somewhere?

I just uploaded my nvim config ! Really do appreciate any help everyone! GitHub - CK-7vn/dotfiles: configs

Just to confirm/deny if it’s zig fmt, create a file (not via neovim) with the contents

const
foo
= 1;

and run zig fmt <filename> on it. Does that reproduce your problem?

Sadly, yes :(, so I created deny.zig, and then added the const foo = 1; and when I saved the file, it appended, actually not just the directory structure but > bin completion.bash.inc completion.zsh.inc data deb install.bat install.sh lib LICENSE path.bash.inc path.fish.inc path.zsh.inc platform properties README RELEASE_NOTES rpm VERSION build.zig build.zig.zon confirm.zig deny.zig src I echo’d const foo = 1 into a zig file, and then ran zig fmt on that file, and it didn’t append the contents, so it has to be some kind of neovim issue…i just can’t figure out what it is, begins even when I run neovim bare bones, it still does it…it’s really got my mind spinning.

Try adding

vim.g.zig_fmt_autosave = 0

to the top of your init.lua, that should at least stop the issue when you save a file.

Otherwise check through https://zigtools.org/zls/editors/vim/nvim-lspconfig/. Unsure if you’re using ZLS, but there could be something useful in there still!

1 Like

Hey! That fixed it!!! Wooooo!!! Thanks a ton! Appreciate all of the help from everyone! Nice to know Zig has such an awesome community surrounding it!

1 Like