diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cd4090..40fce02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ - `nvim_oxi::api::KeymapInfos::buffer` is now an `Option` instead of a `bool` ([#255](https://github.com/noib3/nvim-oxi/pull/255)); +- `nvim_oxi::api::Buffer::get_extmarks()` now takes an + `impl Into` as its first argument instead of a `u32`. + Because `GetExtmarksNamespaceId` implements `From`, this should be an + API-compatible change ([#256](https://github.com/noib3/nvim-oxi/pull/256)); + ### Fixed - fixed the definition of `DecorationProviderOpts`, which was causing diff --git a/crates/api/src/extmark.rs b/crates/api/src/extmark.rs index a818114..6415b2a 100644 --- a/crates/api/src/extmark.rs +++ b/crates/api/src/extmark.rs @@ -195,20 +195,20 @@ impl Buffer { /// was set to `true`. /// /// [1]: https://neovim.io/doc/user/api.html#nvim_buf_get_extmarks() - pub fn get_extmarks( + pub fn get_extmarks>( &self, - ns_id: u32, + ns_id: NsId, start: ExtmarkPosition, end: ExtmarkPosition, opts: &GetExtmarksOpts, ) -> Result< - impl SuperIterator<(u32, usize, usize, Option)> + use<>, + impl SuperIterator<(u32, usize, usize, Option)> + use, > { let mut err = nvim::Error::new(); let extmarks = unsafe { nvim_buf_get_extmarks( self.0, - ns_id as Integer, + ns_id.into().into(), start.into(), end.into(), opts, diff --git a/crates/api/src/types/get_extmarks_namespace_id.rs b/crates/api/src/types/get_extmarks_namespace_id.rs new file mode 100644 index 0000000..4b73e5f --- /dev/null +++ b/crates/api/src/types/get_extmarks_namespace_id.rs @@ -0,0 +1,27 @@ +/// Namespace selector given to +/// [`Buffer::get_extmarks`](crate::Buffer::get_extmarks). +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum GetExtmarksNamespaceId { + /// Get extmarks from all namespaces. + All, + + /// Only get extmarks registered on the namespace with this ID. + Specific(u32), +} + +impl From for GetExtmarksNamespaceId { + #[inline] + fn from(namespace_id: u32) -> Self { + Self::Specific(namespace_id) + } +} + +impl From for types::Integer { + #[inline] + fn from(namespace_id: GetExtmarksNamespaceId) -> Self { + match namespace_id { + GetExtmarksNamespaceId::All => -1, + GetExtmarksNamespaceId::Specific(id) => id as Self, + } + } +} diff --git a/crates/api/src/types/mod.rs b/crates/api/src/types/mod.rs index 66ddd92..c4375b6 100644 --- a/crates/api/src/types/mod.rs +++ b/crates/api/src/types/mod.rs @@ -21,6 +21,7 @@ mod extmark_infos; mod extmark_position; mod extmark_virt_text_chunk; mod extmark_virt_text_position; +mod get_extmarks_namespace_id; mod get_hl_infos; mod got_mode; mod highlight_infos; @@ -73,6 +74,7 @@ pub use extmark_infos::*; pub use extmark_position::*; pub use extmark_virt_text_chunk::*; pub use extmark_virt_text_position::*; +pub use get_extmarks_namespace_id::GetExtmarksNamespaceId; pub use get_hl_infos::GetHlInfos; pub use got_mode::*; pub use highlight_infos::*;