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

Add flymake integration #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add flymake integration #93

wants to merge 1 commit into from

Conversation

zenMaya
Copy link

@zenMaya zenMaya commented Sep 15, 2023

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).
@jcs090218
Copy link
Collaborator

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

@purcell
Copy link
Contributor

purcell commented Mar 1, 2024

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.

(defun zig--setup-flymake-backend ()
(add-hook 'flymake-diagnostic-functions 'zig-flymake nil t))

(if zig-flymake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

zig--flymake-proc
(make-process
:name "zig-flymake" :noquery t :connection-type 'pipe
:buffer (generate-new-buffer "*zig-flymake*")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

"Enable zig flymake integration."
:type 'boolean
:safe #'booleanp
:group 'zig-mode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Successfully merging this pull request may close these issues.

None yet

3 participants