-
-
Notifications
You must be signed in to change notification settings - Fork 21
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 OUTPUT-FILTER option #28
base: master
Are you sure you want to change the base?
Conversation
Closes #25
Looks good! Regarding #26 (comment), CLI command exit statuses are program specific. In the case of eslint, swaping the |
I'm not convinced that's the case. I just updated the PR description to reflect my findings in this area. |
Ah right, I looked over the filter implementation here. I guess in this implementation you can change the signature of the filter function to accept the input buffer and the output temp buffer, and replace the input buffer with whatever is returned from the filter function. When there's no output, the function can just return the input as is. Alternatively, an even easier solution will be if the filter function returns :output-filter (lambda ()
(let ((data (ignore-error 'json-end-of-file (json-read))))
(and data (arrayp data) (alist-get 'output (aref data 0))))) |
Ok nevermind, I see where you are going with this. I just remembered we'll want to preserve mark and point with In that case I maintain something similar to #26 is still the simpler solution. If there aren't any output the processor just needs to return the file as is. :output-processor (lambda (input-file output-file)
(let* ((data (ignore-error 'json-end-of-file (json-read-file output-file))
(output (and data (arrayp data) (alist-get 'output (aref data 0)))))
(if output (make-temp-file "eslint-format" nil nil output) input-file))) If the user cares about cleaning up the temp file, they can append a hook in |
Yes, potentially.
This exposes more info to the function than is necessary. The return value mechanism is more elegant.
That's a degree of unnecessary complication that can and should be avoided by design. |
Take a look at the latest changes here With regard to the temp file, hundred of programs leave temp files in the file system without cleaning them up when exiting. We aren't writing a server here where you'll run the risk of running out of inodes. Just leave OS problems to the OS. |
This commit will supply a callback to the processor. That callback will automatically create a temp file, and will be deleted after insertion. All your concerns are addressed now. Let me know if you want me to submit a new PR. You can now write your processor like so: :output-processor (lambda (output-file result-callback)
(let* ((data (ignore-error 'json-end-of-file (json-read-file output-file)))
(output (and data (arrayp data) (alist-get 'output (aref data 0)))))
(funcall result-callback output))) |
The big issue with all of this is error handling. When There's a pattern here that we're missing by hacking in an extra function, since each step (running the command, processing its output) is a consecutive reformatting step that receives input and can either skip, produce replacement text, or produce error output. I have some ideas about how to handle that more consistently and simply, and will likely pursue that in place of this approach. |
That sounds like a state machine. It's an admirable goal, but the implementation in this PR is entirely fine, the error handling problem isn't new and it's been around since there's an |
Happy new year! Can we merge this please? I'd rather have this than nothing at all. |
Closes #25, #26: this is similar but avoids leaving dangling temp files.
An
eslint --fix
formatter written with this facility looks like this:However, this fails when there are no fixes applicable to the current buffer, because no replacement
output
is included. We would need a structured way for theoutput-filter
function to indicate that it has determined there are no changes to be made.eslint --fix
returns a zero exit code in either case.