flyx/NovaZig

Saving a file makes Nova attempt to save indefinitely

haze opened this issue · 9 comments

haze commented

image

I'm only able to save after I click "Save anyways" on this popup
image

This happens with format on save both off and on

edit: I just removed the LSP from main.js and that seems to have fixed the problem, digging deeper...

flyx commented

This would be zig fmt having a problem. Can you still build?

I think there was a change between recent Nova versions where the API launching external processes no longer injects the login shell's PATH unless you tell it to launch in a shell. This would affect NovaZig because it discovers its utilities via which/env.

I fixed this in the toolbox nova-extension-utils which I have extracted from this extension. My other extension nova-nix-suite was already updated to fix this issue, this one hasn't yet.

If you're adventurous and have nix available on your system, you can try to check out this repo, do a nix flake update (to update nova-extension-utils), then nix build and test the extension in the generated result folder. It may be a few days before I find time to investigate myself.

haze commented

I unfortunately don't have nix available on my computer. I tried using a NixOS vm but didn't get very far there. Are you sure it's "zig fmt"? (I was able to format files just fine, it's just that saving w/ the LanguageServer attached lead to this behavior). I nuked the LanguageServer from main.js and the problem went away

flyx commented

Well the only thing the extension does when saving is formatting via zig fmt, and I have seen this error only when that operation ran into problems.

However it may also be that Nova tries to use the language server's ability to auto-format, I am unsure whether it can do that. Did you configure zls to auto-format?

haze commented

Hmm. I don't think zls has the option to enable formatting. I DO have the option for autofix enabled. I'll try disabling that and trying again

flyx commented

I tried to reproduce this without success. Possibly it is already fixed from upstream nova-extension-utils changes. Since Zig is moving fast, it's always possible that our setups differ, so it would be great if you could test this on your system.

Here's the current dev version, zipped: NovaZig-v0.1.0-2-g132256f. Could you unzip this, open it in Nova for editing, then from the menu Extension -> Activate Project as Extension (need to disable the released NovaZig version first) and see if the error still occurs?

haze commented

image

No dice. I also don't have Format on save enabled.

I think this has to do with ZLS attempting to apply some edits before we save the file. I do not think I can disable this with the config file.

In your compiled extension, if I block ZLS from loading (quite literally delete the chunk where you instantiate the language server in exports.activate), then saving works as intended.

flyx commented

Can you give me your ZLS version (zls --version for compiler version, ideally also commit hash if you compiled from source) and your complete config (zls --show-config-path)? And can you give me the source code where this occurs (if it's publicly available, a GitHub repo would be fine)?

There also seems to be a problem with auto-formatting currently, formatting happens even when I turn it off. This may play into it.

haze commented

ZLS version 0.11.0-dev.62+9e658cd
Zig version 0.11.0-dev.682+fc6d7d279

This is reproducible for me with any zig source file

flyx commented

Quick update, I currently don't find the time to build a dev environment to reproduce this. However, I did scout a bit through the docs and can confirm that

  • Nova does provide support for formatting via Language Server. The docs do not indicate any possibility of disabling this via code in an extension. There also doesn't seem to be any user-facing setting to turn this off.
  • ZLS provides support for auto-formatting. There is no setting to turn it off, at least the docs don't mention one. After the last release (which is what I'm using), there was this commit related to formatting which may have to do something with the problem.

In any case, this issue is a communication problem between zls and Nova, and it is very unlikely that it can be fixed in NovaZig.

What needs to be done with this issue is to reproduce the problem, analyse it, and then report it to whatever component is at fault (either Nova or zls). Not easy when Nova is a binary blob. I hope I find the time to do this early next year.