🔣 A domain-specific language with handler combinators
- Dispatching diagnostics to different handlers
- Duplicating diagnostics to multiple handlers
- Filtering diagnostics
- Accumulating diagnostics (?)
I was going to write a response here that something like a handler combinator thingy is the more natural way to proceed, but you beat me to it :)
@kentookura Are you claiming that with these three combinators you can already implement the features you wanted trivially?
Yes, I think so
One thing that I want to point out is that when implementing a language server, it is important that an empty list of diagnostics gets pushed when a computation that previously failed now succeeded. Right now I am checking this manually, but maybe this is an interesting factor when designing this.
Another thing is that diagnostics need a URI to be published to, and a computation might raise diagnostics for many files. I am handling this by
- making sure that all diagnostic loctexts get created with the
sourceargument - accumulating them in a
(Lsp.Uri.t, diagnostic list) Hashtbl.tthat gets populated byemitandfatal: I am inspecting the loctext of the diagnostic and creating anLsp.Uri.tfrom it.
This is not enough, though:
Say that evaluating file A previously failed and had a diagnostic pushed to it. Running the evaluator again now succeeds, but now I need to know that A failed the last time in order to push an empty list to clear the diagnostics, so I need to track some state.