1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/// Options passed to
/// [`Buffer::get_extmarks()`](crate::Buffer::get_extmarks).
#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct GetExtmarksOpts {
    details: types::Object,
    limits: types::Object,
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl GetExtmarksOpts {
    #[inline(always)]
    /// Creates a new [`GetExtmarksOptsBuilder`].
    pub fn builder() -> GetExtmarksOptsBuilder {
        GetExtmarksOptsBuilder::default()
    }
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
#[derive(Clone, Default)]
pub struct GetExtmarksOptsBuilder(GetExtmarksOpts);

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl GetExtmarksOptsBuilder {
    /// Whether to include the extmark's
    /// [`ExtmarkInfos`](crate::types::ExtmarkInfos) as the last element of
    /// the tuples returned by
    /// [`Buffer::get_extmarks()`](crate::Buffer::get_extmarks).
    #[inline]
    pub fn details(&mut self, details: bool) -> &mut Self {
        #[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
        {
            self.0.details = details.into();
        }
        #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
        {
            self.0.details = details;
            self.0.mask |= 0b1001;
        }
        self
    }

    #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
    #[inline]
    pub fn hl_name(&mut self, hl_name: bool) -> &mut Self {
        self.0.hl_name = hl_name;
        self.0.mask |= 0b10001;
        self
    }

    #[inline]
    pub fn limits(&mut self, limits: bool) -> &mut Self {
        #[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
        {
            self.0.limits = limits.into();
        }
        #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
        {
            self.0.limits = limits as Integer;
            self.0.mask |= 0b101;
        }
        self
    }

    #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
    #[inline]
    pub fn overlap(&mut self, overlap: bool) -> &mut Self {
        self.0.overlap = overlap;
        self.0.mask |= 0b100001;
        self
    }

    #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
    #[inline]
    pub fn ty<S: Into<nvim::String>>(&mut self, ty: S) -> &mut Self {
        self.0.ty = ty.into();
        self.0.mask |= 0b11;
        self
    }

    /// Maximum number of extmarks to return.
    #[inline]
    pub fn build(&mut self) -> GetExtmarksOpts {
        std::mem::take(&mut self.0)
    }
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl From<&GetExtmarksOpts> for types::Dictionary {
    fn from(opts: &GetExtmarksOpts) -> Self {
        Self::from_iter([
            ("details", opts.details.clone()),
            ("limits", opts.limits.clone()),
        ])
    }
}

#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
#[derive(Clone, Debug, Default, macros::OptsBuilder)]
#[repr(C)]
/// Options passed to
/// [`Buffer::get_extmarks()`](crate::Buffer::get_extmarks).
pub struct GetExtmarksOpts {
    #[builder(mask)]
    mask: u64,

    #[builder(
        method = "limits",
        argtype = "bool",
        inline = "{0} as types::Integer"
    )]
    limit: types::Integer,

    /// Whether to include the extmark's
    /// [`ExtmarkInfos`](crate::types::ExtmarkInfos) as the last element of
    /// the tuples returned by
    /// [`Buffer::get_extmarks()`](crate::Buffer::get_extmarks).
    #[builder(argtype = "bool")]
    details: types::Boolean,

    #[builder(argtype = "bool")]
    hl_name: types::Boolean,

    #[builder(argtype = "bool")]
    overlap: types::Boolean,

    // TODO: fix `Into`.
    // TODO: name it `type` instead of `ty`.
    // #[builder(Into)]
    #[builder(
        generics = "S: Into<types::String>",
        argtype = "S",
        inline = "{0}.into()"
    )]
    ty: types::String,
}