Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Code lens for missing signatures #224

Merged
merged 3 commits into from
Dec 9, 2019
Merged

Conversation

serras
Copy link
Contributor

@serras serras commented Dec 7, 2019

This PR adds code lenses for missing type signatures, as discussed in #88. Missing type signatures appear as comments on top of the start of the definition, as shown in this image. When the user clicks on the definition, it's added to the source code.

Unfortunately, the specification of code lenses is not as straightforward as code actions. Instead of returning how to edit the file directly, we need to return an identifier with a command, which is then called when the user clicks on the code lens. That command does not return what to do either, instead it may request things from the client by using a server request. Hence the need for a new type of response in WithMessage, with both the response to the request and an optional user request. This new constructor might be merged with withResponse, but I didn't take that step; let me know if you prefer me to do so.

@cocreature
Copy link
Collaborator

Thanks for the contribution! I haven’t yet tried playing around with this so excuse my ignorance but I’m a bit confused how this relates to the code action that we already have since #81. I thought that already gives you a quickfix button for inserting signatures. Does this only provide a slightly different UX for the same thing or is there something else?

@serras
Copy link
Contributor Author

serras commented Dec 7, 2019 via email

Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Looks good to me with some minor comments, thanks a lot!

I’m slightly worried that we’ll end up duplicating all quickfix hints as codelenses at some point because different people prefer different interfaces. Do you have some intuition on which hints make sense as codelenses and which don’t? Personally, I don’t really see why a codelens is a better interface here than a quickfix which seems like it’s exactly meant for this kind of usecase. Given that the change is fairly small and shares most of the code, I’m happy to add it for now either way but I’m curious about how we should make this decision for similar hints.

src/Development/IDE/LSP/LanguageServer.hs Show resolved Hide resolved
src/Development/IDE/LSP/LanguageServer.hs Outdated Show resolved Hide resolved
src/Development/IDE/LSP/LanguageServer.hs Show resolved Hide resolved
@ocharles
Copy link
Contributor

ocharles commented Dec 8, 2019 via email

@ndmitchell
Copy link
Collaborator

My view is that this change is really about surfacing information to the user about the top level signature. It's also a way to insert it back into the program, but that's a minor part. As such, it's quite different from other fixes.

@cocreature
Copy link
Collaborator

@ocharles The title of the quickfix includes the signature as well, see https://github.com/digital-asset/ghcide/blob/5091a1d2021f89f2b4209d498144b061c1ea7e95/src/Development/IDE/LSP/CodeAction.hs#L150

@ndmitchell Yeah although as mentioned above both the quickfix and the codelens surface the information. It’s a bit more visible with the codelens but that’s fairly specific to how VSCode displays codelenses and quickfixes. There is nothing stopping an editor from displaying quickfixes inline.

@serras
Copy link
Contributor Author

serras commented Dec 8, 2019

One possibility is to remove "add signature" from the code lens (but not from the quick fix). That way it looks like the missing type signature had been "added" to the source code, sort of what @ndmitchell said above (in fact, that was my original goal, it just turned out that code lenses require a command, which led naturally to adding the signature when clicked).

@cocreature my opinion is that no more quick fixes should be turned into code lenses. However, I think the way they are designed is a perfect fit for missing type signatures, since we can show the signature exactly where you would write it on code (at least in VS Code), and it's some sort of "comment" over your code. There's more room, however, to show some additional information about the code as lenses, but that's the topic of another issue.

@serras
Copy link
Contributor Author

serras commented Dec 8, 2019

@cocreature I have implemented your suggestions in the latest commit.

I have also changed the UI for the code lens, so that it only shows the missing type signature, and not the "add signature" text. That makes it look more like a "comment" over the code, rather than a quick fix.

Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@cocreature cocreature merged commit 7f3b0f6 into haskell:master Dec 9, 2019
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Code lens for missing signatures

* Fix tests

* Implement suggestions by @cocreature
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Code lens for missing signatures

* Fix tests

* Implement suggestions by @cocreature
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Code lens for missing signatures

* Fix tests

* Implement suggestions by @cocreature
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants