Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter code actions by diagnostic ranges too #86

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Curry/LanguageServer/Handlers/TextDocument/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ fetchCodeActionsInRange :: (MonadIO m, MonadLsp CFG.Config m) => J.Range -> I.Mo
fetchCodeActionsInRange range entry = filterCodeActionsInRange range <$> fetchCodeActions entry

filterCodeActionsInRange :: J.Range -> [J.CodeAction] -> [J.CodeAction]
filterCodeActionsInRange range = filter $ \a -> any (rangeOverlaps range)
[ txtEdit ^. J.range
| Just workspaceEdit <- [a ^. J.edit]
, Just changes <- [workspaceEdit ^. J.documentChanges]
, J.InL docEdit <- changes
, J.InL txtEdit <- docEdit ^. J.edits
]
filterCodeActionsInRange range = filter $ \a ->
let editRanges = [ txtEdit ^. J.range
| Just workspaceEdit <- [a ^. J.edit]
, Just changes <- [workspaceEdit ^. J.documentChanges]
, J.InL docEdit <- changes
, J.InL txtEdit <- docEdit ^. J.edits
]
diagRanges = [ diag ^. J.range
| Just diags <- [a ^. J.diagnostics]
, diag <- diags
]
ranges = editRanges ++ diagRanges
in any (rangeOverlaps range) ranges

fetchCodeActions :: (MonadIO m, MonadLsp CFG.Config m) => I.ModuleStoreEntry -> m [J.CodeAction]
fetchCodeActions entry = do
Expand Down