nvim-hs 2.1.0.7 → 2.2.0.0
raw patch · 9 files changed
+48/−47 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Neovim.RPC.FunctionCall: acall' :: NvimObject result => FunctionName -> [Object] -> Neovim env (STM result)
+ Neovim: catchNeovimException :: MonadUnliftIO io => io a -> (NeovimException -> io a) -> io a
+ Neovim.API.ByteString: nvim_buf_call :: Buffer -> Int64 -> forall env. Neovim env Object
+ Neovim.API.ByteString: nvim_buf_del_extmark :: Buffer -> Int64 -> Int64 -> forall env. Neovim env Bool
+ Neovim.API.ByteString: nvim_buf_del_mark :: Buffer -> ByteString -> forall env. Neovim env Bool
+ Neovim.API.ByteString: nvim_buf_delete :: Buffer -> Map ByteString Object -> forall env. Neovim env ()
+ Neovim.API.ByteString: nvim_buf_get_extmark_by_id :: Buffer -> Int64 -> Int64 -> Map ByteString Object -> forall env. Neovim env (Vector Int64)
+ Neovim.API.ByteString: nvim_buf_get_extmarks :: Buffer -> Int64 -> Object -> Object -> Map ByteString Object -> forall env. Neovim env (Vector Object)
+ Neovim.API.ByteString: nvim_buf_set_extmark :: Buffer -> Int64 -> Int64 -> Int64 -> Map ByteString Object -> forall env. Neovim env Int64
+ Neovim.API.ByteString: nvim_buf_set_mark :: Buffer -> ByteString -> Int64 -> Int64 -> Map ByteString Object -> forall env. Neovim env Bool
+ Neovim.API.ByteString: nvim_buf_set_text :: Buffer -> Int64 -> Int64 -> Int64 -> Int64 -> Vector ByteString -> forall env. Neovim env ()
+ Neovim.API.ByteString: nvim_chan_send :: Int64 -> ByteString -> forall env. Neovim env ()
+ Neovim.API.ByteString: nvim_del_mark :: ByteString -> forall env. Neovim env Bool
+ Neovim.API.ByteString: nvim_echo :: Vector Object -> Bool -> Map ByteString Object -> forall env. Neovim env ()
+ Neovim.API.ByteString: nvim_eval_statusline :: ByteString -> Map ByteString Object -> forall env. Neovim env (Map ByteString Object)
+ Neovim.API.ByteString: nvim_exec :: ByteString -> Bool -> forall env. Neovim env ByteString
+ Neovim.API.ByteString: nvim_exec_lua :: ByteString -> Vector Object -> forall env. Neovim env Object
+ Neovim.API.ByteString: nvim_get_all_options_info :: forall env. Neovim env (Map ByteString Object)
+ Neovim.API.ByteString: nvim_get_hl_id_by_name :: ByteString -> forall env. Neovim env Int64
+ Neovim.API.ByteString: nvim_get_mark :: ByteString -> Map ByteString Object -> forall env. Neovim env (Vector Object)
+ Neovim.API.ByteString: nvim_get_option_info :: ByteString -> forall env. Neovim env (Map ByteString Object)
+ Neovim.API.ByteString: nvim_get_runtime_file :: ByteString -> Bool -> forall env. Neovim env (Vector ByteString)
+ Neovim.API.ByteString: nvim_notify :: ByteString -> Int64 -> Map ByteString Object -> forall env. Neovim env Object
+ Neovim.API.ByteString: nvim_open_term :: Buffer -> Map ByteString Object -> forall env. Neovim env Int64
+ Neovim.API.ByteString: nvim_set_decoration_provider :: Int64 -> Map ByteString Object -> forall env. Neovim env ()
+ Neovim.API.ByteString: nvim_set_hl :: Int64 -> ByteString -> Map ByteString Object -> forall env. Neovim env ()
+ Neovim.API.ByteString: nvim_ui_pum_set_bounds :: Double -> Double -> Double -> Double -> forall env. Neovim env ()
+ Neovim.API.ByteString: nvim_win_call :: Window -> Int64 -> forall env. Neovim env Object
+ Neovim.API.ByteString: nvim_win_hide :: Window -> forall env. Neovim env ()
+ Neovim.API.String: nvim_buf_call :: Buffer -> Int64 -> forall env. Neovim env Object
+ Neovim.API.String: nvim_buf_del_extmark :: Buffer -> Int64 -> Int64 -> forall env. Neovim env Bool
+ Neovim.API.String: nvim_buf_del_mark :: Buffer -> String -> forall env. Neovim env Bool
+ Neovim.API.String: nvim_buf_delete :: Buffer -> Map String Object -> forall env. Neovim env ()
+ Neovim.API.String: nvim_buf_get_extmark_by_id :: Buffer -> Int64 -> Int64 -> Map String Object -> forall env. Neovim env [Int64]
+ Neovim.API.String: nvim_buf_get_extmarks :: Buffer -> Int64 -> Object -> Object -> Map String Object -> forall env. Neovim env [Object]
+ Neovim.API.String: nvim_buf_set_extmark :: Buffer -> Int64 -> Int64 -> Int64 -> Map String Object -> forall env. Neovim env Int64
+ Neovim.API.String: nvim_buf_set_mark :: Buffer -> String -> Int64 -> Int64 -> Map String Object -> forall env. Neovim env Bool
+ Neovim.API.String: nvim_buf_set_text :: Buffer -> Int64 -> Int64 -> Int64 -> Int64 -> [String] -> forall env. Neovim env ()
+ Neovim.API.String: nvim_chan_send :: Int64 -> String -> forall env. Neovim env ()
+ Neovim.API.String: nvim_del_mark :: String -> forall env. Neovim env Bool
+ Neovim.API.String: nvim_echo :: [Object] -> Bool -> Map String Object -> forall env. Neovim env ()
+ Neovim.API.String: nvim_eval_statusline :: String -> Map String Object -> forall env. Neovim env (Map String Object)
+ Neovim.API.String: nvim_exec :: String -> Bool -> forall env. Neovim env String
+ Neovim.API.String: nvim_exec_lua :: String -> [Object] -> forall env. Neovim env Object
+ Neovim.API.String: nvim_get_all_options_info :: forall env. Neovim env (Map String Object)
+ Neovim.API.String: nvim_get_hl_id_by_name :: String -> forall env. Neovim env Int64
+ Neovim.API.String: nvim_get_mark :: String -> Map String Object -> forall env. Neovim env [Object]
+ Neovim.API.String: nvim_get_option_info :: String -> forall env. Neovim env (Map String Object)
+ Neovim.API.String: nvim_get_runtime_file :: String -> Bool -> forall env. Neovim env [String]
+ Neovim.API.String: nvim_notify :: String -> Int64 -> Map String Object -> forall env. Neovim env Object
+ Neovim.API.String: nvim_open_term :: Buffer -> Map String Object -> forall env. Neovim env Int64
+ Neovim.API.String: nvim_set_decoration_provider :: Int64 -> Map String Object -> forall env. Neovim env ()
+ Neovim.API.String: nvim_set_hl :: Int64 -> String -> Map String Object -> forall env. Neovim env ()
+ Neovim.API.String: nvim_ui_pum_set_bounds :: Double -> Double -> Double -> Double -> forall env. Neovim env ()
+ Neovim.API.String: nvim_win_call :: Window -> Int64 -> forall env. Neovim env Object
+ Neovim.API.String: nvim_win_hide :: Window -> forall env. Neovim env ()
+ Neovim.API.TH: createFunction :: TypeMap -> NeovimFunction -> Q [Dec]
+ Neovim.API.Text: nvim_buf_call :: Buffer -> Int64 -> forall env. Neovim env Object
+ Neovim.API.Text: nvim_buf_del_extmark :: Buffer -> Int64 -> Int64 -> forall env. Neovim env Bool
+ Neovim.API.Text: nvim_buf_del_mark :: Buffer -> Text -> forall env. Neovim env Bool
+ Neovim.API.Text: nvim_buf_delete :: Buffer -> Map Text Object -> forall env. Neovim env ()
+ Neovim.API.Text: nvim_buf_get_extmark_by_id :: Buffer -> Int64 -> Int64 -> Map Text Object -> forall env. Neovim env (Vector Int64)
+ Neovim.API.Text: nvim_buf_get_extmarks :: Buffer -> Int64 -> Object -> Object -> Map Text Object -> forall env. Neovim env (Vector Object)
+ Neovim.API.Text: nvim_buf_set_extmark :: Buffer -> Int64 -> Int64 -> Int64 -> Map Text Object -> forall env. Neovim env Int64
+ Neovim.API.Text: nvim_buf_set_mark :: Buffer -> Text -> Int64 -> Int64 -> Map Text Object -> forall env. Neovim env Bool
+ Neovim.API.Text: nvim_buf_set_text :: Buffer -> Int64 -> Int64 -> Int64 -> Int64 -> Vector Text -> forall env. Neovim env ()
+ Neovim.API.Text: nvim_chan_send :: Int64 -> Text -> forall env. Neovim env ()
+ Neovim.API.Text: nvim_del_mark :: Text -> forall env. Neovim env Bool
+ Neovim.API.Text: nvim_echo :: Vector Object -> Bool -> Map Text Object -> forall env. Neovim env ()
+ Neovim.API.Text: nvim_eval_statusline :: Text -> Map Text Object -> forall env. Neovim env (Map Text Object)
+ Neovim.API.Text: nvim_exec :: Text -> Bool -> forall env. Neovim env Text
+ Neovim.API.Text: nvim_exec_lua :: Text -> Vector Object -> forall env. Neovim env Object
+ Neovim.API.Text: nvim_get_all_options_info :: forall env. Neovim env (Map Text Object)
+ Neovim.API.Text: nvim_get_hl_id_by_name :: Text -> forall env. Neovim env Int64
+ Neovim.API.Text: nvim_get_mark :: Text -> Map Text Object -> forall env. Neovim env (Vector Object)
+ Neovim.API.Text: nvim_get_option_info :: Text -> forall env. Neovim env (Map Text Object)
+ Neovim.API.Text: nvim_get_runtime_file :: Text -> Bool -> forall env. Neovim env (Vector Text)
+ Neovim.API.Text: nvim_notify :: Text -> Int64 -> Map Text Object -> forall env. Neovim env Object
+ Neovim.API.Text: nvim_open_term :: Buffer -> Map Text Object -> forall env. Neovim env Int64
+ Neovim.API.Text: nvim_set_decoration_provider :: Int64 -> Map Text Object -> forall env. Neovim env ()
+ Neovim.API.Text: nvim_set_hl :: Int64 -> Text -> Map Text Object -> forall env. Neovim env ()
+ Neovim.API.Text: nvim_ui_pum_set_bounds :: Double -> Double -> Double -> Double -> forall env. Neovim env ()
+ Neovim.API.Text: nvim_win_call :: Window -> Int64 -> forall env. Neovim env Object
+ Neovim.API.Text: nvim_win_hide :: Window -> forall env. Neovim env ()
+ Neovim.Exceptions: catchNeovimException :: MonadUnliftIO io => io a -> (NeovimException -> io a) -> io a
- Neovim: ErrorResult :: Object -> NeovimException
+ Neovim: ErrorResult :: Doc AnsiStyle -> Object -> NeovimException
- Neovim.Context: ErrorResult :: Object -> NeovimException
+ Neovim.Context: ErrorResult :: Doc AnsiStyle -> Object -> NeovimException
- Neovim.Exceptions: ErrorResult :: Object -> NeovimException
+ Neovim.Exceptions: ErrorResult :: Doc AnsiStyle -> Object -> NeovimException
Files
- CHANGELOG.md +10/−0
- api binary
- library/Neovim.hs +2/−0
- library/Neovim/API/TH.hs +3/−2
- library/Neovim/Exceptions.hs +11/−6
- library/Neovim/RPC/FunctionCall.hs +2/−32
- nvim-hs.cabal +1/−1
- test-suite/Neovim/API/THSpec.hs +6/−6
- test-suite/Neovim/EmbeddedRPCSpec.hs +13/−0
CHANGELOG.md view
@@ -1,3 +1,13 @@+# 2.2.0.0++* NeovimException are now thrown from (synchronous) remote functions and are no+ longer suppressed with an `error` call that also had a terrible error message.+ A function `catchNeovimException` (specialized `catch`) has been added that + catches these errors. +* The return type of asynchronous functions is now alwas + `STM (Either NeovimException result)` and errors have to be handled by the + caller explicitly.+ # 2.1.0.2 * Exported functions and commands now can have the same name.
api view
binary file changed (25287 → 28544 bytes)
library/Neovim.hs view
@@ -63,6 +63,7 @@ wait', err, errOnInvalidResult,+ catchNeovimException, NeovimException(..), -- * Unsorted exports@@ -107,6 +108,7 @@ ask, asks, err, errOnInvalidResult) import Neovim.Main (neovim)+import Neovim.Exceptions (catchNeovimException) import Neovim.Plugin (addAutocmd) import Neovim.Plugin.Classes (AutocmdOptions (..), CommandArguments (..),
library/Neovim/API/TH.hs view
@@ -20,6 +20,7 @@ stringListTypeMap, textVectorTypeMap, bytestringVectorTypeMap,+ createFunction, module UnliftIO.Exception, module Neovim.Classes, module Data.Data,@@ -172,11 +173,11 @@ createFunction :: TypeMap -> NeovimFunction -> Q [Dec] createFunction typeMap nf = do let withDeferred- | async nf = appT [t|STM|]+ | async nf = appT [t|STM|] . appT [t|Either NeovimException|] | otherwise = id callFn- | async nf = [|acall'|]+ | async nf = [|acall|] | otherwise = [|scall'|] functionName = mkName $ name nf
library/Neovim/Exceptions.hs view
@@ -13,6 +13,7 @@ module Neovim.Exceptions ( NeovimException(..) , exceptionToDoc+ , catchNeovimException ) where import Control.Exception (Exception)@@ -21,15 +22,16 @@ import Data.Text.Prettyprint.Doc (Doc, (<+>), viaShow) import Data.Text.Prettyprint.Doc.Render.Terminal (AnsiStyle) import Data.Typeable (Typeable)+import UnliftIO (MonadUnliftIO, catch) -- | Exceptions specific to /nvim-hs/. data NeovimException = ErrorMessage (Doc AnsiStyle)- -- ^ Simply error message that is passed to neovim. It should currently only+ -- ^ Simple error message that is passed to neovim. It should currently only -- contain one line of text.- | ErrorResult Object- -- ^ Error that can be returned by a remote API call. A call of 'fromObject'- -- on this value could be converted to a value of 'NeovimExceptionGen'.+ | ErrorResult (Doc AnsiStyle) Object+ -- ^ Error that can be returned by a remote API call. The 'Doc' argument is+ -- the name of the remote function that threw this exception. deriving (Typeable, Show) @@ -45,6 +47,9 @@ ErrorMessage e -> "Error message:" <+> e - ErrorResult o ->- "Result representing an error:" <+> viaShow o+ ErrorResult fn o ->+ "Function" <+> fn <+> "has thrown an error:" <+> viaShow o +-- | Specialization of 'catch' for 'NeovimException's.+catchNeovimException :: MonadUnliftIO io => io a -> (NeovimException -> io a) -> io a+catchNeovimException action exceptionHandler = action `catch` exceptionHandler
library/Neovim/RPC/FunctionCall.hs view
@@ -11,7 +11,6 @@ -} module Neovim.RPC.FunctionCall ( acall,- acall', scall, scall', scallThrow,@@ -36,26 +35,6 @@ import Prelude --- | Simply fail and call 'error' in case an unexpected exception is thrown.--- This fails with a runtime exception. It is used by the Template Haskell API--- generator for functions that are defined as not being able to fail. If this--- exception occurs, it is a bug in neovim.-unexpectedException :: String -> err -> a-unexpectedException fn _ = error $- "Function threw an exception even though it was declared not to throw one: "- ++ fn----- | Strip the error result from the function call. This should only be used by--- the Template Haskell API generated code for functions that declare--- themselves as unfailable.-withIgnoredException :: (Functor f)- => FunctionName -- ^ For better error messages- -> f (Either err result)- -> f result-withIgnoredException fn = fmap (either ((unexpectedException . show) fn) id)-- -- | Helper function that concurrently puts a 'Message' in the event queue and returns an 'STM' action that returns the result. acall :: (NvimObject result) => FunctionName@@ -71,20 +50,11 @@ convertObject :: (NvimObject result) => Either Object Object -> Either NeovimException result convertObject = \case- Left e -> Left $ ErrorResult e+ Left e -> Left $ ErrorResult (pretty fn) e Right o -> case fromObject o of Left e -> Left $ ErrorMessage e Right r -> Right r --- | Helper function similar to 'acall' that throws a runtime exception if the--- result is an error object.-acall' :: (NvimObject result)- => FunctionName- -> [Object]- -> Neovim env (STM result)-acall' fn parameters = withIgnoredException fn <$> acall fn parameters-- -- | Call a neovim function synchronously. This function blocks until the -- result is available. scall :: (NvimObject result)@@ -105,7 +75,7 @@ -- | Helper function similar to 'scall' that throws a runtime exception if the -- result is an error object. scall' :: NvimObject result => FunctionName -> [Object] -> Neovim env result-scall' fn = withIgnoredException fn . scall fn+scall' fn = either throwIO pure <=< scall fn -- | Lifted variant of 'atomically'.
nvim-hs.cabal view
@@ -1,5 +1,5 @@ name: nvim-hs-version: 2.1.0.7+version: 2.2.0.0 synopsis: Haskell plugin backend for neovim description: This package provides a plugin provider for neovim. It allows you to write
test-suite/Neovim/API/THSpec.hs view
@@ -37,7 +37,7 @@ describe "calling function without an argument" $ do let EF (Function fname _, testFun) = $(TH.function "TestFunction0" 'testFunction0) Sync it "should have a capitalized prefix" $- fname `shouldBe` (F "TestFunction0")+ fname `shouldBe` F "TestFunction0" it "should return the consant value" $ call testFun [] `shouldReturn` ObjectInt 42@@ -49,7 +49,7 @@ describe "calling testFunction with two arguments" $ do let EF (Function fname _, testFun) = $(function' 'testFunction2) Sync it "should have a capitalized prefix" $- fname `shouldBe` (F "TestFunction2")+ fname `shouldBe` F "TestFunction2" it "should return 2 for proper arguments" $ call testFun [ ObjectNil@@ -73,12 +73,12 @@ describe "generating a command from the two argument test function" $ do let EF (Command fname _, _) = $(command' 'testFunction2) [] it "should capitalize the first character" $- fname `shouldBe` (F "TestFunction2")+ fname `shouldBe` F "TestFunction2" describe "generating the test successor functions" $ do let EF (Function fname _, testFun) = $(function' 'testSucc) Sync it "should be named TestSucc" $- fname `shouldBe` (F "TestSucc")+ fname `shouldBe` F "TestSucc" it "should return the old value + 1" . property $ \x -> call testFun [ObjectInt x] `shouldReturn` ObjectInt (x+1)@@ -86,7 +86,7 @@ describe "calling test function with a map argument" $ do let EF (Function fname _, testFun) = $(TH.function "TestFunctionMap" 'testFunctionMap) Sync it "should capitalize the first letter" $- fname `shouldBe` (F "TestFunctionMap")+ fname `shouldBe` F "TestFunctionMap" it "should fail for the wrong number of arguments" $ call testFun [] `shouldThrow` isNeovimException@@ -107,7 +107,7 @@ let EF (Command cname _, testFun) = $(command' 'testCommandOptArgument) [] defCmdArgs = toObject (def :: CommandArguments) it "should capitalize the first letter" $- cname `shouldBe` (F "TestCommandOptArgument")+ cname `shouldBe` F "TestCommandOptArgument" it "should return \"default\" when passed no argument" $ do call testFun [defCmdArgs] `shouldReturn` toObject ("default" :: String)
test-suite/Neovim/EmbeddedRPCSpec.hs view
@@ -7,6 +7,7 @@ import Neovim import Neovim.API.Text+import Neovim.Context (docToText) import qualified Neovim.Context.Internal as Internal import Neovim.Quickfix import Neovim.RPC.Common@@ -65,3 +66,15 @@ q' <- vim_eval "getqflist()" liftIO $ fromObjectUnsafe q' `shouldBe` [q] + it "throws NeovimException with function that failed as Doc" $ do+ let getUndefinedVariable = withNeovimEmbedded Nothing $ vim_get_var "notDefined"+ getUndefinedVariable `shouldThrow` \case+ ErrorResult f _ -> docToText f == "vim_get_var"+ _ -> False++ it "catches" . withNeovimEmbedded Nothing $ do+ let getUndefinedVariable = vim_get_var "notDefined"+ functionThatFailed <- getUndefinedVariable `catchNeovimException` \case+ ErrorResult f _ -> pure . toObject $ docToText f+ _ -> pure ObjectNil+ liftIO $ functionThatFailed `shouldBe` toObject ("vim_get_var" :: String)