File tree 3 files changed +28
-4
lines changed
plugins/hls-hlint-plugin/src/Ide/Plugin
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
286
286
where
287
287
288
288
getCodeActions = do
289
- diags <- getDiagnostics ideState
289
+ allDiags <- getDiagnostics ideState
290
290
let docNfp = toNormalizedFilePath' <$> uriToFilePath' (docId ^. LSP. uri)
291
291
numHintsInDoc = length
292
- [d | (nfp, _, d) <- diags
292
+ [d | (nfp, _, d) <- allDiags
293
293
, validCommand d
294
294
, Just nfp == docNfp
295
295
]
296
+ numHintsInContext = length
297
+ [d | d <- diags
298
+ , validCommand d
299
+ ]
296
300
-- 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
299
304
pure $ applyAllAction: applyOneActions
300
305
else
301
306
pure applyOneActions
Original file line number Diff line number Diff line change @@ -163,6 +163,22 @@ hlintTests = testGroup "hlint suggestions" [
163
163
164
164
, testCase " apply-refact preserve regular comments" $ runHlintSession " " $ do
165
165
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"
166
182
]
167
183
where
168
184
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