@@ -122,12 +122,13 @@ rules = do
122
122
LSP. Diagnostic {
123
123
_range = srcSpanToRange $ ideaSpan idea
124
124
, _severity = Just LSP. DsInfo
125
- , _code = Just (LSP. StringValue $ T. pack $ ideaHint idea)
125
+ , _code = Just $ (LSP. StringValue $ T. pack $ codePre ++ ideaHint idea)
126
126
, _source = Just " hlint"
127
127
, _message = T. pack $ show idea
128
128
, _relatedInformation = Nothing
129
129
, _tags = Nothing
130
130
}
131
+ where codePre = if null $ ideaRefactoring idea then " " else " refact:"
131
132
132
133
-- This one is defined in Development.IDE.GHC.Error but here
133
134
-- the types could come from ghc-lib or ghc
@@ -217,12 +218,12 @@ codeActionProvider _lf ideState plId docId _ context = Right . LSP.List . map CA
217
218
let docNfp = toNormalizedFilePath' <$> uriToFilePath' (docId ^. LSP. uri)
218
219
numHintsInDoc = length
219
220
[d | (nfp, _, d) <- diags
220
- , d ^. LSP. source == Just " hlint "
221
+ , validCommand d
221
222
, Just nfp == docNfp
222
223
]
223
224
-- We only want to show the applyAll code action if there is more than 1
224
225
-- hint in the current document
225
- if numHintsInDoc >= 2 then do
226
+ if numHintsInDoc > 1 then do
226
227
applyAll <- applyAllAction
227
228
pure $ applyAll: applyOne
228
229
else
@@ -238,8 +239,9 @@ codeActionProvider _lf ideState plId docId _ context = Right . LSP.List . map CA
238
239
239
240
-- | Some hints do not have an associated refactoring
240
241
validCommand (LSP. Diagnostic _ _ (Just (LSP. StringValue code)) (Just " hlint" ) _ _ _) =
241
- code /= " Eta reduce"
242
- validCommand _ = False
242
+ " refact:" `T.isPrefixOf` code
243
+ validCommand _ =
244
+ False
243
245
244
246
LSP. List diags = context ^. LSP. diagnostics
245
247
@@ -248,7 +250,7 @@ codeActionProvider _lf ideState plId docId _ context = Right . LSP.List . map CA
248
250
Just . codeAction <$> mkLspCommand plId " applyOne" title (Just args)
249
251
where
250
252
codeAction cmd = LSP. CodeAction title (Just LSP. CodeActionQuickFix ) (Just (LSP. List [diag])) Nothing (Just cmd)
251
- title = " Apply hint: " <> code
253
+ title = T. replace code " refact: " " Apply hint: "
252
254
-- need 'file', 'start_pos' and hint title (to distinguish between alternative suggestions at the same location)
253
255
args = [toJSON (AOP (docId ^. LSP. uri) start code)]
254
256
mkHlintAction (LSP. Diagnostic _r _s _c _source _m _ _) = return Nothing
0 commit comments