File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed
plugins/hls-hlint-plugin/src/Ide/Plugin Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -286,16 +286,21 @@ codeActionProvider ideState plId (CodeActionParams _ _ docId _ context) = Right
286286 where
287287
288288 getCodeActions = do
289- diags <- getDiagnostics ideState
289+ allDiags <- getDiagnostics ideState
290290 let docNfp = toNormalizedFilePath' <$> uriToFilePath' (docId ^. LSP. uri)
291291 numHintsInDoc = length
292- [d | (nfp, _, d) <- diags
292+ [d | (nfp, _, d) <- allDiags
293293 , validCommand d
294294 , Just nfp == docNfp
295295 ]
296+ numHintsInContext = length
297+ [d | d <- diags
298+ , validCommand d
299+ ]
296300 -- We only want to show the applyAll code action if there is more than 1
297- -- hint in the current document
298- if numHintsInDoc > 1 then do
301+ -- hint in the current document and if code action range contains at
302+ -- least one hint
303+ if numHintsInDoc > 1 && numHintsInContext > 0 then do
299304 pure $ applyAllAction: applyOneActions
300305 else
301306 pure applyOneActions
Original file line number Diff line number Diff line change @@ -163,6 +163,22 @@ hlintTests = testGroup "hlint suggestions" [
163163
164164 , testCase " apply-refact preserve regular comments" $ runHlintSession " " $ do
165165 testRefactor " ApplyRefact6.hs" " Redundant bracket" expectedComments
166+
167+ , testCase " applyAll is shown only when there is at least one diagnostic in range" $ runHlintSession " " $ do
168+ doc <- openDoc " ApplyRefact8.hs" " haskell"
169+ _ <- waitForDiagnosticsFromSource doc " hlint"
170+
171+ firstLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 0 0 )
172+ secondLine <- map fromAction <$> getCodeActions doc (mkRange 1 0 1 0 )
173+ thirdLine <- map fromAction <$> getCodeActions doc (mkRange 2 0 2 0 )
174+ multiLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 2 0 )
175+
176+ let hasApplyAll = isJust . find (\ ca -> " Apply all hints" `T.isSuffixOf` (ca ^. L. title))
177+
178+ liftIO $ hasApplyAll firstLine @? " Missing apply all code action"
179+ liftIO $ hasApplyAll secondLine @? " Missing apply all code action"
180+ liftIO $ not (hasApplyAll thirdLine) @? " Unexpected apply all code action"
181+ liftIO $ hasApplyAll multiLine @? " Missing apply all code action"
166182 ]
167183 where
168184 runHlintSession :: FilePath -> Session a -> IO a
Original file line number Diff line number Diff line change 1+ f = (1 )
2+ g = (1 )
3+
You can’t perform that action at this time.
0 commit comments