zwirn-0.2.2.0: app/zwirnzi/LSP/Handlers/Action.hs
{-# LANGUAGE RecordWildCards #-}
module LSP.Handlers.Action where
import Control.Lens ((^.))
import qualified Data.Aeson as J
import LSP.Util
import qualified Language.LSP.Protocol.Lens as LSP
import qualified Language.LSP.Protocol.Message as LSP
import Language.LSP.Protocol.Types ()
import qualified Language.LSP.Protocol.Types as LSP
import Language.LSP.Server (Handlers, requestHandler)
codeActionHandler :: Handlers LSP
codeActionHandler = requestHandler LSP.SMethod_TextDocumentCodeAction $ \req responder -> do
let LSP.CodeActionParams _ _ doc range _ = req ^. LSP.params
-- uri = doc ^. LSP.uri
-- debug (T.pack $ "Processing custom code action" ++ show range)
let title = "Evaluate zwirn code at cursor"
-- NOTE: the cmd needs to be registered via the InitializeResponse message. See lspOptions above
cmd = "zwirn-eval"
args =
[ J.toJSON doc,
J.toJSON range
]
command = LSP.Command title cmd (Just args)
let action = LSP.CodeAction {..}
where
_title = "eval"
_kind = Just $ LSP.CodeActionKind_Custom "zwirn"
_diagnostics = Nothing
_isPreferred = Nothing
_disabled = Nothing
_edit = Nothing
_command = Just command
_data_ = Nothing
responder $ Right $ LSP.InL $ LSP.InR <$> [action]