Skip to content

Commit

Permalink
Documentation, exports and minor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
saep committed Mar 25, 2018
1 parent 6ab5884 commit be18330
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 75 deletions.
18 changes: 9 additions & 9 deletions library/Neovim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ module Neovim (

ask,
asks,
put,
get,
gets,
modify,

-- ** Creating a stateful plugin
-- $statefulplugin
Expand All @@ -69,8 +65,6 @@ module Neovim (
waitErr,
waitErr',
err,
Doc,
Pretty(..),
errOnInvalidResult,
NeovimException(..),
-- ** Generated functions for neovim interaction
Expand All @@ -85,6 +79,11 @@ module Neovim (
unlessM,
docToObject,
docFromObject,
Doc,
AnsiStyle,
Pretty(..),
putDoc,
exceptionToDoc,
Priority(..),
module Control.Monad,
module Control.Applicative,
Expand All @@ -106,10 +105,12 @@ import Neovim.API.String
import Neovim.API.TH (autocmd, command, command',
function, function')
import Neovim.Classes (Dictionary, NvimObject (..),
Doc, AnsiStyle, Pretty(..),
docFromObject, docToObject, (+:))
import Neovim.Config (NeovimConfig (..))
import Neovim.Context (Neovim,
NeovimException (ErrorMessage),
NeovimException(..),
exceptionToDoc,
ask, asks, err,
errOnInvalidResult, get, gets,
modify, put)
Expand All @@ -128,8 +129,7 @@ import Neovim.RPC.FunctionCall (wait, wait', waitErr, waitErr')
import Neovim.Util (unlessM, whenM,
withCustomEnvironment)
import System.Log.Logger (Priority (..))
import Data.Text.Prettyprint.Doc (Doc, Pretty (..))

import Data.Text.Prettyprint.Doc.Render.Terminal (putDoc)
-- Installation {{{1
{- $installation
Expand Down
1 change: 0 additions & 1 deletion library/Neovim/API/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import qualified Data.ByteString as B
import Data.Map (Map)
import qualified Data.Map as Map
import Data.MessagePack
import Data.Monoid
import Data.Serialize
import Neovim.Compat.Megaparsec as P
import System.IO (hClose)
Expand Down
2 changes: 1 addition & 1 deletion library/Neovim/API/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ data ArgType = StringyType


-- | Given a value of type 'Type', test whether it can be classified according
-- to the constructors of 'ArgType'.
-- to the constructors of "ArgType".
classifyArgType :: Type -> Q ArgType
classifyArgType t = do
set <- genStringTypesSet
Expand Down
57 changes: 29 additions & 28 deletions library/Neovim/Classes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ import Data.Int (Int16, Int32, Int64,
import qualified Data.Map.Strict as SMap
import Data.MessagePack
import Data.Monoid
import Data.String (IsString (..))
import Data.Text as Text (Text)
import Data.Text.Prettyprint.Doc (Doc, Pretty (..),
defaultLayoutOptions,
layoutPretty,
lparen, rparen,
layoutPretty, viaShow,
(<+>))
import qualified Data.Text.Prettyprint.Doc as P
import Data.Text.Prettyprint.Doc.Render.Terminal (AnsiStyle,
Expand All @@ -76,6 +74,9 @@ import Prelude
infixr 5 +:

-- | Convenient operator to create a list of 'Object' from normal values.
-- @
-- values +: of :+ different :+ types :+ can +: be +: combined +: this +: way +: []
-- @
(+:) :: (NvimObject o) => o -> [Object] -> [Object]
o +: os = toObject o : os

Expand Down Expand Up @@ -157,7 +158,7 @@ instance NvimObject Double where
fromObject (ObjectInt o) = return $ fromIntegral o
fromObject (ObjectUInt o) = return $ fromIntegral o
fromObject o = throwError $ "Expected ObjectDouble, but got"
<+> pretty (show o)
<+> viaShow o


instance NvimObject Integer where
Expand All @@ -167,7 +168,7 @@ instance NvimObject Integer where
fromObject (ObjectUInt o) = return $ toInteger o
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected ObjectInt, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectInt, but got" <+> viaShow o


instance NvimObject Int64 where
Expand All @@ -177,7 +178,7 @@ instance NvimObject Int64 where
fromObject (ObjectUInt o) = return $ fromIntegral o
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Int32 where
Expand All @@ -187,7 +188,7 @@ instance NvimObject Int32 where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Int16 where
Expand All @@ -197,7 +198,7 @@ instance NvimObject Int16 where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Int8 where
Expand All @@ -207,7 +208,7 @@ instance NvimObject Int8 where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Word where
Expand All @@ -217,7 +218,7 @@ instance NvimObject Word where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Word64 where
Expand All @@ -227,7 +228,7 @@ instance NvimObject Word64 where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Word32 where
Expand All @@ -237,7 +238,7 @@ instance NvimObject Word32 where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Word16 where
Expand All @@ -247,7 +248,7 @@ instance NvimObject Word16 where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Word8 where
Expand All @@ -257,7 +258,7 @@ instance NvimObject Word8 where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance NvimObject Int where
Expand All @@ -267,22 +268,22 @@ instance NvimObject Int where
fromObject (ObjectUInt i) = return $ fromIntegral i
fromObject (ObjectDouble o) = return $ round o
fromObject (ObjectFloat o) = return $ round o
fromObject o = throwError $ "Expected any Integer value, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected any Integer value, but got" <+> viaShow o


instance {-# OVERLAPPING #-} NvimObject [Char] where
toObject = ObjectBinary . UTF8.fromString

fromObject (ObjectBinary o) = return $ UTF8.toString o
fromObject (ObjectString o) = return $ UTF8.toString o
fromObject o = throwError $ "Expected ObjectString, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectString, but got" <+> viaShow o


instance {-# OVERLAPPABLE #-} NvimObject o => NvimObject [o] where
toObject = ObjectArray . map toObject

fromObject (ObjectArray os) = mapM fromObject os
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o


instance NvimObject o => NvimObject (Maybe o) where
Expand Down Expand Up @@ -320,23 +321,23 @@ instance (Ord key, NvimObject key, NvimObject val)
. (fromObject *** fromObject))
. SMap.toList) om

fromObject o = throwError $ "Expected ObjectMap, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectMap, but got" <+> viaShow o


instance NvimObject Text where
toObject = ObjectBinary . encodeUtf8

fromObject (ObjectBinary o) = return $ decodeUtf8 o
fromObject (ObjectString o) = return $ decodeUtf8 o
fromObject o = throwError $ "Expected ObjectBinary, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectBinary, but got" <+> viaShow o


instance NvimObject ByteString where
toObject = ObjectBinary

fromObject (ObjectBinary o) = return o
fromObject (ObjectString o) = return o
fromObject o = throwError $ "Expected ObjectBinary, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectBinary, but got" <+> viaShow o


instance NvimObject Object where
Expand All @@ -353,7 +354,7 @@ instance (NvimObject o1, NvimObject o2) => NvimObject (o1, o2) where
fromObject (ObjectArray [o1, o2]) = (,)
<$> fromObject o1
<*> fromObject o2
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o

instance (NvimObject o1, NvimObject o2, NvimObject o3) => NvimObject (o1, o2, o3) where
toObject (o1, o2, o3) = ObjectArray $ [toObject o1, toObject o2, toObject o3]
Expand All @@ -362,7 +363,7 @@ instance (NvimObject o1, NvimObject o2, NvimObject o3) => NvimObject (o1, o2, o3
<$> fromObject o1
<*> fromObject o2
<*> fromObject o3
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o


instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4) => NvimObject (o1, o2, o3, o4) where
Expand All @@ -373,7 +374,7 @@ instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4) => NvimObj
<*> fromObject o2
<*> fromObject o3
<*> fromObject o4
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o


instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject o5) => NvimObject (o1, o2, o3, o4, o5) where
Expand All @@ -385,7 +386,7 @@ instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject
<*> fromObject o3
<*> fromObject o4
<*> fromObject o5
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o


instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject o5, NvimObject o6) => NvimObject (o1, o2, o3, o4, o5, o6) where
Expand All @@ -398,7 +399,7 @@ instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject
<*> fromObject o4
<*> fromObject o5
<*> fromObject o6
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o


instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject o5, NvimObject o6, NvimObject o7) => NvimObject (o1, o2, o3, o4, o5, o6, o7) where
Expand All @@ -412,7 +413,7 @@ instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject
<*> fromObject o5
<*> fromObject o6
<*> fromObject o7
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o


instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject o5, NvimObject o6, NvimObject o7, NvimObject o8) => NvimObject (o1, o2, o3, o4, o5, o6, o7, o8) where
Expand All @@ -427,7 +428,7 @@ instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject
<*> fromObject o6
<*> fromObject o7
<*> fromObject o8
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o


instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject o5, NvimObject o6, NvimObject o7, NvimObject o8, NvimObject o9) => NvimObject (o1, o2, o3, o4, o5, o6, o7, o8, o9) where
Expand All @@ -443,7 +444,7 @@ instance (NvimObject o1, NvimObject o2, NvimObject o3, NvimObject o4, NvimObject
<*> fromObject o7
<*> fromObject o8
<*> fromObject o9
fromObject o = throwError $ "Expected ObjectArray, but got" <+> pretty (show o)
fromObject o = throwError $ "Expected ObjectArray, but got" <+> viaShow o


-- 1}}}
6 changes: 1 addition & 5 deletions library/Neovim/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Neovim.Context (

Neovim,
NeovimException(..),
exceptionToDoc,
FunctionMap,
FunctionMapEntry,
mkFunctionMap,
Expand Down Expand Up @@ -63,9 +64,6 @@ import Control.Monad.Reader
import Control.Monad.State
import Data.MessagePack (Object)

import Data.Text.Prettyprint.Doc (Pretty(..), defaultLayoutOptions, layoutPretty)
import Data.Text.Prettyprint.Doc.Render.Text (renderStrict)


-- | @'throw'@ specialized to a 'Pretty' value.
err :: Doc AnsiStyle -> Neovim env a
Expand All @@ -85,8 +83,6 @@ errOnInvalidResult a = a >>= \case

Right x ->
return x
Left o ->
(err . exceptionToDoc) o



Expand Down
4 changes: 1 addition & 3 deletions library/Neovim/Exceptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ module Neovim.Exceptions
import Control.Exception (Exception)
import Data.MessagePack (Object (..))
import Data.String (IsString (..))
import Data.Text (Text)
import Data.Text.Prettyprint.Doc (Doc, Pretty (..),
(<+>), viaShow)
import Data.Text.Prettyprint.Doc (Doc, (<+>), viaShow)
import Data.Text.Prettyprint.Doc.Render.Terminal (AnsiStyle)
import Data.Typeable (Typeable)

Expand Down
1 change: 0 additions & 1 deletion library/Neovim/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe (catMaybes)
import Data.MessagePack
import Data.Text.Prettyprint.Doc (Doc, Pretty (..), viaShow, (<+>))
import Data.Traversable (forM)
import System.Log.Logger
import UnliftIO.Async (Async, async, race)
Expand Down
Loading

0 comments on commit be18330

Please sign in to comment.