dune icon indicating copy to clipboard operation
dune copied to clipboard

Generate "_CoqProject" files for Coq theories

Open rlepigre opened this issue 7 months ago • 3 comments

This is a proof of concept for something @ejgallego and I discussed in the past as an alternative to using dune coq top for editors. We generate one _CoqProject file for each coq.theory stanza, which should allow good support across editors for stepping through Coq/Rocq source files.

This is incompatible with the following features, which I see as non-essential (i.e., could be removed IMO):

  • Having more than one coq.theory stanza in a given directory.
  • Using per-module flags in a coq.theory stanza.

If we want to push this through, we might want a way to disable generation of _CoqProject by supporting something like (project_file false) in the coq.theory stanza.

rlepigre avatar May 04 '25 12:05 rlepigre

@ejgallego any chance you could take a look at this?

rlepigre avatar Jun 17 '25 21:06 rlepigre

Yes @rlepigre , I'm almost at the point I will resume work on Dune Rocq; thanks for your patience.

ejgallego avatar Jun 18 '25 17:06 ejgallego

Looks pretty good to me, I have some minor comments, but I suggest to add a changelog and documentation, as I can fix the comments myself.

ejgallego avatar Jun 18 '25 17:06 ejgallego

@ejgallego I added a changelog, but let's wait until we decide how to address the issues I raised in the description of the PR. I'd love to hear your take on these.

rlepigre avatar Jul 05 '25 21:07 rlepigre

This is a proof of concept for something @ejgallego and I discussed in the past as an alternative to using dune coq top for editors.

I guess another alternative would be to have dune coq have some "tell me the flags in a machine readable way" subcommand and teach IDEs to use that.

SkySkimmer avatar Jul 07 '25 11:07 SkySkimmer

I guess another alternative would be to have dune coq have some "tell me the flags in a machine readable way" subcommand and teach IDEs to use that.

That already exists: dune coq top (and its --toplevel argument). You can pass it a "fake toplevel" that spits out the arguments it receives in any format you like.

However, I never managed to get help to integrate support in editors, and in particular in PG (see here).

rlepigre avatar Jul 07 '25 19:07 rlepigre

Having the "fake toplevel" builtin sounds like it would make it much easier to use for IDEs.

SkySkimmer avatar Jul 07 '25 19:07 SkySkimmer

Having the "fake toplevel" builtin sounds like it would make it much easier to use for IDEs.

How so?

Editors would have to:

  1. Run something like dune coq top --no-build --toplevel fake-toplevel path/to/file.v > /tmp/flags.
  2. Run the appropriate toplevel using the flags of /tmp/flags.

The currently possible alternative is to just run dune coq top --no-build --toplevel whatever path/to/file.v.

rlepigre avatar Jul 07 '25 21:07 rlepigre

@ejgallego I added a changelog, but let's wait until we decide how to address the issues I raised in the description of the PR. I'd love to hear your take on these.

I think it is fine to fail in both cases, tho we may want to have a better error message, right?

What's your take on those? The way I see this patch, it is mostly for backwards compatibility, at some point editors should try to understand dune files directly. I guess we should try to add dune-project support to coq-lsp soon.

Something that is not clear to me if we need to install _CoqProject files?

ejgallego avatar Jul 09 '25 14:07 ejgallego

Some IDEs share the process between multiple files, so they do need to extract arguments and don't want to just start a fresh toplevel.

SkySkimmer avatar Jul 14 '25 12:07 SkySkimmer

@Alizter @ejgallego I think this is now in a very reasonable state, since the feature is now opt-in. Hopefully we can get this in quickly.

rlepigre avatar Nov 14 '25 21:11 rlepigre

CI failures look spurious.

rlepigre avatar Nov 15 '25 20:11 rlepigre

Thanks @Alizter!

rlepigre avatar Nov 16 '25 12:11 rlepigre