Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

zig_fmt_autosave writes escape characters in the current buffer #105

Open
Gogopex opened this issue Jul 20, 2024 · 2 comments · May be fixed by #106
Open

zig_fmt_autosave writes escape characters in the current buffer #105

Gogopex opened this issue Jul 20, 2024 · 2 comments · May be fixed by #106

Comments

@Gogopex
Copy link

Gogopex commented Jul 20, 2024

Heya,

~ ❱ nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1720049189
~ ❱ zig version
0.13.0

This is on a completely clean neovim and zig install. Entering :w with a Zig file opened causes escape characters to be printed in the current buffer. This happens across all the terminal emulators I use (ghostty, wezterm, alacritty).

Quick recording:
demo

The escape characters inserted:

]4;1;rgb:cc/24/1d��]4;2;rgb:98/97/1a��]4;3;rgb:d7/99/21��]4;4;rgb:45/85/88��]4;5;rgb:b1/62/86��]4;6;rgb:68/9d/6a��]11;rgb:1d/20/21��]10;rgb:eb/db/b2��]4;0;rgb:1d/20/21��]4;7;rgb:a8/99/84��]4;8;rgb:92/83/74��]4;9;rgb:fb/59/34��]4;10;rgb:b8/bb/26��]4;11;rgb:fa/bd/2f��]4;12;rgb:83/a5/98��]4;13;rgb:d3/86/9b��]4;14;rgb:8e/c0/7c��]4;15;rgb:eb/db/b2��]4;236;rgb:32/30/2f��]4;234;rgb:1d/20/21��]4;235;rgb:28/28/28��]4;237;rgb:3c/38/36��]4;239;rgb:50/49/45��]4;241;rgb:66/5c/54��]4;243;rgb:7c/6f/64��]4;244;rgb:92/83/74��]4;245;rgb:92/83/74��]4;228;rgb:f2/e5/bc��]4;230;rgb:f9/f5/d7��]4;229;rgb:fb/f1/c7��]4;223;rgb:eb/db/b2��]4;250;rgb:d5/c4/a1��]4;248;rgb:bd/ae/93��]4;246;rgb:a8/99/84��]4;167;rgb:fb/49/34��]4;142;rgb:b8/bb/26��]4;214;rgb:fa/bd/2f��]4;109;rgb:83/a5/98��]4;175;rgb:d3/86/9b��]4;108;rgb:8e/c0/7c��]4;208;rgb:fe/80/19��]4;88;rgb:9d/00/06��]4;100;rgb:79/74/0e��]4;136;rgb:b5/76/14��]4;24;rgb:07/66/78��]4;96;rgb:8f/3f/71��]4;66;rgb:42/7b/58��]4;130;rgb:af/3a/03�fn main() u8 {

I've tried tons of things to figure this out and ended up figuring out (after trying 100x things) that setting vim.g.zig_fmt_autosave = 0 fixed the issue, although obviously at the cost of the auto-formatting on save. I ended up trying to debug zig.vim and found that the "guilty" line is https://github.com/ziglang/zig.vim/blob/master/ftplugin/zig.vim#L41. However, my zig env's output seeems clear.

~ ❱ zig env
{
 "zig_exe": "/opt/homebrew/Cellar/zig/0.13.0/bin/zig",
 "lib_dir": "/opt/homebrew/Cellar/zig/0.13.0/lib/zig",
 "std_dir": "/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std",
 "global_cache_dir": "/Users/hey/.cache/zig",
 "version": "0.13.0",
 "target": "aarch64-macos.14.5...14.5-none",
 "env": {
  "ZIG_GLOBAL_CACHE_DIR": null,
  "ZIG_LOCAL_CACHE_DIR": null,
  "ZIG_LIB_DIR": null,
  "ZIG_LIBC": null,
  "ZIG_BUILD_RUNNER": null,
  "ZIG_VERBOSE_LINK": null,
  "ZIG_VERBOSE_CC": null,
  "ZIG_BTRFS_WORKAROUND": null,
  "ZIG_DEBUG_CMD": null,
  "CC": null,
  "NO_COLOR": null,
  "CLICOLOR_FORCE": null,
  "XDG_CACHE_HOME": null,
  "HOME": "/Users/hey"
 }
}

Has anyone had that issue? Am I going crazy?

@melenaus
Copy link

I have the same issue.
After deleting all nvim chaches and re-installing it works for a short time before zig fmt starts throwing errors and slowing down massively on save. This happens both on windows 11 and ubuntu.

@Gogopex
Copy link
Author

Gogopex commented Jul 27, 2024

I fixed it locally by modifying zig.vim, but not sure if it's good enough to merge. I can open up the PR if anyone's interested.

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

Successfully merging a pull request may close this issue.

2 participants