Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Proposal] Add interactive development build mode #8323

Closed
greenbech opened this issue Mar 21, 2021 · 2 comments
Closed

[Proposal] Add interactive development build mode #8323

greenbech opened this issue Mar 21, 2021 · 2 comments
Milestone

Comments

@greenbech
Copy link

greenbech commented Mar 21, 2021

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:

Envisioned workflow

To enable this mode mode, add --interactive flag

zig build --interactive

When this mode is enables, the following steps will be runned:

  1. 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>
  1. Prompt the user for other kinds of errors that could depend on previous ones being fixed
  2. Run zig fmt on all files and prompt the user if they want to overwrite files that would be formatted on disk
  3. 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.

Related issues:
#224
#615
#68

@matu3ba
Copy link
Contributor

matu3ba commented Mar 21, 2021

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.

@g-w1
Copy link
Contributor

g-w1 commented Mar 21, 2021

The --watch option only works in stage2 which is not complete yet.

@andrewrk andrewrk added this to the 0.8.0 milestone Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants