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 instance definition and explain typeclass evidence #4392

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented Aug 29, 2024

Rebased and slightly modified version of #1983

Still requires some tests and docs.

@fendor fendor changed the title Jump to instance definition and explain typeclass evidence for Jump to instance definition and explain typeclass evidence Aug 29, 2024
@fendor fendor force-pushed the fendor/wip/evidence-info branch 2 times, most recently from 0ccc4d3 to 5568ca3 Compare August 29, 2024 15:35
@michaelpj
Copy link
Collaborator

Just at a high level, am I right that if I have

foo :: Num x => x
foo  = 1

let x :: Int = foo

and I call "go to implementation" on "foo" I will get the option to go to the Num Int definition? i.e. not to the "implementation" of "foo" in any real sense. (It's probably still the right method to use, just thinking)

@fendor
Copy link
Collaborator Author

fendor commented Aug 29, 2024

Yes, that's exactly what will happen!

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Definitely needs some tests, it's not at all clear to me how it's going to show up.

ghcide/src/Development/IDE/LSP/HoverDefinition.hs Outdated Show resolved Hide resolved
-> Position
-> MaybeT m [(Location, Identifier)]
gotoDefinition withHieDb getHieFile ideOpts imports srcSpans pos
= lift $ locationsAtPoint withHieDb getHieFile ideOpts imports pos srcSpans

-- | Locate the implementation definition of the name at a given position.
-- Finds the implementation for a overloaded function.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can keep saying "gotoImplementation" and so on, since this corresponds to that LSP method, but let's make this comment clear about what it actually does!

ghcide/src/Development/IDE/Spans/AtPoint.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Spans/AtPoint.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Spans/AtPoint.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Spans/AtPoint.hs Outdated Show resolved Hide resolved
]
prettyName (Right n, dets)
-- We don't want to print evidence variables as they are generated.
| any isEvidenceUse (identInfo dets) = pure $ maybe "" (printOutputable . renderEvidenceTree) (getEvidenceTree rf n) <> "\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

the maybe "" seems supicious. What case is that for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The getEvidenceTree may return Nothing for a variety of reasons. For example, when the name is unexpectedly not found in the reference map. I think in practice, it will always produce something.

We could log it if we failed to build the EvidenceTree for a given name.

ghcide/src/Development/IDE/Spans/AtPoint.hs Outdated Show resolved Hide resolved
@@ -307,6 +331,39 @@ atPoint IdeOptions{} (HAR _ hf _ _ (kind :: HieKind hietype)) (DKMap dm km) env
UnhelpfulLoc {} | isInternalName name || isSystemName name -> Nothing
_ -> Just $ "*Defined " <> printOutputable (pprNameDefnLoc name) <> "*"

-- We want to render the root constraint even if it is a let,
-- but we don't want to render any subsequent lets
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm assuming this makes sense to someone who knows how evidence is represented in GHC...

@michaelpj
Copy link
Collaborator

Can we include a test to see whether this now gives us some kind of useful hover information on overloaded record dot usage?

Adds the necessary instances for handling the request type
`Method_TextDocumentImplementation`.
Further, wire up the appropriate handlers for the "gotoImplementation"
request.
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.

3 participants