{-# LANGUAGE OverloadedStrings #-}
module Ide.Plugin.HandleRequestTypes where
import Data.Text
import Prettyprinter
data RejectionReason =
NotResolveOwner Text
| DisabledGlobally
| FeatureDisabled
| NotFormattingProvider Text
| DoesNotSupportFileType Text
deriving (RejectionReason -> RejectionReason -> Bool
(RejectionReason -> RejectionReason -> Bool)
-> (RejectionReason -> RejectionReason -> Bool)
-> Eq RejectionReason
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RejectionReason -> RejectionReason -> Bool
== :: RejectionReason -> RejectionReason -> Bool
$c/= :: RejectionReason -> RejectionReason -> Bool
/= :: RejectionReason -> RejectionReason -> Bool
Eq)
data HandleRequestResult = HandlesRequest | DoesNotHandleRequest RejectionReason
deriving (HandleRequestResult -> HandleRequestResult -> Bool
(HandleRequestResult -> HandleRequestResult -> Bool)
-> (HandleRequestResult -> HandleRequestResult -> Bool)
-> Eq HandleRequestResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HandleRequestResult -> HandleRequestResult -> Bool
== :: HandleRequestResult -> HandleRequestResult -> Bool
$c/= :: HandleRequestResult -> HandleRequestResult -> Bool
/= :: HandleRequestResult -> HandleRequestResult -> Bool
Eq)
instance Pretty HandleRequestResult where
pretty :: forall ann. HandleRequestResult -> Doc ann
pretty HandleRequestResult
HandlesRequest = Doc ann
"handles this request"
pretty (DoesNotHandleRequest RejectionReason
reason) = RejectionReason -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. RejectionReason -> Doc ann
pretty RejectionReason
reason
instance Pretty RejectionReason where
pretty :: forall ann. RejectionReason -> Doc ann
pretty (NotResolveOwner Text
s) = Doc ann
"does not handle resolve requests for " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
s Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
")."
pretty RejectionReason
DisabledGlobally = Doc ann
"is disabled globally in your config."
pretty RejectionReason
FeatureDisabled = Doc ann
"'s feature that handles this request is disabled in your config."
pretty (NotFormattingProvider Text
s) = Doc ann
"is not the formatting provider ("Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
sDoc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<>Doc ann
") you chose in your config."
pretty (DoesNotSupportFileType Text
s) = Doc ann
"does not support " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
s Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
" filetypes)."
instance Semigroup HandleRequestResult where
HandleRequestResult
HandlesRequest <> :: HandleRequestResult -> HandleRequestResult -> HandleRequestResult
<> HandleRequestResult
HandlesRequest = HandleRequestResult
HandlesRequest
DoesNotHandleRequest RejectionReason
r <> HandleRequestResult
_ = RejectionReason -> HandleRequestResult
DoesNotHandleRequest RejectionReason
r
HandleRequestResult
_ <> DoesNotHandleRequest RejectionReason
r = RejectionReason -> HandleRequestResult
DoesNotHandleRequest RejectionReason
r