Skip to main content

odoo_lsp/
component.rs

1//! [Owl] components.
2//!
3//! [Owl]: https://odoo.github.io/owl/
4
5use tower_lsp_server::ls_types::Range;
6
7use crate::index::{Symbol, SymbolMap, TemplateIndex};
8use crate::template::TemplateName;
9use crate::utils::MinLoc;
10
11pub type ComponentName = Symbol<Component>;
12
13#[derive(Default, Debug)]
14pub struct Component {
15	pub location: Option<MinLoc>,
16	pub subcomponents: Vec<ComponentName>,
17	pub props: SymbolMap<Prop, PropDescriptor>,
18	/// Ancestors whose props are considered part of self.
19	pub ancestors: Vec<ComponentName>,
20	/// Extended as part of normal inheritance.
21	pub extends: Option<ComponentName>,
22	pub template: Option<ComponentTemplate>,
23}
24
25#[derive(Debug)]
26pub enum ComponentTemplate {
27	Name(TemplateName),
28	Inline(Range),
29}
30
31impl Component {
32	pub fn template_location(&self, templates: &TemplateIndex) -> Option<MinLoc> {
33		let template = self.template.as_ref()?;
34		match template {
35			ComponentTemplate::Name(name) => templates.get(name)?.location.clone(),
36			ComponentTemplate::Inline(range) => {
37				let path = self.location.as_ref()?.path;
38				Some(MinLoc { path, range: *range })
39			}
40		}
41	}
42}
43
44#[derive(Debug)]
45pub enum Prop {}
46
47#[derive(Debug, Clone)]
48pub struct PropDescriptor {
49	pub location: MinLoc,
50	pub type_: PropType,
51}
52
53bitflags::bitflags! {
54	#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)]
55	pub struct PropType: u8 {
56		const  Unknown = 0;
57		const Optional = 1 << 0;
58		const   String = 1 << 1;
59		const   Number = 1 << 2;
60		const  Boolean = 1 << 3;
61		const   Object = 1 << 4;
62		const Function = 1 << 5;
63		const    Array = 1 << 6;
64
65		const Any = !0;
66	}
67}