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

Support for resolve for class-plugin lenses #3769

Merged
merged 8 commits into from
Sep 1, 2023

Conversation

joyfulmantis
Copy link
Collaborator

@joyfulmantis joyfulmantis commented Aug 21, 2023

This PR only changes the lenses in the class plugin to rely on resolve. I'm unsure of the benefit of doing the same for the code actions. The resolve was implemented by moving the logic from the code lens method to a separate rule, and then relying on that for the code lens method, the code lens resolve method, and the command.

@joyfulmantis joyfulmantis marked this pull request as ready for review August 23, 2023 11:30
@joyfulmantis joyfulmantis changed the title WIP Initial support for resolve for class-plugin lenses Support for resolve for class-plugin lenses Aug 23, 2023
Copy link
Collaborator

@July541 July541 left a comment

Choose a reason for hiding this comment

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

Not familiar with the resolve, but vote 👍 since you are working on this continuously.

codeLens = makeLens <$> mapMaybe getRangeWithSig targetSigs

pure $ InL codeLens
(InstanceBindLensResult (InstanceBindLens{lensRendered}), _)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we are doing the same thing that codeLens did, do we really need this duplication?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All three methods: the code lens, the code lens resolve, and the command handler rely on the same rule. However, we extract different data from the rule. For the first code lens handler, we only return the range of each code lens and a unique ID that allows us to resolve it later. To resolve the lens we match the unique ID the client sends us to the text edit of the lens (this allows us to extract the title). Finally, for the command, we actually generate a correct textEdit with position mapping properly adjusted and use that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I should add that, the code lens method tends to be called with every file update (a lot). The resolve method gets called for each visible lens. Finally, the command only gets called when someone wants to apply a lens (compared to the other two methods practically never)

Copy link
Collaborator

Choose a reason for hiding this comment

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

My point is about the action, we are calling the same classplugin.GetInstanceBindLens action for different functions, not sure if we can omit some calls, but overall this is good enough now.

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.

Couple of high-level worries

plugins/hls-class-plugin/src/Ide/Plugin/Class/Types.hs Outdated Show resolved Hide resolved
getInstanceBindLensRule recorder = do
defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \GetInstanceBindLens nfp -> runMaybeT $ do
tmr@(tmrRenamed -> (hs_tyclds -> tycls, _, _, _)) <- useMT TypeCheck nfp
(InstanceBindTypeSigsResult allBinds) <- useMT GetInstanceBindTypeSigs nfp
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the only place this rule is called... so is there any reason not to just inline the logic here???

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is used also for code actions, hence the need to create a seperate rule for lens specific stuff.

@joyfulmantis joyfulmantis merged commit 645bb34 into haskell:master Sep 1, 2023
18 of 21 checks passed
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