You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As we know, Zig doesn't have conventional compiler warnings (which I think is a good thing). By this design, the only way Zig can communicate to a developer is to raise compiler errors (which also crashes the compiler) or by auto-formatting the code with zig fmt. I believe there exist enough common coding mistakes/errors a developer makes that Zig could be able to auto-format or have an option about but are of a kind such that they should be prompted and confirmed by the developer. Example of common easy-to-make mistakes are:
When this mode is enables, the following steps will be runned:
First check for mistakes that would not allow zig fmt to run (such as missing semi-colon). Example prompt:
> zig build --interactive
----- /home/name/zig-playground/src/main.zig -----
Missing semi-colon
3. pub fn main() void {
4. const a: usize = 4
-------------------------^ missing semi-colon
5. const b: usize = 2;
6. }
Auto-fixes:
(1)
4. const a: usize = 4;
Options:
'a': abort
'1': insert semi-colon at option (1)
- save the file in your text editor to reinvoke the compiler
zig: <user input>
Prompt the user for other kinds of errors that could depend on previous ones being fixed
Run zig fmt on all files and prompt the user if they want to overwrite files that would be formatted on disk
Continue with the existing zig build
Some kinds of errors should be possible to ignore, such as using var when should have used const or not calling deinit() on a resource. To persist this, I suggest that a new file (something like zig-dev.json) is added to the zig-cache folder.
Another point, all the prompts in this mode should be the same as in the potential Zig Language Server (see #615).
I know that this is not a typical language proposal, however, just as having zig fmt makes some language changes easier to make, I believe that developer prompt warnings/language server warnings also could be part of the language specification and adress issues like #224.
Why having this build mode and not just a language server protocol?
Having an IDE with a language server is great. But it could also be a hassle to set up and not supported by all editors. This would be an easy way to get much of the same development experience. I believe a mode like this would make the compiler feel like a friend and not just a too strict teacher. I also think a mode like this would not need to be very feature complete to give value.
Edit 1
I release that the envision workflow is quite similar to the --watch flag with the related issue #68. I still think that persistent ignorable warnings with potential auto-fixes have the potential to save a lot of developer time.
Dear @greenbech, thanks for your suggestions. zig tries to do things one way and has for some of your questions the (not yet ready) --watch mode. A more convenient option to try out things is watchexec with zig run or zig test.
As to simplify the codebase, zig separates execution options, if possible. So combining things will be up to the users or helping plugins.
There is only basic static analysis yet as zig is not selfhosted, so zig can not help you that much yet.
Feel free to ask me on the discord. Also: Also: We dont have a wiki page on usage how to setup something like the --watch option yet. Would be very nice, if you could add it as to get others started fast.
As we know, Zig doesn't have conventional compiler warnings (which I think is a good thing). By this design, the only way Zig can communicate to a developer is to raise compiler errors (which also crashes the compiler) or by auto-formatting the code with
zig fmt
. I believe there exist enough common coding mistakes/errors a developer makes that Zig could be able to auto-format or have an option about but are of a kind such that they should be prompted and confirmed by the developer. Example of common easy-to-make mistakes are:var
when should have usedconst
(see add an error for usingvar
when one could have usedconst
#224)defer <resource>.deinit()
Envisioned workflow
To enable this mode mode, add
--interactive
flagWhen this mode is enables, the following steps will be runned:
zig fmt
to run (such as missing semi-colon). Example prompt:zig fmt
on all files and prompt the user if they want to overwrite files that would be formatted on diskzig build
Some kinds of errors should be possible to ignore, such as using
var
when should have usedconst
or not callingdeinit()
on a resource. To persist this, I suggest that a new file (something likezig-dev.json
) is added to thezig-cache
folder.Another point, all the prompts in this mode should be the same as in the potential Zig Language Server (see #615).
I know that this is not a typical language proposal, however, just as having
zig fmt
makes some language changes easier to make, I believe thatdeveloper prompt warnings
/language server warnings
also could be part of the language specification and adress issues like #224.Why having this build mode and not just a language server protocol?
Having an IDE with a language server is great. But it could also be a hassle to set up and not supported by all editors. This would be an easy way to get much of the same development experience. I believe a mode like this would make the compiler feel like a friend and not just a too strict teacher. I also think a mode like this would not need to be very feature complete to give value.
Edit 1
I release that the envision workflow is quite similar to the
--watch
flag with the related issue #68. I still think that persistent ignorable warnings with potential auto-fixes have the potential to save a lot of developer time.Related issues:
#224
#615
#68
The text was updated successfully, but these errors were encountered: