-
Notifications
You must be signed in to change notification settings - Fork 88
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
Updating PG way to communicate with Coq #619
Comments
We definitely need to do something like that.
I am willing to participate. Although my short future (few months) is quite busy. |
I don't know enough internals as to know how hard would it be to adapt PG, last time I looked the work done in the async branch was way too complex for what's needed, for example see @cpitclaudel I am talking here of creating a protocol for PG that we will ship in core Coq, so no plugin dependency needed. |
You could always do a prototype with SerAPI of course, if you think that provides a good enough setup; once you are happy we can add to Coq the protocol, but without the serialization parts, so mainly |
I just had a look at |
For the format of output for
|
The simple protocol, you are talking about - does it have a name? Is it implemented already somewhere? Where can I read the specification? |
@Matafou the format of query for now can be string, one important property of query is that it is stateless, usually you'd like to put all printing options on query. @hendriktews , for now it doesn't really have a protocol, the jsCoq / SeraPI protocol is the same, but we could call it elcoq once we make it work with Coq. I think SerAPI can be a good starting point, you can check SerAPI docs they are usually OK [pyCoq will also implement some very similar API soon], but in my view the development of the protocol should be co-dependent with the changes in PG, so we should be free to evolve it. For example as I mentioned we should maybe make the calls take a position and not a statement id as to relieve emacs from synchronizing that stm_id table. I'd be happy to provide a prototype if you folks would need it. |
I don't understand. coq would be aware of positions in the buffer? But positions often change so that would mean coq is also aware of edition events? I second Hendriks question: is there a documentation on stm + protocols for complete beginners? I think I need a fresh look at all this. |
That's how most modern protocol works, you relay edits in some way; see LSP. You can also work sentence-based, as you prefer. But indeed, it is hopeless for editors to understand PL structure with current tech in a complete way.
There is of course serapi documentation, and LSP documentation, but there is nothing too fancy there, the devil is in the details. IMHO it is better to do a session in a Coq call and see the thing working, or please ask specific questions if you have some. |
As far as I understood from briefly reading SerAPI, when the user changes something in the buffer, the UI needs to send Cancel commands for all stuff following the change. When the user finishes, the UI can Add it again and let Coq parse it. This way, the positions are always synchronized between the UI and Coq for the parsed portion. |
OK, I am still trying to understand the actual proposal. Let me rephrase: You propose to design a new protocol Direct support from the Coq team would indeed change the motivation on the Proof General side, I believe... |
The current design is a bit different, you send Synchronizing the positions indeed can be done in many ways.
Indeed, I propose we move PG to a protocol that solves all the problems we currently have, fully supported by the Coq team and included in Coq. I think we should indeed iterate on the design a bit, so we are sure we have a clear model and we have a bit of freedom to fix possible pain points.
Correct. |
coq-lsp is in a usable state now. I think it would be a good time to start experimenting with PG going through lsp. I know PG has many features that would be useful for other UIs so it would be good to start upstreaming these. |
Thanks @Alizter for your heads-up ! This indeed deserves some dedicated discussion in some upcoming PG telco, Cc @Matafou @hendriktews A few questions/comments:
|
I agree. I'm not sure how PG interacts with Coq today (I vaguely know it is going through |
Exactly. To give a few more details,
|
It was a layer using SerAPI (which was very nice to program against), not LSP. It's here: https://github.com/cpitclaudel/elcoq LSP doesn't have support for interactive theorem proving, so it's really coq-lsp that we are going to support (not plain LSP). Are there docs on how to communicate to Coq where we are in the file, where we want to process until, or maybe where the user is looking, etc? |
Yes, when I mentioned LSP I was really meaning coq-lsp. |
LSP doesn't have support for interactive theorem proving, so it's really
coq-lsp that we are going to support (not plain LSP). Are there docs on how
to communicate to Coq where we are in the file, where we want to process
until, or maybe where the user is looking, etc?
I know nothing about `coq-lsp`, but you could probably reproduce the PG
workflow by only telling the `coq-lsp` server about the section of the
buffer that's currently "processed", and just adding/removing chunks at
the end as the user moves the boundary.
[ The LSP protocol is based on the idea that the client sends to the
server the text of the buffer/file, as well as any subsequent
modifications to that text and the LSP server keeps a local copy of
that text. Usually that text is the whole file/buffer, but we could
just as well decide to pretend that it's only the part of the buffer
before the boundary, and when the user moves the present it to the
LSP server as if the user had just inserted/deleted text at the
end. ]
Not sure if that would give you the needed info to display the current
proof state when you're in the middle of a proof, tho.
Stefan
|
You can get a working setup with pure LSP , however that becomes a bit annoying due to having to show goal info using the hover call. coq-lsp provides two extensions to help clients, see https://github.com/ejgallego/coq-lsp/blob/main/etc/doc/PROTOCOL.md There are very close to what lean does today, well, Lean's infoview has a much more complex protocol for some advanced features. Another important thing that you may want to do in proof general is specifying the range of the document you'd like to be checked. coq-lsp by default will check the whole document, but the LSP specification 3.18 will include a coq-lsp underlying checking engine already support (and relies) on checking just a part of the document. So PG would basically use standard LSP + IMVHO letting coq-lsp check the full document is not as wasteful as it seems, and in fact tends to speed up the proof process quite a bit, recall that coq-lsp is incremental so the common case when editing should be that you don't recheck the document, but Coq still needs a few changes to make this work better. But indeed, if you have very long proofs, I agree that a mode with Pull Diagnotics + range is more convenient. |
Another model I guess once we are a bit more mature we will support performance / powersaves mode, with the tradeoff of CPU vs latency. |
Dear PG devs,
the topic of how Proof General interacts with Coq has been again discussed Coq upstream. I think the moment has come where we should try to add a bit more structure to PGs / Coq-EasyCrypt interface and solve many longstanding issues, including a large and tricky to maintain comint code.
I'd suggest to implement some very lightweight protocol, based on sexp or yojson, and fully specified by a typed schema in OCaml; we have enough experience already to understand that a model like the current one provided by SerAPI / jsCoq works well enough, and in fact was co-designed by @cpitclaudel .
The protocol is very easy, you have 4 commands
Add, Query, Check, Cancel
, which can be location-based (à la LSP) or sentence based, and then a few responses such asGoals, Cancelled, Ack
.Note that this kind of protocol avoids many tricky points with the XML one.
Another choice is just to have PG use LSP, I dunno, this would require more work.
This would also open the way to query for other interesting info, which is not possible today.
Handling of coqc output is a separate issue, but usptream is working on it.
Let me know what you folks think.
List of relevant issues:
-w
is passed to Coq via _CoqProject #113The text was updated successfully, but these errors were encountered: