Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T02:54:33.557Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

settings.rs

200 lines · 6.0 KB · rust
1mod base_keymap_setting;
2mod content_into_gpui;
3mod editable_setting_control;
4mod editorconfig_store;
5mod keymap_file;
6mod settings_file;
7mod settings_store;
8mod vscode_import;
9
10pub use settings_macros::RegisterSetting;
11
12pub mod settings_content {
13    pub use ::settings_content::*;
14}
15
16pub mod fallible_options {
17    pub use ::settings_content::{FallibleOption, parse_json};
18}
19
20#[doc(hidden)]
21pub mod private {
22    pub use crate::settings_store::{RegisteredSetting, SettingValue};
23    pub use inventory;
24}
25
26use gpui::{App, Global};
27
28use rust_embed::RustEmbed;
29use std::env;
30use std::{borrow::Cow, fmt, str};
31use util::asset_str;
32
33pub use ::settings_content::*;
34pub use base_keymap_setting::*;
35pub use content_into_gpui::IntoGpui;
36pub use editable_setting_control::*;
37pub use editorconfig_store::{
38    Editorconfig, EditorconfigEvent, EditorconfigProperties, EditorconfigStore,
39};
40pub use keymap_file::{
41    KeyBindingValidator, KeyBindingValidatorRegistration, KeybindSource, KeybindUpdateOperation,
42    KeybindUpdateTarget, KeymapFile, KeymapFileLoadResult,
43};
44pub use settings_file::*;
45pub use settings_json::*;
46pub use settings_store::{
47    DefaultSemanticTokenRules, InvalidSettingsError, LSP_SETTINGS_SCHEMA_URL_PREFIX,
48    LocalSettingsKind, LocalSettingsPath, MigrationStatus, Settings, SettingsFile,
49    SettingsJsonSchemaParams, SettingsKey, SettingsLocation, SettingsParseResult, SettingsStore,
50};
51
52pub use vscode_import::{VsCodeSettings, VsCodeSettingsSource};
53
54pub use keymap_file::ActionSequence;
55
56#[derive(Clone, Debug, PartialEq)]
57pub struct ActiveSettingsProfileName(pub String);
58
59impl Global for ActiveSettingsProfileName {}
60
61pub trait UserSettingsContentExt {
62    fn for_profile(&self, cx: &App) -> Option<&SettingsProfile>;
63    fn for_release_channel(&self) -> Option<&SettingsContent>;
64    fn for_os(&self) -> Option<&SettingsContent>;
65}
66
67impl UserSettingsContentExt for UserSettingsContent {
68    fn for_profile(&self, cx: &App) -> Option<&SettingsProfile> {
69        let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
70            return None;
71        };
72        self.profiles.get(&active_profile.0)
73    }
74
75    fn for_release_channel(&self) -> Option<&SettingsContent> {
76        self.release_channel_overrides
77            .get_by_key(release_channel::RELEASE_CHANNEL.dev_name())
78    }
79
80    fn for_os(&self) -> Option<&SettingsContent> {
81        self.platform_overrides.get_by_key(env::consts::OS)
82    }
83}
84
85#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
86pub struct WorktreeId(usize);
87
88impl From<WorktreeId> for usize {
89    fn from(value: WorktreeId) -> Self {
90        value.0
91    }
92}
93
94impl WorktreeId {
95    pub fn from_usize(handle_id: usize) -> Self {
96        Self(handle_id)
97    }
98
99    pub fn from_proto(id: u64) -> Self {
100        Self(id as usize)
101    }
102
103    pub fn to_proto(self) -> u64 {
104        self.0 as u64
105    }
106
107    pub fn to_usize(self) -> usize {
108        self.0
109    }
110}
111
112impl fmt::Display for WorktreeId {
113    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114        std::fmt::Display::fmt(&self.0, f)
115    }
116}
117
118#[derive(RustEmbed)]
119#[folder = "../../assets"]
120#[include = "settings/*"]
121#[include = "keymaps/*"]
122#[exclude = "*.DS_Store"]
123pub struct SettingsAssets;
124
125pub fn init(cx: &mut App) {
126    let settings = SettingsStore::new(cx, &default_settings());
127    cx.set_global(settings);
128    SettingsStore::observe_active_settings_profile_name(cx).detach();
129}
130
131pub fn default_settings() -> Cow<'static, str> {
132    asset_str::<SettingsAssets>("settings/default.json")
133}
134
135pub fn default_semantic_token_rules() -> Cow<'static, str> {
136    asset_str::<SettingsAssets>("settings/default_semantic_token_rules.json")
137}
138
139#[cfg(target_os = "macos")]
140pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-macos.json";
141
142#[cfg(target_os = "windows")]
143pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-windows.json";
144
145#[cfg(not(any(target_os = "macos", target_os = "windows")))]
146pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-linux.json";
147
148pub fn default_keymap() -> Cow<'static, str> {
149    asset_str::<SettingsAssets>(DEFAULT_KEYMAP_PATH)
150}
151
152pub const VIM_KEYMAP_PATH: &str = "keymaps/vim.json";
153
154pub fn vim_keymap() -> Cow<'static, str> {
155    asset_str::<SettingsAssets>(VIM_KEYMAP_PATH)
156}
157
158/// Specific keybinding overrides. Loaded after the base keymap so they win over
159/// conflicting base-keymap (and default `Editor`) bindings for the same chords,
160/// while still allowing user keymaps (loaded last) to override them. Shared
161/// across features - prefer adding a context block here over creating another
162/// override keymap file.
163#[cfg(target_os = "macos")]
164pub const SPECIFIC_OVERRIDES_KEYMAP_PATH: &str = "keymaps/specific-overrides-macos.json";
165
166#[cfg(not(target_os = "macos"))]
167pub const SPECIFIC_OVERRIDES_KEYMAP_PATH: &str = "keymaps/specific-overrides.json";
168
169pub fn initial_user_settings_content() -> Cow<'static, str> {
170    asset_str::<SettingsAssets>("settings/initial_user_settings.json")
171}
172
173pub fn initial_server_settings_content() -> Cow<'static, str> {
174    asset_str::<SettingsAssets>("settings/initial_server_settings.json")
175}
176
177pub fn initial_project_settings_content() -> Cow<'static, str> {
178    asset_str::<SettingsAssets>("settings/initial_local_settings.json")
179}
180
181pub fn initial_keymap_content() -> Cow<'static, str> {
182    asset_str::<SettingsAssets>("keymaps/initial.json")
183}
184
185pub fn initial_tasks_content() -> Cow<'static, str> {
186    asset_str::<SettingsAssets>("settings/initial_tasks.json")
187}
188
189pub fn initial_worktree_setup_tasks_content() -> Cow<'static, str> {
190    asset_str::<SettingsAssets>("settings/initial_worktree_setup_tasks.json")
191}
192
193pub fn initial_debug_tasks_content() -> Cow<'static, str> {
194    asset_str::<SettingsAssets>("settings/initial_debug_tasks.json")
195}
196
197pub fn initial_local_debug_tasks_content() -> Cow<'static, str> {
198    asset_str::<SettingsAssets>("settings/initial_local_debug_tasks.json")
199}
200
Served at tenant.openagents/omega Member data and write actions are omitted.