1use types::{Array, Integer};
2
3use crate::trait_utils::StringOrListOfStrings;
4#[cfg(feature = "neovim-0-11")] use crate::types::VirtLinesOverflow;
6use crate::types::{ExtmarkHlMode, ExtmarkVirtTextPosition};
7
8#[derive(Clone, Debug, Default, macros::OptsBuilder)]
10#[repr(C)]
11pub struct SetExtmarkOpts {
12 #[builder(mask)]
13 mask: u64,
14
15 #[builder(argtype = "u32", inline = "{0} as types::Integer")]
17 id: types::Integer,
18
19 #[builder(argtype = "u32", inline = "{0} as types::Integer")]
20 end_line: types::Integer,
21
22 #[builder(argtype = "usize", inline = "{0} as types::Integer")]
24 end_row: types::Integer,
25
26 #[builder(argtype = "usize", inline = "{0} as types::Integer")]
28 end_col: types::Integer,
29
30 #[cfg(not(feature = "neovim-0-11"))] #[cfg_attr(docsrs, doc(cfg(not(feature = "neovim-0-11"))))]
33 #[builder(
34 generics = "Hl: crate::HlGroup",
35 argtype = "Hl",
36 inline = r#"{ let Ok(hl_id) = {0}.to_hl_id() else { return self; }; hl_id }"#
37 )]
38 hl_group: types::HlGroupId,
39
40 #[cfg(feature = "neovim-0-11")] #[cfg_attr(docsrs, doc(cfg(feature = "neovim-0-11")))]
43 #[builder(
44 generics = "Hl: crate::SetExtmarkHlGroup",
45 argtype = "Hl",
46 inline = r#"{0}.into_object()"#
47 )]
48 hl_group: types::Object,
49
50 #[builder(
57 generics = r#"Txt: Into<types::String>, Hl: StringOrListOfStrings, Cnk: IntoIterator<Item = (Txt, Hl)>"#,
58 argtype = "Cnk",
59 setter = "set_virt_text"
60 )]
61 virt_text: types::Array,
62
63 #[builder(
65 argtype = "ExtmarkVirtTextPosition",
66 inline = "types::String::from({0})"
67 )]
68 virt_text_pos: types::String,
69
70 #[builder(argtype = "u32", inline = "{0} as types::Integer")]
73 virt_text_win_col: Integer,
74
75 #[builder(argtype = "bool")]
78 virt_text_hide: types::Boolean,
79
80 #[builder(argtype = "bool")]
82 virt_text_repeat_linebreak: types::Boolean,
83
84 #[builder(argtype = "bool")]
87 hl_eol: types::Boolean,
88
89 #[builder(argtype = "ExtmarkHlMode", inline = "types::String::from({0})")]
91 hl_mode: types::String,
92
93 #[builder(argtype = "bool")]
94 invalidate: types::Boolean,
95
96 #[builder(argtype = "bool")]
101 ephemeral: types::Boolean,
102
103 #[builder(argtype = "u32", inline = "{0} as types::Integer")]
106 priority: Integer,
107
108 #[builder(argtype = "bool")]
111 right_gravity: types::Boolean,
112
113 #[builder(argtype = "bool")]
117 end_right_gravity: types::Boolean,
118
119 #[builder(
121 generics = r#"Txt: Into<types::String>, Hl: StringOrListOfStrings, Cnk: IntoIterator<Item = (Txt, Hl)>, ChunkyCnk: IntoIterator<Item = Cnk>"#,
122 argtype = "ChunkyCnk",
123 setter = "set_virt_lines"
124 )]
125 virt_lines: types::Array,
126
127 #[builder(argtype = "bool")]
130 virt_lines_above: types::Boolean,
131
132 #[builder(argtype = "bool")]
135 virt_lines_leftcol: types::Boolean,
136
137 #[cfg_attr(docsrs, doc(cfg(feature = "neovim-0-11")))]
139 #[cfg(feature = "neovim-0-11")] #[builder(argtype = "VirtLinesOverflow", inline = "{0}.into()")]
141 virt_lines_overflow: types::String,
142
143 #[builder(argtype = "bool")]
147 strict: types::Boolean,
148
149 #[builder(argtype = "&str", inline = "types::String::from({0})")]
151 sign_text: types::String,
152
153 #[builder(
155 generics = "Hl: crate::HlGroup",
156 argtype = "Hl",
157 inline = r#"{ let Ok(hl_id) = {0}.to_hl_id() else { return self; }; hl_id }"#
158 )]
159 sign_hl_group: types::HlGroupId,
160
161 #[builder(
163 generics = "Hl: crate::HlGroup",
164 argtype = "Hl",
165 inline = r#"{ let Ok(hl_id) = {0}.to_hl_id() else { return self; }; hl_id }"#
166 )]
167 number_hl_group: types::HlGroupId,
168
169 #[builder(
171 generics = "Hl: crate::HlGroup",
172 argtype = "Hl",
173 inline = r#"{ let Ok(hl_id) = {0}.to_hl_id() else { return self; }; hl_id }"#
174 )]
175 line_hl_group: types::HlGroupId,
176
177 #[builder(
180 generics = "Hl: crate::HlGroup",
181 argtype = "Hl",
182 inline = r#"{ let Ok(hl_id) = {0}.to_hl_id() else { return self; }; hl_id }"#
183 )]
184 cursorline_hl_group: types::HlGroupId,
185
186 #[builder(
192 argtype = "Option<char>",
193 inline = "{0}.map(types::String::from).unwrap_or_default()"
194 )]
195 conceal: types::String,
196
197 #[cfg_attr(docsrs, doc(cfg(feature = "neovim-0-11")))]
200 #[cfg(feature = "neovim-0-11")] #[builder(argtype = "()", inline = "{let _ = {0}; types::String::new()}")]
202 conceal_lines: types::String,
203
204 #[builder(argtype = "bool")]
205 spell: types::Boolean,
206
207 #[builder(argtype = "bool")]
210 ui_watched: types::Boolean,
211
212 #[builder(argtype = "bool")]
217 undo_restore: types::Boolean,
218
219 #[builder(argtype = "&str", inline = "types::String::from({0})")]
224 url: types::String,
225
226 scoped: types::Boolean,
229}
230
231#[inline]
232fn set_virt_lines<Txt, Hl, Cnk, ChunkyCnk>(
233 field: &mut Array,
234 virt_lines: ChunkyCnk,
235) where
236 ChunkyCnk: IntoIterator<Item = Cnk>,
237 Cnk: IntoIterator<Item = (Txt, Hl)>,
238 Txt: Into<types::String>,
239 Hl: StringOrListOfStrings,
240{
241 *field = virt_lines
242 .into_iter()
243 .map(|chnky| {
244 Array::from_iter(chnky.into_iter().map(|(txt, hl)| {
245 Array::from_iter([txt.into().into(), hl.to_object()])
246 }))
247 })
248 .collect::<Array>();
249}
250
251#[inline]
252fn set_virt_text<Txt, Hl, Cnk>(field: &mut Array, virt_text: Cnk)
253where
254 Cnk: IntoIterator<Item = (Txt, Hl)>,
255 Txt: Into<types::String>,
256 Hl: StringOrListOfStrings,
257{
258 *field = virt_text
259 .into_iter()
260 .map(|(txt, hl)| Array::from_iter([txt.into().into(), hl.to_object()]))
261 .collect::<Array>();
262}