-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6bd943e
Addresses michealpj's pr comments
joyfulmantis e9b2661
Move Types.hs changes to general-resolve-improvements branch
joyfulmantis 149263e
Merge branch 'master' into hlint-suggestions
joyfulmantis e161988
Merge branch 'master' into hlint-suggestions
michaelpj 92155ee
Merge branch 'master' into hlint-suggestions
joyfulmantis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ | |
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE StrictData #-} | ||
{-# LANGUAGE TupleSections #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
|
||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
-- On 9.4 we get a new redundant constraint warning, but deleting the | ||
|
@@ -423,7 +423,7 @@ codeActionProvider ideState _pluginId (CodeActionParams _ _ documentId _ context | |
|
||
where | ||
applyAllAction verTxtDocId = | ||
let args = Just $ toJSON (AA verTxtDocId) | ||
let args = Just $ toJSON (ApplyHint verTxtDocId Nothing) | ||
in LSP.CodeAction "Apply all hints" (Just LSP.CodeActionKind_QuickFix) Nothing Nothing Nothing Nothing Nothing args | ||
|
||
-- |Some hints do not have an associated refactoring | ||
|
@@ -435,23 +435,21 @@ codeActionProvider ideState _pluginId (CodeActionParams _ _ documentId _ context | |
diags = context ^. LSP.diagnostics | ||
|
||
resolveProvider :: Recorder (WithPriority Log) -> PluginMethodHandler IdeState Method_CodeActionResolve | ||
resolveProvider recorder ideState _pluginId ca@CodeAction {_data_ = Just data_} = pluginResponse $ do | ||
case fromJSON data_ of | ||
(Success (AA verTxtDocId@(VersionedTextDocumentIdentifier uri _))) -> do | ||
file <- getNormalizedFilePath uri | ||
edit <- ExceptT $ liftIO $ applyHint recorder ideState file Nothing verTxtDocId | ||
pure $ ca & LSP.edit ?~ edit | ||
(Success (AO verTxtDocId@(VersionedTextDocumentIdentifier uri _) pos hintTitle)) -> do | ||
let oneHint = OneHint pos hintTitle | ||
file <- getNormalizedFilePath uri | ||
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) | ||
edit <- ExceptT $ liftIO $ applyHint recorder ideState file oneHint verTxtDocId | ||
pure $ ca & LSP.edit ?~ edit | ||
(Success (IH verTxtDocId@(VersionedTextDocumentIdentifier uri _) hintTitle )) -> do | ||
file <- getNormalizedFilePath uri | ||
resolveProvider recorder ideState _ | ||
ca@CodeAction {_data_ = Just (fromJSON -> (Success (IgnoreHint verTxtDocId hintTitle)))} = pluginResponse $ do | ||
file <- getNormalizedFilePath (verTxtDocId ^. LSP.uri) | ||
edit <- ExceptT $ liftIO $ ignoreHint recorder ideState file verTxtDocId hintTitle | ||
pure $ ca & LSP.edit ?~ edit | ||
Error s-> throwE ("JSON decoding error: " <> s) | ||
resolveProvider _ _ _ _ = pluginResponse $ throwE "CodeAction with no data field" | ||
resolveProvider _ _ _ | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as the other PR, throw the |
||
|
||
-- | Convert a hlint diagnostic into an apply and an ignore code action | ||
-- if applicable | ||
|
@@ -461,13 +459,13 @@ diagnosticToCodeActions verTxtDocId diagnostic | |
, let isHintApplicable = "refact:" `T.isPrefixOf` code | ||
, let hint = T.replace "refact:" "" code | ||
, let suppressHintTitle = "Ignore hint \"" <> hint <> "\" in this module" | ||
, let suppressHintArguments = IH verTxtDocId hint | ||
, let suppressHintArguments = IgnoreHint verTxtDocId hint | ||
= catMaybes | ||
-- Applying the hint is marked preferred because it addresses the underlying error. | ||
-- Disabling the rule isn't, because less often used and configuration can be adapted. | ||
[ if | isHintApplicable | ||
, let applyHintTitle = "Apply hint \"" <> hint <> "\"" | ||
applyHintArguments = AO verTxtDocId start hint -> | ||
applyHintArguments = ApplyHint verTxtDocId (Just $ OneHint start hint) -> | ||
Just (mkCodeAction applyHintTitle diagnostic (Just (toJSON applyHintArguments)) True) | ||
| otherwise -> Nothing | ||
, Just (mkCodeAction suppressHintTitle diagnostic (Just (toJSON suppressHintArguments)) False) | ||
|
@@ -525,22 +523,25 @@ ignoreHint _recorder ideState nfp verTxtDocId ignoreHintTitle = do | |
Nothing -> pure $ Left "Unable to get fileContents" | ||
|
||
-- --------------------------------------------------------------------- | ||
data HlintResolveCommands = AA { verTxtDocId :: VersionedTextDocumentIdentifier} | ||
| AO { verTxtDocId :: VersionedTextDocumentIdentifier | ||
, start_pos :: Position | ||
-- | There can be more than one hint suggested at the same position, so HintTitle is used to distinguish between them. | ||
, hintTitle :: HintTitle | ||
} | ||
| IH { verTxtDocId :: VersionedTextDocumentIdentifier | ||
, ignoreHintTitle :: HintTitle | ||
} deriving (Generic, ToJSON, FromJSON) | ||
data HlintResolveCommands = | ||
ApplyHint | ||
{ verTxtDocId :: VersionedTextDocumentIdentifier | ||
-- |If Nothing, apply all hints, otherise only apply | ||
-- the given hint | ||
, oneHint :: Maybe OneHint | ||
} | ||
| IgnoreHint | ||
{ verTxtDocId :: VersionedTextDocumentIdentifier | ||
, ignoreHintTitle :: HintTitle | ||
} deriving (Generic, ToJSON, FromJSON) | ||
|
||
type HintTitle = T.Text | ||
|
||
data OneHint = OneHint | ||
{ oneHintPos :: Position | ||
, oneHintTitle :: HintTitle | ||
} deriving (Eq, Show) | ||
data OneHint = | ||
OneHint | ||
{ oneHintPos :: Position | ||
, oneHintTitle :: HintTitle | ||
} deriving (Generic, Eq, Show, ToJSON, FromJSON) | ||
|
||
applyHint :: Recorder (WithPriority Log) -> IdeState -> NormalizedFilePath -> Maybe OneHint -> VersionedTextDocumentIdentifier -> IO (Either String WorkspaceEdit) | ||
applyHint recorder ide nfp mhint verTxtDocId = | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.This stuff is a bit nitpicky but I think it's usually worth it
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.