Skip to content

Error highlighting#77

Merged
mikeshulman merged 14 commits intogwaithimirdain:masterfrom
ElifUskuplu:elif-error-locs
Aug 16, 2025
Merged

Error highlighting#77
mikeshulman merged 14 commits intogwaithimirdain:masterfrom
ElifUskuplu:elif-error-locs

Conversation

@ElifUskuplu
Copy link
Collaborator

I've added an error highlighting property to proofgeneral mode. However, this is incomplete. It captures error position well, but in highlight, there is some shifting problem for some cases. An example is below.
Screenshot from 2025-06-05 19-22-40
I assume this is due to special characters. I'm working on this, but I wanted to show its current situation.

Co-authored-by: Mike Shulman <shulman@sandiego.edu>
ElifUskuplu and others added 2 commits June 5, 2025 22:44
Co-authored-by: Mike Shulman <shulman@sandiego.edu>
@ElifUskuplu
Copy link
Collaborator Author

ElifUskuplu commented Jun 7, 2025

I updated error highlight clearing rules, but I've found another problem in highlighting. If there is a line break between last successful span and the line containing the error, highlighting shifts accordingly.
situation1
situation2

@remimimimimi
Copy link

Wouldn't it be a better idea to use ready-made libraries for error highlighting like flymake-mode or flycheck-mode? See comparison here. I think flycheck-mode will be a better fit, since it should be easier to work with.

@mikeshulman
Copy link
Collaborator

@remimimimimi Thanks for the suggestion! I've never used either of those, but my impression (possibly erroneous) is that they wouldn't be a great fit. They seem designed to run a syntax checker themselves, asynchronously in the background on the entire buffer, and parse its pre-existing output format. Whereas in our situation, ProofGeneral is already handling the invocation of and communication with the proof assistant, which is synchronous and executes only one command at a time, plus we can also customize the output of the proof assistant to make it trivially easy to parse. Possibly there are some pieces of those packages that we could use, but I'm doubtful that trying to do so would save us more work than it created. But if you think differently, please explain!

@ElifUskuplu
Copy link
Collaborator Author

@remimimimimi I agree with Mike. Also, I'm not sure whether using them both flycheck and proofgeneral together can cause some problems. I've no experience with the former.

@mikeshulman
Copy link
Collaborator

I did a bit of quick google searching and didn't turn up anyone combining flycheck+proofgeneral.

@remimimimimi
Copy link

I recommended looking at them because it seemed strange that the proof general doesn’t handle overlays itself. It seemed like a solution for this, but agree that flycheck solving different problem.

Rocq seems to implement their own error highlighting mechanism as well. I checked proof general code base to find where error highlighting could happen automatically from error regex, but found nothing.

Want to mention that proof general has predefined faces for error highlighting proof-script-sticky-error-face and proof-script-highlight-error-face, which you might want to use instead of creating your own. Also, you don’t have to store overlays in variable, as you can delete all overlays in range by their face property like this (remove-overlays beg end 'face 'narya-error-face).

@mikeshulman
Copy link
Collaborator

Thanks for the tips! Maybe we should look at the Rocq code for some ideas, then.

I think the immediate reason for the offset shift is that the current code is counting offsets from the end of the last successful span rather than the beginning of the current unsuccessful span, and PG skips past blank lines (at least) before starting to grab the current command that it sends to the PA, so those two are not the same. There must be a way to grab the current span even in the case of an error.

@mikeshulman
Copy link
Collaborator

This PR needed merging with master, and while I was looking at it I found a way to fix the issue. Weirdly proof-action-list is set to nil in the case of an error before the handle-output function is called, but we can grab the correct starting location by advising proof-shell-error-or-interrupt-action. I also fixed a few things in the code for clearing error highlights.

@mikeshulman mikeshulman merged commit ddbce11 into gwaithimirdain:master Aug 16, 2025
4 checks passed
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.

3 participants