7
7
{-# LANGUAGE TypeInType #-}
8
8
{-# LANGUAGE ScopedTypeVariables #-}
9
9
{-# LANGUAGE ExistentialQuantification #-}
10
+ {-# LANGUAGE DuplicateRecordFields #-}
10
11
11
12
{-|
12
13
Module : Language.LSP.Test
@@ -501,7 +502,7 @@ getDocumentSymbols doc = do
501
502
-- | Returns the code actions in the specified range.
502
503
getCodeActions :: TextDocumentIdentifier -> Range -> Session [Command |? CodeAction ]
503
504
getCodeActions doc range = do
504
- ctx <- getCodeActionContext doc
505
+ ctx <- getCodeActionContextInRange doc range
505
506
rsp <- request STextDocumentCodeAction (CodeActionParams Nothing Nothing doc range ctx)
506
507
507
508
case rsp ^. result of
@@ -526,6 +527,26 @@ getAllCodeActions doc = do
526
527
Left e -> throw (UnexpectedResponseError (SomeLspId $ fromJust rspLid) e)
527
528
Right (List cmdOrCAs) -> pure (acc ++ cmdOrCAs)
528
529
530
+ getCodeActionContextInRange :: TextDocumentIdentifier -> Range -> Session CodeActionContext
531
+ getCodeActionContextInRange doc caRange = do
532
+ curDiags <- getCurrentDiagnostics doc
533
+ let diags = [ d | d@ Diagnostic {_range= range} <- curDiags
534
+ , overlappingRange caRange range
535
+ ]
536
+ return $ CodeActionContext (List diags) Nothing
537
+ where
538
+ overlappingRange :: Range -> Range -> Bool
539
+ overlappingRange (Range s e) range =
540
+ positionInRange s range
541
+ || positionInRange e range
542
+
543
+ positionInRange :: Position -> Range -> Bool
544
+ positionInRange (Position pl po) (Range (Position sl so) (Position el eo)) =
545
+ pl > sl && pl < el
546
+ || pl == sl && pl == el && po >= so && po <= eo
547
+ || pl == sl && po >= so
548
+ || pl == el && po <= eo
549
+
529
550
getCodeActionContext :: TextDocumentIdentifier -> Session CodeActionContext
530
551
getCodeActionContext doc = do
531
552
curDiags <- getCurrentDiagnostics doc
0 commit comments