Fix Nightly (#214)

Tracks https://github.com/neovim/neovim/pull/32098
This commit is contained in:
Riccardo Mazzarini 2025-01-24 13:17:02 +08:00 committed by GitHub
parent 8999e511d3
commit 40ecec656a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 109 additions and 31 deletions

View file

@ -319,6 +319,8 @@ pub struct SetExtmarkOpts {
end_col: types::Integer,
/// Name of the highlight group used to highlight this mark.
#[cfg(not(feature = "neovim-nightly"))] // On 0.9 and 0.10.
#[cfg_attr(docsrs, doc(cfg(not(feature = "neovim-nightly"))))]
#[builder(
generics = "Hl: crate::HlGroup",
argtype = "Hl",
@ -326,6 +328,16 @@ pub struct SetExtmarkOpts {
)]
hl_group: types::HlGroupId,
/// Name of the highlight group used to highlight this mark.
#[cfg(feature = "neovim-nightly")] // Only on Nightly.
#[cfg_attr(docsrs, doc(cfg(feature = "neovim-nightly")))]
#[builder(
generics = "Hl: crate::SetExtmarkHlGroup",
argtype = "Hl",
inline = r#"{0}.into_object()"#
)]
hl_group: types::Object,
/// Virtual text to link to this mark. Every `(text, highlights)` tuple
/// represents a text chunk with a specified highlight. The highlights
/// specified in `highlights` will be combined together, with the highest

View file

@ -175,6 +175,38 @@ impl HlGroup for &str {
}
}
/// A trait implemented by types that can be passed to
/// [`SetExtmarkOptsBuilder::hl_group`](crate::opts::SetExtmarkOptsBuilder::hl_group).
#[cfg(feature = "neovim-nightly")] // Only on Nightly.
#[cfg_attr(docsrs, doc(cfg(feature = "neovim-nightly")))]
pub trait SetExtmarkHlGroup {
fn into_object(self) -> Object;
}
#[cfg(feature = "neovim-nightly")] // Only on Nightly.
impl SetExtmarkHlGroup for Integer {
#[inline]
fn into_object(self) -> Object {
self.into()
}
}
#[cfg(feature = "neovim-nightly")] // Only on Nightly.
impl SetExtmarkHlGroup for &str {
#[inline]
fn into_object(self) -> Object {
self.into()
}
}
#[cfg(feature = "neovim-nightly")] // Only on Nightly.
impl<T: StringOrInt> SetExtmarkHlGroup for Vec<T> {
#[inline]
fn into_object(self) -> Object {
self.into_iter().map(StringOrInt::to_object).collect::<Array>().into()
}
}
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
mod sealed {
pub trait Sealed {}

View file

@ -23,9 +23,16 @@ pub struct ExtmarkInfos {
#[serde(default)]
pub hl_eol: Option<bool>,
#[cfg(not(feature = "neovim-nightly"))] // On 0.9 and 0.10.
#[cfg_attr(docsrs, doc(cfg(not(feature = "neovim-nightly"))))]
#[serde(default)]
pub hl_group: Option<String>,
#[cfg(feature = "neovim-nightly")] // Only on Nightly.
#[cfg_attr(docsrs, doc(cfg(feature = "neovim-nightly")))]
#[serde(default)]
pub hl_group: Option<super::OneOrMore<String>>,
#[serde(default)]
pub hl_mode: Option<ExtmarkHlMode>,

View file

@ -24,3 +24,12 @@ impl From<&str> for OneOrMore<String> {
OneOrMore::One(s.to_owned())
}
}
impl<T: PartialEq> PartialEq<T> for OneOrMore<T> {
fn eq(&self, other: &T) -> bool {
match self {
OneOrMore::One(one) => one == other,
OneOrMore::List(_) => false,
}
}
}