8
14
Fork
You've already forked zig-mode
1

Add flymake integration #93

Open
zenMaya wants to merge 1 commit from zenMaya/master into master
pull from: zenMaya/master
merge into: ziglang:master
ziglang:master
zenMaya commented 2023年09月15日 19:28:25 +02:00 (Migrated from github.com)
Copy link

Flymake is a pretty good backend to report compiler errors to. Better than compilation-mode. This commit allows, if user calls flymake-mode, to automatically call a zig command. It is zig build test but can be zig ast-check or similar. The errors are automatically reported to the buffer. This works project-wide with correct locations.

However, a small limitation is, that only one process can be spawned. This is because otherwise there would be much more code to check in a alist. (key would be either (project-current) or if nil (current-buffer))

I don't think it is a huge limitation, as the commands runs project-wide and most people won't run more than one project check at a time.

In the reference implementation the command is ran per buffer, which this implementation does not support. And that is why the limitation is here compared to the flymake
manual (https://www.gnu.org/software/emacs/manual/html_node/flymake/An-annotated-example-backend.html).

Flymake is a pretty good backend to report compiler errors to. Better than `compilation-mode`. This commit allows, if user calls `flymake-mode`, to automatically call a zig command. It is `zig build test` but can be `zig ast-check` or similar. The errors are automatically reported to the buffer. This works project-wide with correct locations. However, a small limitation is, that only one process can be spawned. This is because otherwise there would be much more code to check in a alist. (key would be either `(project-current)` or if nil `(current-buffer)`) I don't think it is a huge limitation, as the commands runs project-wide and most people won't run more than one project check at a time. In the reference implementation the command is ran per buffer, which this implementation does not support. And that is why the limitation is here compared to the flymake manual (https://www.gnu.org/software/emacs/manual/html_node/flymake/An-annotated-example-backend.html).
Collaborator
Copy link

Why not create another package flymake-zig? Probably cleaner this way. 🤔

Why not create another package `flymake-zig`? Probably cleaner this way. 🤔
purcell commented 2024年03月01日 13:50:04 +01:00 (Migrated from github.com)
Copy link

Every version of Emacs that zig-mode supports has a compatible modern flymake included, so here I wouldn't recommend splitting it into a separate package: it's fairly common and reasonable for a major mode to bundle some basic flymake support. I have some comments on the specifics of this PR, though, which I'll leave in a quick review.

Every version of Emacs that zig-mode supports has a compatible modern `flymake` included, so here I wouldn't recommend splitting it into a separate package: it's fairly common and reasonable for a major mode to bundle some basic flymake support. I have some comments on the specifics of this PR, though, which I'll leave in a quick review.
purcell (Migrated from github.com) reviewed 2024年03月01日 13:57:35 +01:00
@ -73,0 +74,4 @@
"Enable zig flymake integration."
:type 'boolean
:safe #'booleanp
:group 'zig-mode)
purcell (Migrated from github.com) commented 2024年03月01日 13:57:27 +01:00
Copy link

:group is redundant in all these defcustoms because it defaults to the group created by the defgroup above.

`:group` is redundant in all these `defcustom`s because it defaults to the group created by the `defgroup` above.
@ -120,0 +164,4 @@
(beg-col (string-to-number (match-string 3)))
;; Zig does not warn, only errors or notes.
(type (if (string-match "^error" msg)
:error
purcell (Migrated from github.com) commented 2024年03月01日 13:56:21 +01:00
Copy link

Worth checking here whether this honours buffer-local exec-path (ie. $PATH) settings in the initial source buffer, which is necessary when using direnv and envrc.el to put a specific zig on the path.

Worth checking here whether this honours buffer-local `exec-path` (ie. `$PATH`) settings in the initial source buffer, which is necessary when using `direnv` and `envrc.el` to put a specific `zig` on the path.
purcell (Migrated from github.com) commented 2024年03月01日 13:54:07 +01:00
Copy link

Doing this once at the top level is not going to work out well because changing zig-flymake after loading the file will make no difference. Better to add the zig--setup-flymake-backend to the default value of zig-mode-hook (which might mean adding an explicit defcustom for zig-mode-hook, or simply omit it and suggest that users call add-hook themselves.

If doing that, then you'd rename the function to zig-setup-flymake-backend because it's now effectively a public function.

Doing this once at the top level is not going to work out well because changing zig-flymake after loading the file will make no difference. Better to add the zig--setup-flymake-backend to the default value of zig-mode-hook (which might mean adding an explicit defcustom for zig-mode-hook, or simply omit it and suggest that users call add-hook themselves. If doing that, then you'd rename the function to zig-setup-flymake-backend because it's now effectively a public function.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin zenMaya/master:zenMaya/master
git switch zenMaya/master
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig-mode!93
Reference in a new issue
ziglang/zig-mode
No description provided.
Delete branch "zenMaya/master"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?