neovimhaskell / nvim-hs

Neovim API for Haskell plugins as well as the plugin provider
Other
267 stars 18 forks source link

`nvim_buf_get_extmark_by_id` has the wrong type when asking for details #106

Open isovector opened 1 year ago

isovector commented 1 year ago

When nvim_buf_get_extmark_by_id is called with a map containing {"details ": true}, it also returns the details object. But nvim-hs is expecting to parse the result as Vector Int64, which isn't true :)

The following snippet crashes nvim-hs:

getExtmarkIntervalById :: Int64 -> Buffer -> Int64 -> Neovim env ()
getExtmarkIntervalById ns b x = do
  !z <- fmap V.toList $ nvim_buf_get_extmark_by_id b ns x $ M.singleton "details" $ ObjectBool True
  pure ()

with the error

ErrorMessage Expected any Integer value, but got ObjectMap (fromList [(ObjectString "end_col", ObjectInt 19) ....)])

A better type here I think would be:

nvim_buf_get_extmark_by_id :: Buffer -> Int64 -> Int64 -> Map Text Object -> forall env. Neovim env (Int64, Maybe (Map Text Object))
isovector commented 1 year ago

This is a bug upstream https://github.com/neovim/neovim/issues/21239

Is it something we can work around in nvim-hs in the meantime?

saep commented 1 year ago

You can use the swiss army knife of api functions: nvim_call_function

getExtmarkIntervalById :: Int64 -> Buffer -> Int64 -> Neovim env Object
getExtmarkIntervalById ns b x = do
  !z <- nvim_call_function "nvim_buf_get_extmark_by_id" (b +: ns +: x +: Map.singleton "details" True +: [])
  pure z
isovector commented 1 year ago

Amazing, thanks @saep ! And thanks for being so responsive always!

saep commented 1 year ago

Thank you for your kinds words!

I wonder if I had known to work round this issue in this way if I hadn't added nvim_call_function to the neovim codebase myself. ^_^