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

Make go-to-definition on a typeclass projection application go to the instance(s) #1767

Merged
merged 25 commits into from
Jan 19, 2023

Conversation

rish987
Copy link
Contributor

@rish987 rish987 commented Oct 22, 2022

Closes #1722, pending #1903.

@rish987 rish987 force-pushed the go-to-instance branch 2 times, most recently from ba85f34 to e06e665 Compare October 22, 2022 03:32
@rish987
Copy link
Contributor Author

rish987 commented Oct 23, 2022

Hmm the CI test failures are puzzling me (it looks like they're still not getting the instance locations for some reason), because everything passes locally when I do:

$ ./test_single.sh {goTo,goto2}.lean

@Kha
Copy link
Member

Kha commented Oct 23, 2022

The interactive tests are not designed for referencing core files in their output. Either you'll need to change the existing tests not to reference core instances, or we implement something in the vein of #1722 (comment) that would prevent these tests from showing instances.

@leodemoura
Copy link
Member

@rish987 Today we were discussing this PR in the dev meeting. Could you please clarify the semantics you are implementing?

@rish987
Copy link
Contributor Author

rish987 commented Oct 24, 2022

Sure, I was trying to follow what Sebastian described here, basically, on go-to-definition or go-to-type if we get an Info node that represents an application of a typeclass projection, rather than going to the syntax or elaborator, we extract all of the relevant instances and present that in a list. I've also included the elaborator in this list because you were originally only able to get to that through go-to-definition (the syntax is still accessible as before through go-to-declaration).

I think I may need some help with the tests though (I blindly copied over expected outputs that I just noticed include URIs on my local filesystem 😰 so of course it won't work). Perhaps we need some additional filtering to preserve existing behavior (and some new tests as well to specifically test the new functionality), I was discussing this with @Kha yesterday and it sounded like he had an idea regarding that?

@Kha
Copy link
Member

Kha commented Oct 25, 2022

Right, the fundamental issue is that when looking at the typeclass method call Expr, we don't know if this info node was responsible for the TC synthesis, and thus whether original/canonical syntax was responsible for it. What I proposed to Rish is to simply whitelist syntax that we know does this, e.g. i.stx.isOfKind identKind || i.stx.isOfKind ``Parser.Term.app and probably others as well. A different, probably more general heuristic would be to check if no nested info node contains the same Expr (making use of the tree structure of the info tree, heh).

@rish987 rish987 marked this pull request as draft October 29, 2022 01:18
@Kha Kha mentioned this pull request Dec 1, 2022
@rish987 rish987 marked this pull request as ready for review December 13, 2022 03:06
@rish987
Copy link
Contributor Author

rish987 commented Dec 13, 2022

Okay this should finally be ready! I've merged in #1903 so it depends on that PR being merged first.

@rish987 rish987 closed this Dec 13, 2022
@rish987
Copy link
Contributor Author

rish987 commented Dec 13, 2022

Whoops, didn't mean to close it!

@rish987 rish987 reopened this Dec 13, 2022
Copy link
Member

@Kha Kha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great all in all!

src/Lean/Server/FileWorker/RequestHandling.lean Outdated Show resolved Hide resolved
src/Lean/Server/FileWorker/RequestHandling.lean Outdated Show resolved Hide resolved
src/Lean/Server/FileWorker/RequestHandling.lean Outdated Show resolved Hide resolved
src/Lean/Server/FileWorker/RequestHandling.lean Outdated Show resolved Hide resolved
src/Lean/Server/FileWorker/RequestHandling.lean Outdated Show resolved Hide resolved
src/Lean/Server/FileWorker/RequestHandling.lean Outdated Show resolved Hide resolved
src/Lean/Server/InfoUtils.lean Outdated Show resolved Hide resolved
src/Lean/Server/InfoUtils.lean Outdated Show resolved Hide resolved
Comment on lines 18 to 22
structure InfoWithCtx where
ctx : Elab.ContextInfo
info : Elab.Info
children : PersistentArray InfoTree
deriving Inhabited, TypeName
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to InfoUtils and use it in hoverableInfoAt? and locationLinksOfInfo etc. The deriving TypeName should probably be left here though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, let me know what you think of the refactor.

Copy link
Member

@Vtec234 Vtec234 Jan 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry to only comment on this now but InfoWithCtx is only really intended for use as a way of bundling data together in the RPC protocol so that interactive expressions and go-to-def in the infoview work. As Gabriel put it, it's a kind of "type popup + go-to-def thunk". Unless you need to do something with RPC here, it would be better not to move it and to add another type with whatever semantics you need instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicating it wouldn't be hard, but since the type is opaque in the RPC protocol I'm not really seeing the motivation. It's a sensible bundle of data to have in the server in general, and the name fits as well. Even if we don't necessarily need children in the widgets.

Copy link
Member

@Vtec234 Vtec234 Jan 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type seems like a better fit for Elab.InfoTree, if anything, because it was already hacky as far as the RPC interface is concerned — the outputs of delaboration are Elab.Infos but they should really be a much more restricted Delab.Info without variants like .ofCompletion. But okay, since InfoWithCtx is opaque we can always keep it around for uses such as in this PR but replace it with something else in the RPC interface. Btw @rish987 you probably want to also make the output of hoverableInfoAt? and termGoalAt? be InfoWithCtx, document what the children field is, and change the docstring to note that it's used for more than just RPC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for the suggestions.

@Kha Kha changed the title feat: make go-to-definition on a typeclass projection application go to the instance(s) Make go-to-definition on a typeclass projection application go to the instance(s) Dec 13, 2022
@Kha Kha added the changelog label Dec 13, 2022
@rish987 rish987 force-pushed the go-to-instance branch 2 times, most recently from 6527820 to acf4acb Compare January 3, 2023 04:09
@rish987 rish987 force-pushed the go-to-instance branch 3 times, most recently from aca714d to 9ebb657 Compare January 3, 2023 04:18
@rish987 rish987 marked this pull request as draft January 16, 2023 23:41
@rish987 rish987 marked this pull request as ready for review January 19, 2023 02:21
@rish987 rish987 requested a review from Kha January 19, 2023 02:21
@Kha Kha enabled auto-merge (squash) January 19, 2023 08:05
@Kha Kha merged commit 561e404 into leanprover:master Jan 19, 2023
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.

Go-to-definition on typeclass method should go to instance
4 participants