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

Further hlint resolve changes. #3685

Merged
merged 5 commits into from
Jul 12, 2023

Conversation

joyfulmantis
Copy link
Collaborator

I missed some of michealpj's pr suggestions from last pr, so this pr addresses them.

@@ -1069,8 +1075,17 @@ mkCodeActionWithResolveAndCommand plId codeActionMethod codeResolveMethod =
-- resolve data type to allow the server to know who to send the resolve request to
supportsCodeActionResolve caps ->
pure $ InL (wrapCodeActionResolveData pid <$> ls)
-- If they do not we will drop the data field, in addition we will populate the command
-- field with our command to execute the resolve, with the whole code action as it's argument.
{- Note [Code action resolve fallback to commands]
Copy link
Collaborator

Choose a reason for hiding this comment

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

the note convention is generally to put these at the top level (so they're easier to read) and at the end of the file

-- pas it to the resolve handler (which expects a whole code action)
-- pass it to the resolve handler (which expects a whole code action)
-- It should be noted that mkLspCommand already specifies the command
-- to the plugin, so we don't need to do that here.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
-- to the plugin, so we don't need to do that here.
-- to the plugin, so we don't need to do that here and can just use the same command name

, ca ^. L.command == _command
, ca ^. L.isPreferred == _isPreferred
, ca ^. L.data_ == _data_
, ca ^. L.disabled == _disabled -> do
Copy link
Collaborator

Choose a reason for hiding this comment

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

lol, this is kind of annoying. I guess there isn't a super easy way to check if two records are the same except for a specific field. One thing we could do is define a helper in lsp-types or similar:

checkCodeActionResolveFields :: [Text] -> CodeAction -> CodeAction -> Maybe Text

i.e. something that takes the set of client-allowed updateable fields, the two code actions, and either passes or gives you a helpful error. Then that's just exactly the thing everyone will need.

, ca ^. L.disabled == _disabled -> do
_ <- sendRequest SMethod_WorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wedits) (\_ -> pure ())
pure $ Right Data.Aeson.Null
| otherwise -> pure $ Left $ responseError "CodeAction fields beside edit changed during resolve"
Copy link
Collaborator

Choose a reason for hiding this comment

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

e.g. it would be nice to say which one! And maybe even include the two code actions. This is all very much bonus points and it all seems pointless... until someone reports a bug with one of the errors, and then you're always grateful to have the detail!

CodeAction {_data_ = Just (fromJSON @HlintResolveCommands -> (Error (T.pack -> str)))} =
pure $ Left $ ResponseError (InR ErrorCodes_ParseError) str Nothing
resolveProvider _ _ _ CodeAction {_data_ = _} =
pure $ Left $ ResponseError (InR ErrorCodes_InvalidParams) "Unexpected argument for code action resolve handler: (Probably Nothing)" Nothing
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment as the other PR, throw the Value in the error

edit <- ExceptT $ liftIO $ applyHint recorder ideState file (Just oneHint) verTxtDocId
resolveProvider recorder ideState _
ca@CodeAction {_data_ = Just (fromJSON -> (Success (ApplyHint verTxtDocId oneHint)))} = pluginResponse $ do
file <- getNormalizedFilePath (verTxtDocId ^. LSP.uri)
Copy link
Collaborator

Choose a reason for hiding this comment

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

again, for minor deduplication, I'd be tempted to do just the pattern match on the HlintResolveCommands later, i.e.

... fromJson -> command) = pluginResponse $ do
  file <- getNormalizedFilePath ...
  edit <- case command of ...
  pure $ ca & LSP.edit ?~ edit

This stuff is a bit nitpicky but I think it's usually worth it

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 reason why we can't is because we need the uri to do anything useful, and that's encoded in the data. I'm gonna try and see if I can model resolve provider infrastructure on what we have for commands. That way hls core can do the json decoding and also store a uri to pass on to the handlers for us to use right away.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah right, I see. Yeah, maybe that's natural. But then again maybe we should leave this stuff up to plugins. Something like the URI you definitely always need though.

@joyfulmantis joyfulmantis added the merge me Label to trigger pull request merge label Jul 12, 2023
@joyfulmantis joyfulmantis enabled auto-merge (squash) July 12, 2023 13:09
@joyfulmantis joyfulmantis merged commit ea6850f into haskell:master Jul 12, 2023
40 of 42 checks passed
@fendor fendor mentioned this pull request Aug 8, 2023
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants