Skip to main content

logicaffeine_web/ui/components/
context_view.rs

1//! Context view panel for Code mode.
2//!
3//! Displays the current proof context including definitions, inductive types,
4//! and their constructors. Organizes entries by category.
5//!
6//! # Props
7//!
8//! - `definitions` - List of term definitions
9//! - `inductives` - List of inductive type definitions
10//!
11//! # Key Types
12//!
13//! - [`ContextEntry`] - A single definition or type in the context
14//! - [`EntryKind`] - Definition, Inductive, or Constructor
15
16use dioxus::prelude::*;
17
18const CONTEXT_VIEW_STYLE: &str = r#"
19.context-view {
20    display: flex;
21    flex-direction: column;
22    height: 100%;
23    background: var(--studio-surface, #12161c);
24    font-family: 'SF Mono', 'Fira Code', monospace;
25}
26
27
28.context-sections {
29    flex: 1;
30    overflow: auto;
31    padding: var(--studio-inset, 12px);
32}
33
34.context-section {
35    margin-bottom: 20px;
36}
37
38/* The list ends at its last section; the panel's own inset is the only space after it. */
39.context-section:last-child {
40    margin-bottom: 0;
41}
42
43.context-section-header {
44    font-size: 11px;
45    font-weight: 600;
46    text-transform: uppercase;
47    letter-spacing: 0.5px;
48    color: rgba(255, 255, 255, 0.4);
49    margin-bottom: 8px;
50    padding-bottom: 4px;
51    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
52}
53
54.context-item {
55    padding: 4px 0;
56    font-size: 12px;
57    line-height: 1.5;
58}
59
60.context-item-name {
61    color: #61afef;
62    font-weight: 500;
63}
64
65.context-item-type {
66    color: rgba(255, 255, 255, 0.6);
67    margin-left: 8px;
68}
69
70.context-item-type::before {
71    content: ": ";
72    color: rgba(255, 255, 255, 0.3);
73}
74
75.context-item-body {
76    margin-top: 4px;
77    padding-top: 4px;
78    border-top: 1px dashed rgba(255, 255, 255, 0.06);
79    color: rgba(255, 255, 255, 0.5);
80    font-size: 11px;
81}
82
83.context-empty {
84    display: flex;
85    flex-direction: column;
86    align-items: center;
87    justify-content: center;
88    height: 100%;
89    color: rgba(255, 255, 255, 0.4);
90    text-align: center;
91    padding: 20px;
92    font-size: 13px;
93}
94
95/* Type keywords highlighting */
96.type-keyword {
97    color: #c678dd;
98}
99
100.type-name {
101    color: #e5c07b;
102}
103
104.type-arrow {
105    color: rgba(255, 255, 255, 0.4);
106}
107"#;
108
109/// A definition entry in the context.
110#[derive(Clone, PartialEq)]
111pub struct ContextEntry {
112    pub name: String,
113    pub ty: String,
114    pub body: Option<String>,
115    pub kind: EntryKind,
116}
117
118#[derive(Clone, Copy, PartialEq)]
119pub enum EntryKind {
120    Definition,
121    Inductive,
122    Constructor,
123}
124
125#[component]
126pub fn ContextView(definitions: Vec<ContextEntry>, inductives: Vec<ContextEntry>) -> Element {
127    rsx! {
128        style { "{CONTEXT_VIEW_STYLE}" }
129
130        div { class: "context-view",
131            // Sections
132            div { class: "context-sections",
133                if definitions.is_empty() && inductives.is_empty() {
134                    div { class: "context-empty",
135                        "No definitions in scope"
136                    }
137                } else {
138                    // Inductive types section
139                    if !inductives.is_empty() {
140                        div { class: "context-section",
141                            div { class: "context-section-header", "Inductive Types" }
142                            for entry in inductives.iter() {
143                                ContextItem {
144                                    key: "{entry.name}",
145                                    entry: entry.clone(),
146                                }
147                            }
148                        }
149                    }
150
151                    // Definitions section
152                    if !definitions.is_empty() {
153                        div { class: "context-section",
154                            div { class: "context-section-header", "Definitions" }
155                            for entry in definitions.iter() {
156                                ContextItem {
157                                    key: "{entry.name}",
158                                    entry: entry.clone(),
159                                }
160                            }
161                        }
162                    }
163                }
164            }
165        }
166    }
167}
168
169#[component]
170fn ContextItem(entry: ContextEntry) -> Element {
171    rsx! {
172        div { class: "context-item",
173            div {
174                span { class: "context-item-name", "{entry.name}" }
175                span { class: "context-item-type", "{entry.ty}" }
176            }
177            if let Some(body) = &entry.body {
178                div { class: "context-item-body", ":= {body}" }
179            }
180        }
181    }
182}