File tree 3 files changed +24
-4
lines changed
plugins/hls-hlint-plugin/src/Ide/Plugin
3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -268,20 +268,21 @@ getHlintSettingsRule usage =
268
268
-- ---------------------------------------------------------------------
269
269
270
270
codeActionProvider :: PluginMethodHandler IdeState TextDocumentCodeAction
271
- codeActionProvider ideState plId (CodeActionParams _ _ docId _ context) = Right . LSP. List . map InR <$> liftIO getCodeActions
271
+ codeActionProvider ideState plId (CodeActionParams _ _ docId caRange context) = Right . LSP. List . map InR <$> liftIO getCodeActions
272
272
where
273
273
274
274
getCodeActions = do
275
275
diags <- getDiagnostics ideState
276
276
let docNfp = toNormalizedFilePath' <$> uriToFilePath' (docId ^. LSP. uri)
277
- numHintsInDoc = length
278
- [d | (nfp, _, d) <- diags
277
+ numHintsInRange = length
278
+ [d | (nfp, _, d@ LSP. Diagnostic {_range = range} ) <- diags
279
279
, validCommand d
280
280
, Just nfp == docNfp
281
+ , subRange range caRange
281
282
]
282
283
-- We only want to show the applyAll code action if there is more than 1
283
284
-- hint in the current document
284
- if numHintsInDoc > 1 then do
285
+ if numHintsInRange > 1 then do
285
286
pure $ applyAllAction: applyOneActions
286
287
else
287
288
pure applyOneActions
Original file line number Diff line number Diff line change @@ -170,6 +170,22 @@ hlintTests = testGroup "hlint suggestions" [
170
170
171
171
, testCase " apply-refact preserve regular comments" $ runHlintSession " " $ do
172
172
testRefactor " ApplyRefact6.hs" " Redundant bracket" expectedComments
173
+
174
+ , testCase " applyAll is shown only when there is at least one diagnostic in range" $ runHlintSession " " $ do
175
+ doc <- openDoc " ApplyRefact7.hs" " haskell"
176
+ _ <- waitForDiagnosticsFromSource doc " hlint"
177
+
178
+ firstLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 0 0 )
179
+ secondLine <- map fromAction <$> getCodeActions doc (mkRange 1 0 1 0 )
180
+ thirdLine <- map fromAction <$> getCodeActions doc (mkRange 2 0 2 0 )
181
+ multiLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 2 0 )
182
+
183
+ let hasApplyAll = isJust . find (\ ca -> " Apply all hints" `T.isSuffixOf` (ca ^. L. title))
184
+
185
+ liftIO $ not (hasApplyAll firstLine) @? " There is no apply all code action"
186
+ liftIO $ not (hasApplyAll secondLine) @? " There is no apply all code action"
187
+ liftIO $ not (hasApplyAll thirdLine) @? " There is an apply all code action"
188
+ liftIO $ hasApplyAll multiLine @? " There is no apply all code action"
173
189
]
174
190
where
175
191
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