{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

{- |
Module      :  Neovim.Quickfix
Description :  API for interacting with the quickfix list
Copyright   :  (c) Sebastian Witte
License     :  Apache-2.0

Maintainer  :  woozletoff@gmail.com
Stability   :  experimental
Portability :  GHC
-}
module Neovim.Quickfix where

import Neovim.API.String ( vim_call_function )
import Neovim.Classes
    ( Generic,
      NFData,
      (<+>),
      Doc,
      AnsiStyle,
      NvimObject(toObject, fromObject),
      (+:) )
import Neovim.Context ( throwError, Neovim )


import Control.Monad (void)
import Data.ByteString as BS (ByteString, all, elem)
import qualified Data.Map as Map
import Data.Maybe ( fromMaybe )
import Data.MessagePack ( Object(ObjectBinary, ObjectMap) )
import Prettyprinter (viaShow)
import Prelude

{- | This is a wrapper around neovim's @setqflist()@. @strType@ can be any
 string that you can append to (hence 'Monoid') that is also an instance
 of 'NvimObject'. You can e.g. use the plain old 'String'.
-}
setqflist ::
    (Monoid strType, NvimObject strType) =>
    [QuickfixListItem strType] ->
    QuickfixAction ->
    Neovim env ()
setqflist :: forall strType env.
(Monoid strType, NvimObject strType) =>
[QuickfixListItem strType] -> QuickfixAction -> Neovim env ()
setqflist [QuickfixListItem strType]
qs QuickfixAction
a =
    Neovim env Object -> Neovim env ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Neovim env Object -> Neovim env ())
-> Neovim env Object -> Neovim env ()
forall a b. (a -> b) -> a -> b
$ String -> [Object] -> Neovim env Object
forall env. String -> [Object] -> Neovim env Object
vim_call_function String
"setqflist" ([Object] -> Neovim env Object) -> [Object] -> Neovim env Object
forall a b. (a -> b) -> a -> b
$ [QuickfixListItem strType]
qs [QuickfixListItem strType] -> [Object] -> [Object]
forall o. NvimObject o => o -> [Object] -> [Object]
+: QuickfixAction
a QuickfixAction -> [Object] -> [Object]
forall o. NvimObject o => o -> [Object] -> [Object]
+: []

data ColumnNumber
    = VisualColumn Int
    | ByteIndexColumn Int
    | NoColumn
    deriving (ColumnNumber -> ColumnNumber -> Bool
(ColumnNumber -> ColumnNumber -> Bool)
-> (ColumnNumber -> ColumnNumber -> Bool) -> Eq ColumnNumber
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ColumnNumber -> ColumnNumber -> Bool
== :: ColumnNumber -> ColumnNumber -> Bool
$c/= :: ColumnNumber -> ColumnNumber -> Bool
/= :: ColumnNumber -> ColumnNumber -> Bool
Eq, Eq ColumnNumber
Eq ColumnNumber =>
(ColumnNumber -> ColumnNumber -> Ordering)
-> (ColumnNumber -> ColumnNumber -> Bool)
-> (ColumnNumber -> ColumnNumber -> Bool)
-> (ColumnNumber -> ColumnNumber -> Bool)
-> (ColumnNumber -> ColumnNumber -> Bool)
-> (ColumnNumber -> ColumnNumber -> ColumnNumber)
-> (ColumnNumber -> ColumnNumber -> ColumnNumber)
-> Ord ColumnNumber
ColumnNumber -> ColumnNumber -> Bool
ColumnNumber -> ColumnNumber -> Ordering
ColumnNumber -> ColumnNumber -> ColumnNumber
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ColumnNumber -> ColumnNumber -> Ordering
compare :: ColumnNumber -> ColumnNumber -> Ordering
$c< :: ColumnNumber -> ColumnNumber -> Bool
< :: ColumnNumber -> ColumnNumber -> Bool
$c<= :: ColumnNumber -> ColumnNumber -> Bool
<= :: ColumnNumber -> ColumnNumber -> Bool
$c> :: ColumnNumber -> ColumnNumber -> Bool
> :: ColumnNumber -> ColumnNumber -> Bool
$c>= :: ColumnNumber -> ColumnNumber -> Bool
>= :: ColumnNumber -> ColumnNumber -> Bool
$cmax :: ColumnNumber -> ColumnNumber -> ColumnNumber
max :: ColumnNumber -> ColumnNumber -> ColumnNumber
$cmin :: ColumnNumber -> ColumnNumber -> ColumnNumber
min :: ColumnNumber -> ColumnNumber -> ColumnNumber
Ord, Int -> ColumnNumber -> ShowS
[ColumnNumber] -> ShowS
ColumnNumber -> String
(Int -> ColumnNumber -> ShowS)
-> (ColumnNumber -> String)
-> ([ColumnNumber] -> ShowS)
-> Show ColumnNumber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ColumnNumber -> ShowS
showsPrec :: Int -> ColumnNumber -> ShowS
$cshow :: ColumnNumber -> String
show :: ColumnNumber -> String
$cshowList :: [ColumnNumber] -> ShowS
showList :: [ColumnNumber] -> ShowS
Show, (forall x. ColumnNumber -> Rep ColumnNumber x)
-> (forall x. Rep ColumnNumber x -> ColumnNumber)
-> Generic ColumnNumber
forall x. Rep ColumnNumber x -> ColumnNumber
forall x. ColumnNumber -> Rep ColumnNumber x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ColumnNumber -> Rep ColumnNumber x
from :: forall x. ColumnNumber -> Rep ColumnNumber x
$cto :: forall x. Rep ColumnNumber x -> ColumnNumber
to :: forall x. Rep ColumnNumber x -> ColumnNumber
Generic)

instance NFData ColumnNumber

data SignLocation strType
    = LineNumber Int
    | SearchPattern strType
    deriving (SignLocation strType -> SignLocation strType -> Bool
(SignLocation strType -> SignLocation strType -> Bool)
-> (SignLocation strType -> SignLocation strType -> Bool)
-> Eq (SignLocation strType)
forall strType.
Eq strType =>
SignLocation strType -> SignLocation strType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall strType.
Eq strType =>
SignLocation strType -> SignLocation strType -> Bool
== :: SignLocation strType -> SignLocation strType -> Bool
$c/= :: forall strType.
Eq strType =>
SignLocation strType -> SignLocation strType -> Bool
/= :: SignLocation strType -> SignLocation strType -> Bool
Eq, Eq (SignLocation strType)
Eq (SignLocation strType) =>
(SignLocation strType -> SignLocation strType -> Ordering)
-> (SignLocation strType -> SignLocation strType -> Bool)
-> (SignLocation strType -> SignLocation strType -> Bool)
-> (SignLocation strType -> SignLocation strType -> Bool)
-> (SignLocation strType -> SignLocation strType -> Bool)
-> (SignLocation strType
    -> SignLocation strType -> SignLocation strType)
-> (SignLocation strType
    -> SignLocation strType -> SignLocation strType)
-> Ord (SignLocation strType)
SignLocation strType -> SignLocation strType -> Bool
SignLocation strType -> SignLocation strType -> Ordering
SignLocation strType
-> SignLocation strType -> SignLocation strType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall strType. Ord strType => Eq (SignLocation strType)
forall strType.
Ord strType =>
SignLocation strType -> SignLocation strType -> Bool
forall strType.
Ord strType =>
SignLocation strType -> SignLocation strType -> Ordering
forall strType.
Ord strType =>
SignLocation strType
-> SignLocation strType -> SignLocation strType
$ccompare :: forall strType.
Ord strType =>
SignLocation strType -> SignLocation strType -> Ordering
compare :: SignLocation strType -> SignLocation strType -> Ordering
$c< :: forall strType.
Ord strType =>
SignLocation strType -> SignLocation strType -> Bool
< :: SignLocation strType -> SignLocation strType -> Bool
$c<= :: forall strType.
Ord strType =>
SignLocation strType -> SignLocation strType -> Bool
<= :: SignLocation strType -> SignLocation strType -> Bool
$c> :: forall strType.
Ord strType =>
SignLocation strType -> SignLocation strType -> Bool
> :: SignLocation strType -> SignLocation strType -> Bool
$c>= :: forall strType.
Ord strType =>
SignLocation strType -> SignLocation strType -> Bool
>= :: SignLocation strType -> SignLocation strType -> Bool
$cmax :: forall strType.
Ord strType =>
SignLocation strType
-> SignLocation strType -> SignLocation strType
max :: SignLocation strType
-> SignLocation strType -> SignLocation strType
$cmin :: forall strType.
Ord strType =>
SignLocation strType
-> SignLocation strType -> SignLocation strType
min :: SignLocation strType
-> SignLocation strType -> SignLocation strType
Ord, Int -> SignLocation strType -> ShowS
[SignLocation strType] -> ShowS
SignLocation strType -> String
(Int -> SignLocation strType -> ShowS)
-> (SignLocation strType -> String)
-> ([SignLocation strType] -> ShowS)
-> Show (SignLocation strType)
forall strType.
Show strType =>
Int -> SignLocation strType -> ShowS
forall strType. Show strType => [SignLocation strType] -> ShowS
forall strType. Show strType => SignLocation strType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall strType.
Show strType =>
Int -> SignLocation strType -> ShowS
showsPrec :: Int -> SignLocation strType -> ShowS
$cshow :: forall strType. Show strType => SignLocation strType -> String
show :: SignLocation strType -> String
$cshowList :: forall strType. Show strType => [SignLocation strType] -> ShowS
showList :: [SignLocation strType] -> ShowS
Show, (forall x. SignLocation strType -> Rep (SignLocation strType) x)
-> (forall x. Rep (SignLocation strType) x -> SignLocation strType)
-> Generic (SignLocation strType)
forall x. Rep (SignLocation strType) x -> SignLocation strType
forall x. SignLocation strType -> Rep (SignLocation strType) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall strType x.
Rep (SignLocation strType) x -> SignLocation strType
forall strType x.
SignLocation strType -> Rep (SignLocation strType) x
$cfrom :: forall strType x.
SignLocation strType -> Rep (SignLocation strType) x
from :: forall x. SignLocation strType -> Rep (SignLocation strType) x
$cto :: forall strType x.
Rep (SignLocation strType) x -> SignLocation strType
to :: forall x. Rep (SignLocation strType) x -> SignLocation strType
Generic)

instance (NFData strType) => NFData (SignLocation strType)

{- | Quickfix list item. The parameter names should mostly conform to those in
 @:h setqflist()@. Some fields are merged to explicitly state mutually
 exclusive elements or some other behavior of the fields.

 see 'quickfixListItem' for creating a value of this type without typing too
 much.
-}
data QuickfixListItem strType = QFItem
    { -- | Since the filename is only used if no buffer can be specified, this
      -- field is a merge of @bufnr@ and @filename@.
      forall strType. QuickfixListItem strType -> Either Int strType
bufOrFile :: Either Int strType
    , -- | Line number or search pattern to locate the error.
      forall strType. QuickfixListItem strType -> Either Int strType
lnumOrPattern :: Either Int strType
    , -- | A tuple of a column number and a boolean indicating which kind of
      -- indexing should be used. 'True' means that the visual column should be
      -- used. 'False' means to use the byte index.
      forall strType. QuickfixListItem strType -> ColumnNumber
col :: ColumnNumber
    , -- | Error number.
      forall strType. QuickfixListItem strType -> Maybe Int
nr :: Maybe Int
    , -- | Description of the error.
      forall strType. QuickfixListItem strType -> strType
text :: strType
    , -- | Type of error.
      forall strType. QuickfixListItem strType -> QuickfixErrorType
errorType :: QuickfixErrorType
    }
    deriving (QuickfixListItem strType -> QuickfixListItem strType -> Bool
(QuickfixListItem strType -> QuickfixListItem strType -> Bool)
-> (QuickfixListItem strType -> QuickfixListItem strType -> Bool)
-> Eq (QuickfixListItem strType)
forall strType.
Eq strType =>
QuickfixListItem strType -> QuickfixListItem strType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall strType.
Eq strType =>
QuickfixListItem strType -> QuickfixListItem strType -> Bool
== :: QuickfixListItem strType -> QuickfixListItem strType -> Bool
$c/= :: forall strType.
Eq strType =>
QuickfixListItem strType -> QuickfixListItem strType -> Bool
/= :: QuickfixListItem strType -> QuickfixListItem strType -> Bool
Eq, Int -> QuickfixListItem strType -> ShowS
[QuickfixListItem strType] -> ShowS
QuickfixListItem strType -> String
(Int -> QuickfixListItem strType -> ShowS)
-> (QuickfixListItem strType -> String)
-> ([QuickfixListItem strType] -> ShowS)
-> Show (QuickfixListItem strType)
forall strType.
Show strType =>
Int -> QuickfixListItem strType -> ShowS
forall strType. Show strType => [QuickfixListItem strType] -> ShowS
forall strType. Show strType => QuickfixListItem strType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall strType.
Show strType =>
Int -> QuickfixListItem strType -> ShowS
showsPrec :: Int -> QuickfixListItem strType -> ShowS
$cshow :: forall strType. Show strType => QuickfixListItem strType -> String
show :: QuickfixListItem strType -> String
$cshowList :: forall strType. Show strType => [QuickfixListItem strType] -> ShowS
showList :: [QuickfixListItem strType] -> ShowS
Show, (forall x.
 QuickfixListItem strType -> Rep (QuickfixListItem strType) x)
-> (forall x.
    Rep (QuickfixListItem strType) x -> QuickfixListItem strType)
-> Generic (QuickfixListItem strType)
forall x.
Rep (QuickfixListItem strType) x -> QuickfixListItem strType
forall x.
QuickfixListItem strType -> Rep (QuickfixListItem strType) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall strType x.
Rep (QuickfixListItem strType) x -> QuickfixListItem strType
forall strType x.
QuickfixListItem strType -> Rep (QuickfixListItem strType) x
$cfrom :: forall strType x.
QuickfixListItem strType -> Rep (QuickfixListItem strType) x
from :: forall x.
QuickfixListItem strType -> Rep (QuickfixListItem strType) x
$cto :: forall strType x.
Rep (QuickfixListItem strType) x -> QuickfixListItem strType
to :: forall x.
Rep (QuickfixListItem strType) x -> QuickfixListItem strType
Generic)

instance (NFData strType) => NFData (QuickfixListItem strType)

-- | Simple error type enum.
data QuickfixErrorType = Warning | Error
    deriving (QuickfixErrorType -> QuickfixErrorType -> Bool
(QuickfixErrorType -> QuickfixErrorType -> Bool)
-> (QuickfixErrorType -> QuickfixErrorType -> Bool)
-> Eq QuickfixErrorType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: QuickfixErrorType -> QuickfixErrorType -> Bool
== :: QuickfixErrorType -> QuickfixErrorType -> Bool
$c/= :: QuickfixErrorType -> QuickfixErrorType -> Bool
/= :: QuickfixErrorType -> QuickfixErrorType -> Bool
Eq, Eq QuickfixErrorType
Eq QuickfixErrorType =>
(QuickfixErrorType -> QuickfixErrorType -> Ordering)
-> (QuickfixErrorType -> QuickfixErrorType -> Bool)
-> (QuickfixErrorType -> QuickfixErrorType -> Bool)
-> (QuickfixErrorType -> QuickfixErrorType -> Bool)
-> (QuickfixErrorType -> QuickfixErrorType -> Bool)
-> (QuickfixErrorType -> QuickfixErrorType -> QuickfixErrorType)
-> (QuickfixErrorType -> QuickfixErrorType -> QuickfixErrorType)
-> Ord QuickfixErrorType
QuickfixErrorType -> QuickfixErrorType -> Bool
QuickfixErrorType -> QuickfixErrorType -> Ordering
QuickfixErrorType -> QuickfixErrorType -> QuickfixErrorType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: QuickfixErrorType -> QuickfixErrorType -> Ordering
compare :: QuickfixErrorType -> QuickfixErrorType -> Ordering
$c< :: QuickfixErrorType -> QuickfixErrorType -> Bool
< :: QuickfixErrorType -> QuickfixErrorType -> Bool
$c<= :: QuickfixErrorType -> QuickfixErrorType -> Bool
<= :: QuickfixErrorType -> QuickfixErrorType -> Bool
$c> :: QuickfixErrorType -> QuickfixErrorType -> Bool
> :: QuickfixErrorType -> QuickfixErrorType -> Bool
$c>= :: QuickfixErrorType -> QuickfixErrorType -> Bool
>= :: QuickfixErrorType -> QuickfixErrorType -> Bool
$cmax :: QuickfixErrorType -> QuickfixErrorType -> QuickfixErrorType
max :: QuickfixErrorType -> QuickfixErrorType -> QuickfixErrorType
$cmin :: QuickfixErrorType -> QuickfixErrorType -> QuickfixErrorType
min :: QuickfixErrorType -> QuickfixErrorType -> QuickfixErrorType
Ord, Int -> QuickfixErrorType -> ShowS
[QuickfixErrorType] -> ShowS
QuickfixErrorType -> String
(Int -> QuickfixErrorType -> ShowS)
-> (QuickfixErrorType -> String)
-> ([QuickfixErrorType] -> ShowS)
-> Show QuickfixErrorType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> QuickfixErrorType -> ShowS
showsPrec :: Int -> QuickfixErrorType -> ShowS
$cshow :: QuickfixErrorType -> String
show :: QuickfixErrorType -> String
$cshowList :: [QuickfixErrorType] -> ShowS
showList :: [QuickfixErrorType] -> ShowS
Show, ReadPrec [QuickfixErrorType]
ReadPrec QuickfixErrorType
Int -> ReadS QuickfixErrorType
ReadS [QuickfixErrorType]
(Int -> ReadS QuickfixErrorType)
-> ReadS [QuickfixErrorType]
-> ReadPrec QuickfixErrorType
-> ReadPrec [QuickfixErrorType]
-> Read QuickfixErrorType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS QuickfixErrorType
readsPrec :: Int -> ReadS QuickfixErrorType
$creadList :: ReadS [QuickfixErrorType]
readList :: ReadS [QuickfixErrorType]
$creadPrec :: ReadPrec QuickfixErrorType
readPrec :: ReadPrec QuickfixErrorType
$creadListPrec :: ReadPrec [QuickfixErrorType]
readListPrec :: ReadPrec [QuickfixErrorType]
Read, Int -> QuickfixErrorType
QuickfixErrorType -> Int
QuickfixErrorType -> [QuickfixErrorType]
QuickfixErrorType -> QuickfixErrorType
QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType]
QuickfixErrorType
-> QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType]
(QuickfixErrorType -> QuickfixErrorType)
-> (QuickfixErrorType -> QuickfixErrorType)
-> (Int -> QuickfixErrorType)
-> (QuickfixErrorType -> Int)
-> (QuickfixErrorType -> [QuickfixErrorType])
-> (QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType])
-> (QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType])
-> (QuickfixErrorType
    -> QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType])
-> Enum QuickfixErrorType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: QuickfixErrorType -> QuickfixErrorType
succ :: QuickfixErrorType -> QuickfixErrorType
$cpred :: QuickfixErrorType -> QuickfixErrorType
pred :: QuickfixErrorType -> QuickfixErrorType
$ctoEnum :: Int -> QuickfixErrorType
toEnum :: Int -> QuickfixErrorType
$cfromEnum :: QuickfixErrorType -> Int
fromEnum :: QuickfixErrorType -> Int
$cenumFrom :: QuickfixErrorType -> [QuickfixErrorType]
enumFrom :: QuickfixErrorType -> [QuickfixErrorType]
$cenumFromThen :: QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType]
enumFromThen :: QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType]
$cenumFromTo :: QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType]
enumFromTo :: QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType]
$cenumFromThenTo :: QuickfixErrorType
-> QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType]
enumFromThenTo :: QuickfixErrorType
-> QuickfixErrorType -> QuickfixErrorType -> [QuickfixErrorType]
Enum, QuickfixErrorType
QuickfixErrorType -> QuickfixErrorType -> Bounded QuickfixErrorType
forall a. a -> a -> Bounded a
$cminBound :: QuickfixErrorType
minBound :: QuickfixErrorType
$cmaxBound :: QuickfixErrorType
maxBound :: QuickfixErrorType
Bounded, (forall x. QuickfixErrorType -> Rep QuickfixErrorType x)
-> (forall x. Rep QuickfixErrorType x -> QuickfixErrorType)
-> Generic QuickfixErrorType
forall x. Rep QuickfixErrorType x -> QuickfixErrorType
forall x. QuickfixErrorType -> Rep QuickfixErrorType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. QuickfixErrorType -> Rep QuickfixErrorType x
from :: forall x. QuickfixErrorType -> Rep QuickfixErrorType x
$cto :: forall x. Rep QuickfixErrorType x -> QuickfixErrorType
to :: forall x. Rep QuickfixErrorType x -> QuickfixErrorType
Generic)

instance NFData QuickfixErrorType

instance NvimObject QuickfixErrorType where
    toObject :: QuickfixErrorType -> Object
toObject = \case
        QuickfixErrorType
Warning -> ByteString -> Object
ObjectBinary ByteString
"W"
        QuickfixErrorType
Error -> ByteString -> Object
ObjectBinary ByteString
"E"

    fromObject :: Object -> Either (Doc AnsiStyle) QuickfixErrorType
fromObject Object
o = case Object -> Either (Doc AnsiStyle) String
forall o. NvimObject o => Object -> Either (Doc AnsiStyle) o
fromObject Object
o :: Either (Doc AnsiStyle) String of
        Right String
"W" -> QuickfixErrorType -> Either (Doc AnsiStyle) QuickfixErrorType
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return QuickfixErrorType
Warning
        Right String
"E" -> QuickfixErrorType -> Either (Doc AnsiStyle) QuickfixErrorType
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return QuickfixErrorType
Error
        Either (Doc AnsiStyle) String
_ -> QuickfixErrorType -> Either (Doc AnsiStyle) QuickfixErrorType
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return QuickfixErrorType
Error

{- | Create a 'QuickfixListItem' by providing the minimal amount of arguments
 needed.
-}
quickfixListItem ::
    (Monoid strType) =>
    -- | buffer of file name
    Either Int strType ->
    -- | line number or pattern
    Either Int strType ->
    QuickfixListItem strType
quickfixListItem :: forall strType.
Monoid strType =>
Either Int strType
-> Either Int strType -> QuickfixListItem strType
quickfixListItem Either Int strType
bufferOrFile Either Int strType
lineOrPattern =
    QFItem
        { bufOrFile :: Either Int strType
bufOrFile = Either Int strType
bufferOrFile
        , lnumOrPattern :: Either Int strType
lnumOrPattern = Either Int strType
lineOrPattern
        , col :: ColumnNumber
col = ColumnNumber
NoColumn
        , nr :: Maybe Int
nr = Maybe Int
forall a. Maybe a
Nothing
        , text :: strType
text = strType
forall a. Monoid a => a
mempty
        , errorType :: QuickfixErrorType
errorType = QuickfixErrorType
Error
        }

instance
    (Monoid strType, NvimObject strType) =>
    NvimObject (QuickfixListItem strType)
    where
    toObject :: QuickfixListItem strType -> Object
toObject QFItem{strType
Maybe Int
Either Int strType
QuickfixErrorType
ColumnNumber
bufOrFile :: forall strType. QuickfixListItem strType -> Either Int strType
lnumOrPattern :: forall strType. QuickfixListItem strType -> Either Int strType
col :: forall strType. QuickfixListItem strType -> ColumnNumber
nr :: forall strType. QuickfixListItem strType -> Maybe Int
text :: forall strType. QuickfixListItem strType -> strType
errorType :: forall strType. QuickfixListItem strType -> QuickfixErrorType
bufOrFile :: Either Int strType
lnumOrPattern :: Either Int strType
col :: ColumnNumber
nr :: Maybe Int
text :: strType
errorType :: QuickfixErrorType
..} =
        (Map ByteString Object -> Object
forall o. NvimObject o => o -> Object
toObject :: Map.Map ByteString Object -> Object) (Map ByteString Object -> Object)
-> ([(ByteString, Object)] -> Map ByteString Object)
-> [(ByteString, Object)]
-> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(ByteString, Object)] -> Map ByteString Object
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(ByteString, Object)] -> Object)
-> [(ByteString, Object)] -> Object
forall a b. (a -> b) -> a -> b
$
            [ (Int -> (ByteString, Object))
-> (strType -> (ByteString, Object))
-> Either Int strType
-> (ByteString, Object)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
                (\Int
b -> (ByteString
"bufnr", Int -> Object
forall o. NvimObject o => o -> Object
toObject Int
b))
                (\strType
f -> (ByteString
"filename", strType -> Object
forall o. NvimObject o => o -> Object
toObject strType
f))
                Either Int strType
bufOrFile
            , (Int -> (ByteString, Object))
-> (strType -> (ByteString, Object))
-> Either Int strType
-> (ByteString, Object)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
                (\Int
l -> (ByteString
"lnum", Int -> Object
forall o. NvimObject o => o -> Object
toObject Int
l))
                (\strType
p -> (ByteString
"pattern", strType -> Object
forall o. NvimObject o => o -> Object
toObject strType
p))
                Either Int strType
lnumOrPattern
            , (ByteString
"type", QuickfixErrorType -> Object
forall o. NvimObject o => o -> Object
toObject QuickfixErrorType
errorType)
            , (ByteString
"text", strType -> Object
forall o. NvimObject o => o -> Object
toObject strType
text)
            ]
                [(ByteString, Object)]
-> [(ByteString, Object)] -> [(ByteString, Object)]
forall a. [a] -> [a] -> [a]
++ case ColumnNumber
col of
                    ColumnNumber
NoColumn -> []
                    ByteIndexColumn Int
i -> [(ByteString
"col", Int -> Object
forall o. NvimObject o => o -> Object
toObject Int
i), (ByteString
"vcol", Bool -> Object
forall o. NvimObject o => o -> Object
toObject Bool
False)]
                    VisualColumn Int
i -> [(ByteString
"col", Int -> Object
forall o. NvimObject o => o -> Object
toObject Int
i), (ByteString
"vcol", Bool -> Object
forall o. NvimObject o => o -> Object
toObject Bool
True)]

    fromObject :: Object -> Either (Doc AnsiStyle) (QuickfixListItem strType)
fromObject objectMap :: Object
objectMap@(ObjectMap Map Object Object
_) = do
        Map ByteString Object
m <- Object -> Either (Doc AnsiStyle) (Map ByteString Object)
forall o. NvimObject o => Object -> Either (Doc AnsiStyle) o
fromObject Object
objectMap
        let l :: NvimObject o => ByteString -> Either (Doc AnsiStyle) o
            l :: forall o. NvimObject o => ByteString -> Either (Doc AnsiStyle) o
l ByteString
key = case ByteString -> Map ByteString Object -> Maybe Object
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ByteString
key Map ByteString Object
m of
                Just Object
o -> Object -> Either (Doc AnsiStyle) o
forall o. NvimObject o => Object -> Either (Doc AnsiStyle) o
fromObject Object
o
                Maybe Object
Nothing -> Doc AnsiStyle -> Either (Doc AnsiStyle) o
forall a. Doc AnsiStyle -> Either (Doc AnsiStyle) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Doc AnsiStyle -> Either (Doc AnsiStyle) o)
-> Doc AnsiStyle -> Either (Doc AnsiStyle) o
forall a b. (a -> b) -> a -> b
$ Doc AnsiStyle
"Key not found."
        Either Int strType
bufOrFile <- case (ByteString -> Either (Doc AnsiStyle) Int
forall o. NvimObject o => ByteString -> Either (Doc AnsiStyle) o
l ByteString
"bufnr", ByteString -> Either (Doc AnsiStyle) strType
forall o. NvimObject o => ByteString -> Either (Doc AnsiStyle) o
l ByteString
"filename") of
            (Right Int
b, Either (Doc AnsiStyle) strType
_) -> Either Int strType -> Either (Doc AnsiStyle) (Either Int strType)
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either Int strType -> Either (Doc AnsiStyle) (Either Int strType))
-> Either Int strType
-> Either (Doc AnsiStyle) (Either Int strType)
forall a b. (a -> b) -> a -> b
$ Int -> Either Int strType
forall a b. a -> Either a b
Left Int
b
            (Either (Doc AnsiStyle) Int
_, Right strType
f) -> Either Int strType -> Either (Doc AnsiStyle) (Either Int strType)
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either Int strType -> Either (Doc AnsiStyle) (Either Int strType))
-> Either Int strType
-> Either (Doc AnsiStyle) (Either Int strType)
forall a b. (a -> b) -> a -> b
$ strType -> Either Int strType
forall a b. b -> Either a b
Right strType
f
            (Either (Doc AnsiStyle) Int, Either (Doc AnsiStyle) strType)
_ -> Doc AnsiStyle -> Either (Doc AnsiStyle) (Either Int strType)
forall a. Doc AnsiStyle -> Either (Doc AnsiStyle) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Doc AnsiStyle -> Either (Doc AnsiStyle) (Either Int strType))
-> Doc AnsiStyle -> Either (Doc AnsiStyle) (Either Int strType)
forall a b. (a -> b) -> a -> b
$ Doc AnsiStyle
"No buffer number or file name inside quickfix list item."
        Either Int strType
lnumOrPattern <- case (ByteString -> Either (Doc AnsiStyle) Int
forall o. NvimObject o => ByteString -> Either (Doc AnsiStyle) o
l ByteString
"lnum", ByteString -> Either (Doc AnsiStyle) strType
forall o. NvimObject o => ByteString -> Either (Doc AnsiStyle) o
l ByteString
"pattern") of
            (Right Int
lnum, Either (Doc AnsiStyle) strType
_) -> Either Int strType -> Either (Doc AnsiStyle) (Either Int strType)
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either Int strType -> Either (Doc AnsiStyle) (Either Int strType))
-> Either Int strType
-> Either (Doc AnsiStyle) (Either Int strType)
forall a b. (a -> b) -> a -> b
$ Int -> Either Int strType
forall a b. a -> Either a b
Left Int
lnum
            (Either (Doc AnsiStyle) Int
_, Right strType
pat) -> Either Int strType -> Either (Doc AnsiStyle) (Either Int strType)
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either Int strType -> Either (Doc AnsiStyle) (Either Int strType))
-> Either Int strType
-> Either (Doc AnsiStyle) (Either Int strType)
forall a b. (a -> b) -> a -> b
$ strType -> Either Int strType
forall a b. b -> Either a b
Right strType
pat
            (Either (Doc AnsiStyle) Int, Either (Doc AnsiStyle) strType)
_ -> Doc AnsiStyle -> Either (Doc AnsiStyle) (Either Int strType)
forall a. Doc AnsiStyle -> Either (Doc AnsiStyle) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Doc AnsiStyle -> Either (Doc AnsiStyle) (Either Int strType))
-> Doc AnsiStyle -> Either (Doc AnsiStyle) (Either Int strType)
forall a b. (a -> b) -> a -> b
$ Doc AnsiStyle
"No line number or search pattern inside quickfix list item."
        let l' :: NvimObject o => ByteString -> Either (Doc AnsiStyle) (Maybe o)
            l' :: forall o.
NvimObject o =>
ByteString -> Either (Doc AnsiStyle) (Maybe o)
l' ByteString
key = case ByteString -> Map ByteString Object -> Maybe Object
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ByteString
key Map ByteString Object
m of
                Just Object
o -> o -> Maybe o
forall a. a -> Maybe a
Just (o -> Maybe o)
-> Either (Doc AnsiStyle) o -> Either (Doc AnsiStyle) (Maybe o)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> Either (Doc AnsiStyle) o
forall o. NvimObject o => Object -> Either (Doc AnsiStyle) o
fromObject Object
o
                Maybe Object
Nothing -> Maybe o -> Either (Doc AnsiStyle) (Maybe o)
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe o
forall a. Maybe a
Nothing
        Maybe Int
nr <-
            ByteString -> Either (Doc AnsiStyle) (Maybe Int)
forall o.
NvimObject o =>
ByteString -> Either (Doc AnsiStyle) (Maybe o)
l' ByteString
"nr" Either (Doc AnsiStyle) (Maybe Int)
-> (Maybe Int -> Either (Doc AnsiStyle) (Maybe Int))
-> Either (Doc AnsiStyle) (Maybe Int)
forall a b.
Either (Doc AnsiStyle) a
-> (a -> Either (Doc AnsiStyle) b) -> Either (Doc AnsiStyle) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
                Just Int
0 -> Maybe Int -> Either (Doc AnsiStyle) (Maybe Int)
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Int
forall a. Maybe a
Nothing
                Maybe Int
nr' -> Maybe Int -> Either (Doc AnsiStyle) (Maybe Int)
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Int
nr'
        Maybe Int
c <- ByteString -> Either (Doc AnsiStyle) (Maybe Int)
forall o.
NvimObject o =>
ByteString -> Either (Doc AnsiStyle) (Maybe o)
l' ByteString
"col"
        Maybe Bool
v <- ByteString -> Either (Doc AnsiStyle) (Maybe Bool)
forall o.
NvimObject o =>
ByteString -> Either (Doc AnsiStyle) (Maybe o)
l' ByteString
"vcol"
        let col :: ColumnNumber
col = ColumnNumber -> Maybe ColumnNumber -> ColumnNumber
forall a. a -> Maybe a -> a
fromMaybe ColumnNumber
NoColumn (Maybe ColumnNumber -> ColumnNumber)
-> Maybe ColumnNumber -> ColumnNumber
forall a b. (a -> b) -> a -> b
$ do
                Int
c' <- Maybe Int
c
                Bool
v' <- Maybe Bool
v
                case (Int
c', Bool
v') of
                    (Int
0, Bool
_) -> ColumnNumber -> Maybe ColumnNumber
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ColumnNumber
NoColumn
                    (Int
_, Bool
True) -> ColumnNumber -> Maybe ColumnNumber
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (ColumnNumber -> Maybe ColumnNumber)
-> ColumnNumber -> Maybe ColumnNumber
forall a b. (a -> b) -> a -> b
$ Int -> ColumnNumber
VisualColumn Int
c'
                    (Int
_, Bool
False) -> ColumnNumber -> Maybe ColumnNumber
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (ColumnNumber -> Maybe ColumnNumber)
-> ColumnNumber -> Maybe ColumnNumber
forall a b. (a -> b) -> a -> b
$ Int -> ColumnNumber
ByteIndexColumn Int
c'
        strType
text <- strType -> Maybe strType -> strType
forall a. a -> Maybe a -> a
fromMaybe strType
forall a. Monoid a => a
mempty (Maybe strType -> strType)
-> Either (Doc AnsiStyle) (Maybe strType)
-> Either (Doc AnsiStyle) strType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Either (Doc AnsiStyle) (Maybe strType)
forall o.
NvimObject o =>
ByteString -> Either (Doc AnsiStyle) (Maybe o)
l' ByteString
"text"
        QuickfixErrorType
errorType <- QuickfixErrorType -> Maybe QuickfixErrorType -> QuickfixErrorType
forall a. a -> Maybe a -> a
fromMaybe QuickfixErrorType
Error (Maybe QuickfixErrorType -> QuickfixErrorType)
-> Either (Doc AnsiStyle) (Maybe QuickfixErrorType)
-> Either (Doc AnsiStyle) QuickfixErrorType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Either (Doc AnsiStyle) (Maybe QuickfixErrorType)
forall o.
NvimObject o =>
ByteString -> Either (Doc AnsiStyle) (Maybe o)
l' ByteString
"type"
        QuickfixListItem strType
-> Either (Doc AnsiStyle) (QuickfixListItem strType)
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return QFItem{strType
Maybe Int
Either Int strType
QuickfixErrorType
ColumnNumber
bufOrFile :: Either Int strType
lnumOrPattern :: Either Int strType
col :: ColumnNumber
nr :: Maybe Int
text :: strType
errorType :: QuickfixErrorType
bufOrFile :: Either Int strType
lnumOrPattern :: Either Int strType
nr :: Maybe Int
col :: ColumnNumber
text :: strType
errorType :: QuickfixErrorType
..}
    fromObject Object
o =
        Doc AnsiStyle -> Either (Doc AnsiStyle) (QuickfixListItem strType)
forall a. Doc AnsiStyle -> Either (Doc AnsiStyle) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Doc AnsiStyle
 -> Either (Doc AnsiStyle) (QuickfixListItem strType))
-> Doc AnsiStyle
-> Either (Doc AnsiStyle) (QuickfixListItem strType)
forall a b. (a -> b) -> a -> b
$
            Doc AnsiStyle
"Could not deserialize QuickfixListItem,"
                Doc AnsiStyle -> Doc AnsiStyle -> Doc AnsiStyle
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc AnsiStyle
"expected a map but received:"
                Doc AnsiStyle -> Doc AnsiStyle -> Doc AnsiStyle
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Object -> Doc AnsiStyle
forall a ann. Show a => a -> Doc ann
viaShow Object
o

data QuickfixAction
    = -- | Add items to the current list (or create a new one if none exists).
      Append
    | -- | Replace current list (or create a new one if none exists).
      Replace
    | -- | Create a new list.
      New
    deriving (QuickfixAction -> QuickfixAction -> Bool
(QuickfixAction -> QuickfixAction -> Bool)
-> (QuickfixAction -> QuickfixAction -> Bool) -> Eq QuickfixAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: QuickfixAction -> QuickfixAction -> Bool
== :: QuickfixAction -> QuickfixAction -> Bool
$c/= :: QuickfixAction -> QuickfixAction -> Bool
/= :: QuickfixAction -> QuickfixAction -> Bool
Eq, Eq QuickfixAction
Eq QuickfixAction =>
(QuickfixAction -> QuickfixAction -> Ordering)
-> (QuickfixAction -> QuickfixAction -> Bool)
-> (QuickfixAction -> QuickfixAction -> Bool)
-> (QuickfixAction -> QuickfixAction -> Bool)
-> (QuickfixAction -> QuickfixAction -> Bool)
-> (QuickfixAction -> QuickfixAction -> QuickfixAction)
-> (QuickfixAction -> QuickfixAction -> QuickfixAction)
-> Ord QuickfixAction
QuickfixAction -> QuickfixAction -> Bool
QuickfixAction -> QuickfixAction -> Ordering
QuickfixAction -> QuickfixAction -> QuickfixAction
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: QuickfixAction -> QuickfixAction -> Ordering
compare :: QuickfixAction -> QuickfixAction -> Ordering
$c< :: QuickfixAction -> QuickfixAction -> Bool
< :: QuickfixAction -> QuickfixAction -> Bool
$c<= :: QuickfixAction -> QuickfixAction -> Bool
<= :: QuickfixAction -> QuickfixAction -> Bool
$c> :: QuickfixAction -> QuickfixAction -> Bool
> :: QuickfixAction -> QuickfixAction -> Bool
$c>= :: QuickfixAction -> QuickfixAction -> Bool
>= :: QuickfixAction -> QuickfixAction -> Bool
$cmax :: QuickfixAction -> QuickfixAction -> QuickfixAction
max :: QuickfixAction -> QuickfixAction -> QuickfixAction
$cmin :: QuickfixAction -> QuickfixAction -> QuickfixAction
min :: QuickfixAction -> QuickfixAction -> QuickfixAction
Ord, Int -> QuickfixAction
QuickfixAction -> Int
QuickfixAction -> [QuickfixAction]
QuickfixAction -> QuickfixAction
QuickfixAction -> QuickfixAction -> [QuickfixAction]
QuickfixAction
-> QuickfixAction -> QuickfixAction -> [QuickfixAction]
(QuickfixAction -> QuickfixAction)
-> (QuickfixAction -> QuickfixAction)
-> (Int -> QuickfixAction)
-> (QuickfixAction -> Int)
-> (QuickfixAction -> [QuickfixAction])
-> (QuickfixAction -> QuickfixAction -> [QuickfixAction])
-> (QuickfixAction -> QuickfixAction -> [QuickfixAction])
-> (QuickfixAction
    -> QuickfixAction -> QuickfixAction -> [QuickfixAction])
-> Enum QuickfixAction
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: QuickfixAction -> QuickfixAction
succ :: QuickfixAction -> QuickfixAction
$cpred :: QuickfixAction -> QuickfixAction
pred :: QuickfixAction -> QuickfixAction
$ctoEnum :: Int -> QuickfixAction
toEnum :: Int -> QuickfixAction
$cfromEnum :: QuickfixAction -> Int
fromEnum :: QuickfixAction -> Int
$cenumFrom :: QuickfixAction -> [QuickfixAction]
enumFrom :: QuickfixAction -> [QuickfixAction]
$cenumFromThen :: QuickfixAction -> QuickfixAction -> [QuickfixAction]
enumFromThen :: QuickfixAction -> QuickfixAction -> [QuickfixAction]
$cenumFromTo :: QuickfixAction -> QuickfixAction -> [QuickfixAction]
enumFromTo :: QuickfixAction -> QuickfixAction -> [QuickfixAction]
$cenumFromThenTo :: QuickfixAction
-> QuickfixAction -> QuickfixAction -> [QuickfixAction]
enumFromThenTo :: QuickfixAction
-> QuickfixAction -> QuickfixAction -> [QuickfixAction]
Enum, QuickfixAction
QuickfixAction -> QuickfixAction -> Bounded QuickfixAction
forall a. a -> a -> Bounded a
$cminBound :: QuickfixAction
minBound :: QuickfixAction
$cmaxBound :: QuickfixAction
maxBound :: QuickfixAction
Bounded, Int -> QuickfixAction -> ShowS
[QuickfixAction] -> ShowS
QuickfixAction -> String
(Int -> QuickfixAction -> ShowS)
-> (QuickfixAction -> String)
-> ([QuickfixAction] -> ShowS)
-> Show QuickfixAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> QuickfixAction -> ShowS
showsPrec :: Int -> QuickfixAction -> ShowS
$cshow :: QuickfixAction -> String
show :: QuickfixAction -> String
$cshowList :: [QuickfixAction] -> ShowS
showList :: [QuickfixAction] -> ShowS
Show, (forall x. QuickfixAction -> Rep QuickfixAction x)
-> (forall x. Rep QuickfixAction x -> QuickfixAction)
-> Generic QuickfixAction
forall x. Rep QuickfixAction x -> QuickfixAction
forall x. QuickfixAction -> Rep QuickfixAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. QuickfixAction -> Rep QuickfixAction x
from :: forall x. QuickfixAction -> Rep QuickfixAction x
$cto :: forall x. Rep QuickfixAction x -> QuickfixAction
to :: forall x. Rep QuickfixAction x -> QuickfixAction
Generic)

instance NFData QuickfixAction

instance NvimObject QuickfixAction where
    toObject :: QuickfixAction -> Object
toObject = \case
        QuickfixAction
Append -> ByteString -> Object
ObjectBinary ByteString
"a"
        QuickfixAction
Replace -> ByteString -> Object
ObjectBinary ByteString
"r"
        QuickfixAction
New -> ByteString -> Object
ObjectBinary ByteString
""

    fromObject :: Object -> Either (Doc AnsiStyle) QuickfixAction
fromObject Object
o = case Object -> Either (Doc AnsiStyle) ByteString
forall o. NvimObject o => Object -> Either (Doc AnsiStyle) o
fromObject Object
o of
        Right ByteString
"a" -> QuickfixAction -> Either (Doc AnsiStyle) QuickfixAction
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return QuickfixAction
Append
        Right ByteString
"r" -> QuickfixAction -> Either (Doc AnsiStyle) QuickfixAction
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return QuickfixAction
Replace
        Right ByteString
s | (Word8 -> Bool) -> ByteString -> Bool
BS.all (Word8 -> ByteString -> Bool
`BS.elem` ByteString
" \t\n\r") ByteString
s -> QuickfixAction -> Either (Doc AnsiStyle) QuickfixAction
forall a. a -> Either (Doc AnsiStyle) a
forall (m :: * -> *) a. Monad m => a -> m a
return QuickfixAction
New
        Either (Doc AnsiStyle) ByteString
_ -> Doc AnsiStyle -> Either (Doc AnsiStyle) QuickfixAction
forall a b. a -> Either a b
Left Doc AnsiStyle
"Could not convert to QuickfixAction"