Skip to content
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

jump to definition #214

Closed
gares opened this issue Mar 12, 2021 · 7 comments
Closed

jump to definition #214

gares opened this issue Mar 12, 2021 · 7 comments
Labels
Coq requires a patch to Coq Document Manager Cf https://github.com/coq-community/vscoq/projects/1

Comments

@gares
Copy link
Member

gares commented Mar 12, 2021

we need a libobject which populates a map kername -> loc (where loc contains a file name relative to the logical path)

mathcomp.ssreflect.ssrnat.len -> mathcomp.ssreflect + ssrnat.v + loc
Coq.Init.Peano.le -> Coq.Init + Peano.v + loc

The one asks Coq where the logpath is mapped from, eg mathcomp.ssreflect -> $coqlib/user-contribs/mathcomp/ssreflect/, and the can generate the link file:///$coqlib/user-contribs/mathcomp/ssreflect/ssrnat.v

The libobject should be a bit down, since we also need to get links to generated stuff, eg foo_rect (and point to Inductive foo).

In response to the request
https://microsoft.github.io/language-server-protocol/specification#textDocument_declaration
one (re)globalized the AST we have in the document module, gets the kernel name, looks it up in the map, and generates the link.
It is not always possible to "globalize" a vernac, since sometimes (eg Inductive/Record) it is messed up with interpretation.
Possibilities:

  • do it easy when possible, support only some sentences, eg Definition and Theorem and tactic
  • have ad-hoc globalization code for inductive (take it from Coq-Elpi) and see if it can be pushed back upstream or not
  • do the coqdoc hack: re-run the sentence logging 'loc -> kername' (dumpglob supports streaming to a non-file, IIRC). This has the nice effect of workings in all cases, but can be more expensive, and suffers from the ltac repeat t returning a gazillion of hits
@gares gares added Document Manager Cf https://github.com/coq-community/vscoq/projects/1 Coq requires a patch to Coq labels Mar 12, 2021
@SkySkimmer
Copy link
Contributor

Is there a way to get the current loc from declare-ish?

Then one asks Coq where the logpath is mapped from

That's not necessarily unique, we should ask where the file is mapped from instead
(you can have -Q foo1 foo -Q foo2 foo and then foo.bar may be foo1/bar.v or foo2/bar.v)

For functors

Module F(A:T). 
Definition bla := ...
End F.
Module M := F X.

looking up M.bla should point to line 2 (Defininition ...) IMO
To do this we keep DirPath.t * Loc.t

If we want to have an additional pointer to the Module := line we would need to do something at functor application too, not sure how easy that is.

@gares
Copy link
Member Author

gares commented Apr 16, 2021

I did some "experiments" with this idea in Coq-Elpi (using a few hacks on top of 8.13).
Since coq/coq#13844 is merged commands get their loc in input, and could store a libobject which for example links one or more GlobRef.t to that loc.

This is what I could get in the context of the HB.about math-comp/hierarchy-builder#227 command:

Screenshot from 2021-04-16 14-50-00

IMO, at least for the easy case of Definition/Lemma and Inductive, we can try to add this libobject. WDYT @SkySkimmer ?

@SkySkimmer
Copy link
Contributor

IMO, at least for the easy case of Definition/Lemma and Inductive, we can try to add this libobject. WDYT @SkySkimmer ?

It makes sense to me.

I guess you used Loc.t so there are the same limitations with relocated / installed files as Jim had for the ltac debugger.

Proof of concept: coq/coq@3f02b36 (note that the test suite output/ rewrites all filenames to "stdin" for some reason)

@RalfJung
Copy link

This would help a lot to get vscoq on par with what is typically expected in a modern IDE. :)

AFAIK there are ways to get jump-to-definition in emacs with Company Coq, or did I imagine that? Could vscoq use the same approach for this?

@gares
Copy link
Member Author

gares commented Sep 10, 2024

Iirc there is a way to open the file, and maybe there is code already for that. Going to the correct line requires some work, even if the outline (on the left panel) can jump to any definition within the same file.

@Dontrian
Copy link

I am following the software foundation books right now and have to say that being able to jump to a definition/lemma would be great. There are often multiple consecutive definitions of the same thing (in different modules) for teaching purposes and being able to quickly jump to the one referenced (and thus also the related theorems that are defined around it) would be very useful. It is also kind of an expected feature in modern IDEs, as mentionned above.

@rtetley
Copy link
Collaborator

rtetley commented Jan 17, 2025

This was closed by #911

@rtetley rtetley closed this as completed Jan 17, 2025
@rtetley rtetley added this to the Road map star issues milestone Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Coq requires a patch to Coq Document Manager Cf https://github.com/coq-community/vscoq/projects/1
Projects
None yet
Development

No branches or pull requests

5 participants