Closed timfayz closed 1 month ago
By default, the vscode-zig extension provides formatting by itself and does not rely on ZLS unless the zig.formattingProvider
config option is set to zls
. There have been other recent reports about the vscode-zig formatting not working properly but me and @SuperAuguste have not been able to reliably reproduce or identify the cause of this issue.
One possible reason could be the fact that zig fmt
has recently become just in time compiled when it is first used. This means that formatting for the first time will take some time until the formatter has been compiled. This can be easily noticed when running zig fmt --help
with a new Zig version or cleared cache.
Until this has been resolved, you can switch to ZLS as the formatting provider which does not have this issue as far as I can tell.
Lately, I've been getting this freeze almost every minute or so. I gave "zig.formattingProvider": "zls"
a try, and it seems it's working! My saviour! Thank you! The question is then what kind of formatter I was using? The option was set to extension
. Also, does it mean the "zig.zls.*"
options are irrelevant unless switched to the zls
provider?
Both formatting providers behave identical. extension
means that the vscode-zig extension runs zig fmt
behind the scenes. zls
means that the vscode-zig extension will ask ZLS to format the file and ZLS will run the standard library code that implements zig fmt
(ZLS basically contains the zig fmt
command). The zig.formattingProvider
is only about formatting the zig.zls.*
are about all the other ZLS features that are not formatting.
The zig.formattingProvider is only about formatting [and] the zig.zls.* are about all the other ZLS features that are not formatting.
Sorry, I didn't really understand the answer. Isn't, say, zig.zls.enableAutofix
part of the formatting? If not, then what is it part of?
Also, I tried to disable the formatting altogether but realized that I can't (through options) unless I disable the extension itself. Here are my options (relevant parts):
"zig.formattingProvider": "off",
"zig.zls.enableBuildOnSave": false,
"editor.formatOnSave": false,
Interesting to note that when it comes to formatting other files (eg. json), the formatOnSave
set to false effectively disables the feature. So it seems the extension does not respect the global option and formatting is executed no matter what.
Update: "zig.formattingProvider": "off"
indeed disables formatting (I just needed to reload the editor). However, solely using "editor.formatOnSave": false
doesn't disable it.
Sorry, I didn't really understand the answer. Isn't, say,
zig.zls.enableAutofix
part of the formatting? If not, then what is it part of?
Autofix may appear as a feature build on top of formatting but they are actually independent. You can use autofix without formatting and the other way round.
When talking about formatting, I refer to all changes that zig fmt
does. All other text edits you see are autofix from ZLS and don't rely on zig fmt
or the zig executable in general.
The zig.formattingProvider
only concerns itself with formatting and not autofix.
However, solely using
"editor.formatOnSave": false
doesn't disable it.
The vscode-zig extension overrides the editor.formatOnSave
option for Zig which takes priority over the "ordinary" editor.formatOnSave
option.
To disable formatting on Zig files in VS Code, the following needs to be added to settings.json
:
"[zig]": {
"editor.formatOnSave": false
}
This should have hopefully been fixed by https://github.com/ziglang/vscode-zig/pull/222 which is in the vscode-zig 0.5.9 release. If this still happens, feel free to report this to vscode-zig.
Zig Version
0.12.0
Zig Language Server Version
ZLS 0.12.0
Client / Code Editor / Extensions
Visual Studio Code-1.88.1
Steps to Reproduce and Observed Behavior
I use zls as part of the Zig extension for vscode. The problem is that zls constantly freezes when attempting to format a file before saving. It happens more frequently when there are syntax errors. Aside from that, I don't see any significant patterns. When it happens, vscode pops up a notification on the right, stating
Saving 'some_file.zig': Running 'Zig Language' Formatter
, and I am unable to save the file (other than continuing editing it). As a result, I find myself constantly pressingcmd+shift+p
to open the command palette and runningDeveloper: Reload Window
to forcefully "reset" the editor.I have the following configuration:
Note that there are two instances of
zig.zls.path
. This is to show that I have tried both: the zls installed by the extension itself and the one I manually installed throughbrew install zls
. Unfortunately, the problem persists regardless of which binary I use. I don't remember exactly when the problem started, but it dates back to zls versionfd9d2642e27ac65ea96fb37a27e02c9e2d269e23
, committed on Oct 22, 2023 (so no fuzz about latest 0.12.0 release, I simply tired of this problem and decided to report now). Despite trying various zig and zls updates, uninstalling and reinstalling the extension, or reopening the editor, the issue always remains.Expected Behavior
No freezing.
Relevant log output