nvim_api/types/
option_infos.rs

1use nvim_types::{
2    conversion::{self, FromObject},
3    serde::Deserializer,
4    Object,
5};
6use serde::Deserialize;
7
8/// Informations related to an option. Unlike in the Lua API, the `type` field
9/// is omitted because it's included in the definition of `default`.
10#[non_exhaustive]
11#[derive(Clone, Debug, PartialEq, Deserialize)]
12pub struct OptionInfos {
13    /// TODO: docs
14    pub allows_duplicates: bool,
15
16    /// List of comma-separated values.
17    pub commalist: bool,
18
19    /// The default value for the option.
20    pub default: Object,
21
22    /// TODO: docs
23    pub flaglist: bool,
24
25    /// Whether a window or buffer option also has a global value.
26    pub global_local: bool,
27
28    /// Channel id where the option was set (`0` for local).
29    pub last_set_chan: i64,
30
31    /// The line number where the option was set.
32    pub last_set_linenr: usize,
33
34    /// Last set script id (if any).
35    pub last_set_sid: i32,
36
37    /// Name of the option (like `"filetype"`).
38    pub name: String,
39
40    /// Scope of the option.
41    pub scope: OptionScope,
42
43    /// Shortened name of the  option (like `"ft"`).
44    pub shortname: String,
45
46    /// Whether the option was set.
47    pub was_set: bool,
48}
49
50impl FromObject for OptionInfos {
51    fn from_object(obj: Object) -> Result<Self, conversion::Error> {
52        Self::deserialize(Deserializer::new(obj)).map_err(Into::into)
53    }
54}
55
56#[non_exhaustive]
57#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Deserialize)]
58pub enum OptionScope {
59    #[serde(rename = "buf")]
60    Buffer,
61
62    #[serde(rename = "global")]
63    Global,
64
65    #[serde(rename = "win")]
66    Window,
67}
68
69impl OptionScope {
70    #[inline]
71    pub const fn is_buffer(&self) -> bool {
72        matches!(self, OptionScope::Buffer)
73    }
74
75    #[inline]
76    pub const fn is_global(&self) -> bool {
77        matches!(self, OptionScope::Global)
78    }
79
80    #[inline]
81    pub const fn is_window(&self) -> bool {
82        matches!(self, OptionScope::Window)
83    }
84}