nvim_oxi_api/opts/
decoration_provider.rs1use types::Object;
2
3use crate::ToFunction;
4use crate::{Buffer, Window};
5
6pub type OnBufArgs = (
10 String, Buffer, );
13
14pub type OnEndArgs = (
17 String, u32, );
20
21pub type OnLineArgs = (
24 String, Window, Buffer, usize, );
29
30pub type OnStartArgs = (
33 String, u32, u32, );
37
38pub type OnWinArgs = (
41 String, Window, Buffer, u32, u32, );
47
48pub type DontSkipRedrawCycle = bool;
51
52pub type DontSkipOnLines = bool;
55
56#[cfg(not(feature = "neovim-0-10"))] #[derive(Clone, Debug, Default)]
60#[repr(C)]
61pub struct DecorationProviderOpts {
62 on_buf: Object,
63 on_end: Object,
64 on_win: Object,
65 on_line: Object,
66 on_start: Object,
67 _on_hl_def: Object,
68 _on_spell_nav: Object,
69}
70
71#[cfg(feature = "neovim-0-10")] #[derive(Clone, Debug, Default)]
75#[repr(C)]
76pub struct DecorationProviderOpts {
77 on_start: Object,
78 on_buf: Object,
79 on_win: Object,
80 on_line: Object,
81 on_end: Object,
82 _on_hl_def: Object,
83 _on_spell_nav: Object,
84}
85
86impl DecorationProviderOpts {
87 #[inline(always)]
88 pub fn builder() -> DecorationProviderOptsBuilder {
90 DecorationProviderOptsBuilder::default()
91 }
92}
93
94#[derive(Clone, Default)]
95pub struct DecorationProviderOptsBuilder(DecorationProviderOpts);
96
97impl DecorationProviderOptsBuilder {
98 #[inline]
99 pub fn on_buf<F>(&mut self, fun: F) -> &mut Self
100 where
101 F: ToFunction<OnBufArgs, ()>,
102 {
103 self.0.on_buf = Object::from_luaref(fun.into_luaref());
104 self
105 }
106
107 #[inline]
108 pub fn on_end<F>(&mut self, fun: F) -> &mut Self
109 where
110 F: ToFunction<OnEndArgs, ()>,
111 {
112 self.0.on_end = Object::from_luaref(fun.into_luaref());
113 self
114 }
115
116 #[inline]
117 pub fn on_line<F>(&mut self, fun: F) -> &mut Self
118 where
119 F: ToFunction<OnLineArgs, ()>,
120 {
121 self.0.on_line = Object::from_luaref(fun.into_luaref());
122 self
123 }
124
125 #[inline]
126 pub fn on_start<F>(&mut self, fun: F) -> &mut Self
127 where
128 F: ToFunction<OnStartArgs, DontSkipRedrawCycle>,
129 {
130 self.0.on_start = Object::from_luaref(fun.into_luaref());
131 self
132 }
133
134 #[inline]
135 pub fn on_win<F>(&mut self, fun: F) -> &mut Self
136 where
137 F: ToFunction<OnWinArgs, DontSkipOnLines>,
138 {
139 self.0.on_win = Object::from_luaref(fun.into_luaref());
140 self
141 }
142
143 #[inline]
144 pub fn build(&mut self) -> DecorationProviderOpts {
145 std::mem::take(&mut self.0)
146 }
147}