X-Git-Url: http://git.lukelau.me/?p=lsp-test.git;a=blobdiff_plain;f=src%2FLanguage%2FLSP%2FTest.hs;fp=src%2FLanguage%2FLSP%2FTest.hs;h=ae2453065be6051420e6c73e218208cd0c120a4a;hp=6c5c4a6674681b0a077352f9274864737eb1bad5;hb=cc180dcaf2f72684a42b73d1cb76c31037c8c81a;hpb=04857dfc5bde657533dc042ec451abbf7ea3a334 diff --git a/src/Language/LSP/Test.hs b/src/Language/LSP/Test.hs index 6c5c4a6..ae24530 100644 --- a/src/Language/LSP/Test.hs +++ b/src/Language/LSP/Test.hs @@ -7,6 +7,7 @@ {-# LANGUAGE TypeInType #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE DuplicateRecordFields #-} {-| Module : Language.LSP.Test @@ -501,7 +502,7 @@ getDocumentSymbols doc = do -- | Returns the code actions in the specified range. getCodeActions :: TextDocumentIdentifier -> Range -> Session [Command |? CodeAction] getCodeActions doc range = do - ctx <- getCodeActionContext doc + ctx <- getCodeActionContextInRange doc range rsp <- request STextDocumentCodeAction (CodeActionParams Nothing Nothing doc range ctx) case rsp ^. result of @@ -526,6 +527,26 @@ getAllCodeActions doc = do Left e -> throw (UnexpectedResponseError (SomeLspId $ fromJust rspLid) e) Right (List cmdOrCAs) -> pure (acc ++ cmdOrCAs) +getCodeActionContextInRange :: TextDocumentIdentifier -> Range -> Session CodeActionContext +getCodeActionContextInRange doc caRange = do + curDiags <- getCurrentDiagnostics doc + let diags = [ d | d@Diagnostic{_range=range} <- curDiags + , overlappingRange caRange range + ] + return $ CodeActionContext (List diags) Nothing + where + overlappingRange :: Range -> Range -> Bool + overlappingRange (Range s e) range = + positionInRange s range + || positionInRange e range + + positionInRange :: Position -> Range -> Bool + positionInRange (Position pl po) (Range (Position sl so) (Position el eo)) = + pl > sl && pl < el + || pl == sl && pl == el && po >= so && po <= eo + || pl == sl && po >= so + || pl == el && po <= eo + getCodeActionContext :: TextDocumentIdentifier -> Session CodeActionContext getCodeActionContext doc = do curDiags <- getCurrentDiagnostics doc