Contribution Guidelines & Code Standards
This guide covers the code standards and conventions used in Glass development.Repository Rules
When using the GitHub CLI:Rust Coding Guidelines
Core Principles
- Prioritize correctness and clarity - Speed and efficiency are secondary unless specified
- Avoid organizational comments - Don’t summarize code. Only comment to explain “why” when it’s tricky or non-obvious
- Prefer existing files - Implement functionality in existing files unless it’s a new logical component
- Never create
mod.rspaths - Usesrc/some_module.rsinstead ofsrc/some_module/mod.rs
Error Handling
Always handle errors appropriately:- Propagate errors with
?when the calling function should handle them - Use
.log_err()or similar when you need to ignore errors but want visibility - Avoid functions that panic like
unwrap()- use?to propagate errors - Be careful with operations like indexing that may panic if indexes are out of bounds
- Ensure async operations propagate errors to the UI layer for meaningful user feedback
Variable Naming
- Use full words for variable names - no abbreviations like “q” for “queue”
- Use variable shadowing to scope clones in async contexts:
Crate Structure
When creating new crates, prefer specifying the library root path inCargo.toml:
GPUI Guidelines
GPUI is Glass’s GPU-accelerated UI framework providing state and concurrency management.Context Types
Context types allow interaction with global state, windows, entities, and system services. They’re typically passed ascx:
App- Root context type, access to global state and entitiesContext<T>- Provided when updating anEntity<T>, dereferences intoAppAsyncApp/AsyncWindowContext- Provided bycx.spawn, can be held across await points
Window
Window provides access to application window state. Passed as window argument before cx. Used for focus management, dispatching actions, drawing, and user input.
Entities
AnEntity<T> is a handle to state of type T:
WeakEntity<T> is a weak handle that may no longer exist. Useful to avoid memory leaks from mutually recursive handles.
Concurrency
All entity and UI rendering occurs on a single foreground thread.Task<R>, a future that can be awaited. If dropped, work is cancelled. To prevent cancellation:
- Await the task in another async context
- Detach with
task.detach()ortask.detach_and_log_err(cx) - Store the task in a field (work stops when struct is dropped)
Task::ready(value).
Timers in Tests
In GPUI tests, prefer GPUI executor timers over
smol::Timer::after(...).run_until_parked().
Elements and Rendering
TheRender trait renders state into an element tree using flexbox layout:
SharedStringavoids copying strings (either&'static strorArc<str>)- Style methods similar to Tailwind CSS
- Use
.when(condition, |this| ...)for conditional attributes - Use
.when_some(option, |this, value| ...)for optional values
RenderOnce trait for components constructed just to become elements:
- Takes ownership of
self - Receives
&mut Appinstead of&mut Context<Self> - Use
#[derive(IntoElement)]to use directly as children
Input Events and Actions
Register input event handlers:Notify and Events
When state changes affect rendering:_subscriptions: Vec<Subscription> field to keep them alive.
Pull Request Standards
When opening or updating a pull request:PR Title
- Use clear, correctly capitalized, imperative format
- Example:
Fix crash in project panel - Avoid conventional commit prefixes (
fix:,feat:,docs:) - No trailing punctuation
- Optionally prefix with crate name when one crate is the clear scope
- Example:
git_ui: Add history view
- Example:
PR Body
Include aRelease Notes: section as the final section:
- Added ...,- Fixed ..., or- Improved ...for user-facing changes- N/Afor docs-only and non-user-facing changes
UI/UX Checklist
When changes affect UI, consult this checklist:Accessibility / Ergonomics
- Do all keyboard shortcuts work as intended?
- Are shortcuts discoverable (tooltips, menus, docs)?
- Do all mouse actions work (drag, context menus, resizing, scrolling)?
- Does the feature look great in light mode and dark mode?
- Are hover states, focus rings, and active states clear and consistent?
- Is it usable without a mouse (keyboard-only navigation)?
Responsiveness
- Does the UI scale gracefully on narrow panes, short panes, and high-DPI displays?
- Does resizing panes or windows keep the UI usable and attractive?
- Do dialogs or modals stay centered and within viewport bounds?
Platform Consistency
- Is the feature fully usable on Windows, Linux, and Mac?
- Does it respect system-level settings (fonts, scaling, input methods)?
Performance
- All user interactions must have instant feedback
- If the user requests something slow (e.g., LLM generation), show work-in-progress indication
- Does it handle large files, big projects, or heavy workloads without degrading?
- Frames must take no more than 8ms (120fps)
Consistency
- Does it match Glass’s design language (spacing, typography, icons)?
- Are terminology, labels, and tone consistent with the rest of Glass?
- Are interactions consistent (how tabs close, modals dismiss, errors show)?
User Paths & Edge Cases
- What does the happy path look like?
- What does the unhappy path look like? (errors, rejections, invalid states)
- How does it work in offline vs. online states?
- How does it work in unauthenticated vs. authenticated states?
- How does it behave if data is missing, corrupted, or delayed?
- Are error messages actionable and consistent with Glass’s voice?
Discoverability & Learning
- Can a first-time user figure it out without docs?
- Is there an intuitive way to undo/redo actions?
- Are power features discoverable but not intrusive?
- Is there a path from beginner to expert usage (progressive disclosure)?
Avoid Creative Additions
Next Steps
Testing Practices
Learn how to write and run tests for Glass