Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvim_buf_get_extmark_by_id has the wrong type when asking for details #106

Open
isovector opened this issue Nov 30, 2022 · 4 comments
Open
Labels
bug upstream workaround Issue has a work around mentioned in the discussion

Comments

@isovector
Copy link
Contributor

isovector commented Nov 30, 2022

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
Copy link
Contributor Author

This is a bug upstream neovim/neovim#21239

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

@saep
Copy link
Member

saep commented Nov 30, 2022

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
Copy link
Contributor Author

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

@saep
Copy link
Member

saep commented Nov 30, 2022

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. ^_^

@saep saep added the workaround Issue has a work around mentioned in the discussion label Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug upstream workaround Issue has a work around mentioned in the discussion
Projects
None yet
Development

No branches or pull requests

2 participants