@@ -409,7 +409,7 @@ codeActionProvider ideState pluginId (CodeActionParams _ _ documentId _ context)
409
409
| let TextDocumentIdentifier uri = documentId
410
410
, Just docNormalizedFilePath <- uriToNormalizedFilePath (toNormalizedUri uri)
411
411
= do
412
- version <- ( ^. LSP. version) <$> getVersionedTextDoc documentId
412
+ verTxtDocId <- getVersionedTextDoc documentId
413
413
liftIO $ fmap (Right . LSP. List . map LSP. InR ) $ do
414
414
allDiagnostics <- atomically $ getDiagnostics ideState
415
415
@@ -429,19 +429,19 @@ codeActionProvider ideState pluginId (CodeActionParams _ _ documentId _ context)
429
429
pure if | Just modSummaryResult <- modSummaryResult
430
430
, Just source <- source
431
431
, let dynFlags = ms_hspp_opts $ msrModSummary modSummaryResult ->
432
- diags >>= diagnosticToCodeActions dynFlags source pluginId documentId version
432
+ diags >>= diagnosticToCodeActions dynFlags source pluginId verTxtDocId
433
433
| otherwise -> []
434
434
| otherwise -> pure []
435
435
if numHintsInDoc > 1 && numHintsInContext > 0 then do
436
- pure $ singleHintCodeActions ++ [applyAllAction version ]
436
+ pure $ singleHintCodeActions ++ [applyAllAction verTxtDocId ]
437
437
else
438
438
pure singleHintCodeActions
439
439
| otherwise
440
440
= pure $ Right $ LSP. List []
441
441
442
442
where
443
- applyAllAction version =
444
- let args = Just [toJSON (documentId ^. LSP. uri, version) ]
443
+ applyAllAction verTxtDocId =
444
+ let args = Just [toJSON verTxtDocId ]
445
445
cmd = mkLspCommand pluginId " applyAll" " Apply all hints" args
446
446
in LSP. CodeAction " Apply all hints" (Just LSP. CodeActionQuickFix ) Nothing Nothing Nothing Nothing (Just cmd) Nothing
447
447
@@ -455,25 +455,24 @@ codeActionProvider ideState pluginId (CodeActionParams _ _ documentId _ context)
455
455
456
456
-- | Convert a hlint diagnostic into an apply and an ignore code action
457
457
-- if applicable
458
- diagnosticToCodeActions :: DynFlags -> T. Text -> PluginId -> TextDocumentIdentifier -> TextDocumentVersion -> LSP. Diagnostic -> [LSP. CodeAction ]
459
- diagnosticToCodeActions dynFlags fileContents pluginId documentId version diagnostic
458
+ diagnosticToCodeActions :: DynFlags -> T. Text -> PluginId -> VersionedTextDocumentIdentifier -> LSP. Diagnostic -> [LSP. CodeAction ]
459
+ diagnosticToCodeActions dynFlags fileContents pluginId verTxtDocId diagnostic
460
460
| LSP. Diagnostic { _source = Just " hlint" , _code = Just (InR code), _range = LSP. Range start _ } <- diagnostic
461
- , let TextDocumentIdentifier uri = documentId
462
461
, let isHintApplicable = " refact:" `T.isPrefixOf` code
463
462
, let hint = T. replace " refact:" " " code
464
463
, let suppressHintTitle = " Ignore hint \" " <> hint <> " \" in this module"
465
464
, let suppressHintTextEdits = mkSuppressHintTextEdits dynFlags fileContents hint
466
465
, let suppressHintWorkspaceEdit =
467
466
LSP. WorkspaceEdit
468
- (Just (Map. singleton uri (List suppressHintTextEdits)))
467
+ (Just (Map. singleton (verTxtDocId ^. LSP. uri) (List suppressHintTextEdits)))
469
468
Nothing
470
469
Nothing
471
470
= catMaybes
472
471
-- Applying the hint is marked preferred because it addresses the underlying error.
473
472
-- Disabling the rule isn't, because less often used and configuration can be adapted.
474
473
[ if | isHintApplicable
475
474
, let applyHintTitle = " Apply hint \" " <> hint <> " \" "
476
- applyHintArguments = [toJSON (AOP (documentId ^. LSP. uri) start hint version )]
475
+ applyHintArguments = [toJSON (AOP verTxtDocId start hint)]
477
476
applyHintCommand = mkLspCommand pluginId " applyOne" applyHintTitle (Just applyHintArguments) ->
478
477
Just (mkCodeAction applyHintTitle diagnostic Nothing (Just applyHintCommand) True )
479
478
| otherwise -> Nothing
@@ -515,13 +514,13 @@ mkSuppressHintTextEdits dynFlags fileContents hint =
515
514
combinedTextEdit : lineSplitTextEditList
516
515
-- ---------------------------------------------------------------------
517
516
518
- applyAllCmd :: Recorder (WithPriority Log ) -> CommandFunction IdeState ( Uri , TextDocumentVersion )
519
- applyAllCmd recorder ide (uri, version) = do
520
- let file = maybe (error $ show uri ++ " is not a file." )
517
+ applyAllCmd :: Recorder (WithPriority Log ) -> CommandFunction IdeState VersionedTextDocumentIdentifier
518
+ applyAllCmd recorder ide verTxtDocId = do
519
+ let file = maybe (error $ show (verTxtDocId ^. LSP. uri) ++ " is not a file." )
521
520
toNormalizedFilePath'
522
- (uriToFilePath' uri)
521
+ (uriToFilePath' (verTxtDocId ^. LSP. uri) )
523
522
withIndefiniteProgress " Applying all hints" Cancellable $ do
524
- res <- liftIO $ applyHint recorder ide file Nothing version
523
+ res <- liftIO $ applyHint recorder ide file Nothing verTxtDocId
525
524
logWith recorder Debug $ LogApplying file res
526
525
case res of
527
526
Left err -> pure $ Left (responseError (T. pack $ " hlint:applyAll: " ++ show err))
@@ -532,11 +531,10 @@ applyAllCmd recorder ide (uri, version) = do
532
531
-- ---------------------------------------------------------------------
533
532
534
533
data ApplyOneParams = AOP
535
- { file :: Uri
534
+ { verTxtDocId :: VersionedTextDocumentIdentifier
536
535
, start_pos :: Position
537
536
-- | There can be more than one hint suggested at the same position, so HintTitle is used to distinguish between them.
538
537
, hintTitle :: HintTitle
539
- , textVersion :: TextDocumentVersion
540
538
} deriving (Eq ,Show ,Generic ,FromJSON ,ToJSON )
541
539
542
540
type HintTitle = T. Text
@@ -547,22 +545,22 @@ data OneHint = OneHint
547
545
} deriving (Eq , Show )
548
546
549
547
applyOneCmd :: Recorder (WithPriority Log ) -> CommandFunction IdeState ApplyOneParams
550
- applyOneCmd recorder ide (AOP uri pos title version ) = do
548
+ applyOneCmd recorder ide (AOP verTxtDocId pos title) = do
551
549
let oneHint = OneHint pos title
552
- let file = maybe (error $ show uri ++ " is not a file." ) toNormalizedFilePath'
553
- (uriToFilePath' uri)
550
+ let file = maybe (error $ show (verTxtDocId ^. LSP. uri) ++ " is not a file." ) toNormalizedFilePath'
551
+ (uriToFilePath' (verTxtDocId ^. LSP. uri) )
554
552
let progTitle = " Applying hint: " <> title
555
553
withIndefiniteProgress progTitle Cancellable $ do
556
- res <- liftIO $ applyHint recorder ide file (Just oneHint) version
554
+ res <- liftIO $ applyHint recorder ide file (Just oneHint) verTxtDocId
557
555
logWith recorder Debug $ LogApplying file res
558
556
case res of
559
557
Left err -> pure $ Left (responseError (T. pack $ " hlint:applyOne: " ++ show err))
560
558
Right fs -> do
561
559
_ <- sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing fs) (\ _ -> pure () )
562
560
pure $ Right Null
563
561
564
- applyHint :: Recorder (WithPriority Log ) -> IdeState -> NormalizedFilePath -> Maybe OneHint -> TextDocumentVersion -> IO (Either String WorkspaceEdit )
565
- applyHint recorder ide nfp mhint version =
562
+ applyHint :: Recorder (WithPriority Log ) -> IdeState -> NormalizedFilePath -> Maybe OneHint -> VersionedTextDocumentIdentifier -> IO (Either String WorkspaceEdit )
563
+ applyHint recorder ide nfp mhint verTxtDocId =
566
564
runExceptT $ do
567
565
let runAction' :: Action a -> IO a
568
566
runAction' = runAction " applyHint" ide
@@ -619,8 +617,7 @@ applyHint recorder ide nfp mhint version =
619
617
#endif
620
618
case res of
621
619
Right appliedFile -> do
622
- let uri = fromNormalizedUri (filePathToUri' nfp)
623
- let wsEdit = diffText' True (uri, oldContent) (T. pack appliedFile) IncludeDeletions version
620
+ let wsEdit = diffText' True (verTxtDocId, oldContent) (T. pack appliedFile) IncludeDeletions
624
621
ExceptT $ return (Right wsEdit)
625
622
Left err ->
626
623
throwE err
0 commit comments