Skip to repository content57 lines · 1.8 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T03:32:35.550Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
settings.rs
1//! Provides access to Zed settings.
2
3#[path = "../wit/since_v0.8.0/settings.rs"]
4mod types;
5
6use crate::{Project, Result, SettingsLocation, Worktree, wit};
7use serde_json;
8pub use types::*;
9
10impl LanguageSettings {
11 /// Returns the [`LanguageSettings`] for the given language.
12 pub fn for_worktree(language: Option<&str>, worktree: &Worktree) -> Result<Self> {
13 get_settings("language", language, Some(worktree.id()))
14 }
15}
16
17impl LspSettings {
18 /// Returns the [`LspSettings`] for the given language server.
19 pub fn for_worktree(language_server_name: &str, worktree: &Worktree) -> Result<Self> {
20 get_settings("lsp", Some(language_server_name), Some(worktree.id()))
21 }
22}
23
24impl ContextServerSettings {
25 /// Returns the [`ContextServerSettings`] for the given context server.
26 pub fn for_project(context_server_id: &str, project: &Project) -> Result<Self> {
27 let global_setting: Self = get_settings("context_servers", Some(context_server_id), None)?;
28
29 for worktree_id in project.worktree_ids() {
30 let settings = get_settings(
31 "context_servers",
32 Some(context_server_id),
33 Some(worktree_id),
34 )?;
35 if settings != global_setting {
36 return Ok(settings);
37 }
38 }
39
40 Ok(global_setting)
41 }
42}
43
44fn get_settings<T: serde::de::DeserializeOwned>(
45 settings_type: &str,
46 settings_name: Option<&str>,
47 worktree_id: Option<u64>,
48) -> Result<T> {
49 let location = worktree_id.map(|worktree_id| SettingsLocation {
50 worktree_id,
51 path: String::new(),
52 });
53 let settings_json = wit::get_settings(location.as_ref(), settings_type, settings_name)?;
54 let settings: T = serde_json::from_str(&settings_json).map_err(|err| err.to_string())?;
55 Ok(settings)
56}
57