Files
oak-gpui/crates/git_hosting_providers/src/settings.rs
T
fcdab160f9 Settings refactor (#38367)
Co-Authored-By: Ben K <ben@zed.dev>
Co-Authored-By: Anthony <anthony@zed.dev>
Co-Authored-By: Mikayla <mikayla@zed.dev>

Release Notes:

- settings: Major internal changes to settings. The primary user-facing
effect is that some settings which did not make sense in project
settings files are no-longer read from there. (For example the inline
blame settings)

---------

Co-authored-by: Ben Kunkle <ben@zed.dev>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: Anthony <anthony@zed.dev>
2025-09-18 16:47:23 +00:00

75 lines
2.4 KiB
Rust

use std::sync::Arc;
use git::GitHostingProviderRegistry;
use gpui::App;
use settings::{GitHostingProviderConfig, GitHostingProviderKind, Settings, SettingsStore};
use url::Url;
use util::ResultExt as _;
use crate::{Bitbucket, Github, Gitlab};
pub(crate) fn init(cx: &mut App) {
GitHostingProviderSettings::register(cx);
init_git_hosting_provider_settings(cx);
}
fn init_git_hosting_provider_settings(cx: &mut App) {
update_git_hosting_providers_from_settings(cx);
cx.observe_global::<SettingsStore>(update_git_hosting_providers_from_settings)
.detach();
}
fn update_git_hosting_providers_from_settings(cx: &mut App) {
let settings_store = cx.global::<SettingsStore>();
let settings = GitHostingProviderSettings::get_global(cx);
let provider_registry = GitHostingProviderRegistry::global(cx);
let local_values: Vec<GitHostingProviderConfig> = settings_store
.get_all_locals::<GitHostingProviderSettings>()
.into_iter()
.flat_map(|(_, _, providers)| providers.git_hosting_providers.clone())
.collect();
let iter = settings
.git_hosting_providers
.clone()
.into_iter()
.chain(local_values)
.filter_map(|provider| {
let url = Url::parse(&provider.base_url).log_err()?;
Some(match provider.provider {
GitHostingProviderKind::Bitbucket => {
Arc::new(Bitbucket::new(&provider.name, url)) as _
}
GitHostingProviderKind::Github => Arc::new(Github::new(&provider.name, url)) as _,
GitHostingProviderKind::Gitlab => Arc::new(Gitlab::new(&provider.name, url)) as _,
})
});
provider_registry.set_setting_providers(iter);
}
#[derive(Debug, Clone)]
pub struct GitHostingProviderSettings {
pub git_hosting_providers: Vec<GitHostingProviderConfig>,
}
impl Settings for GitHostingProviderSettings {
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
Self {
git_hosting_providers: content.project.git_hosting_providers.clone().unwrap(),
}
}
fn refine(&mut self, content: &settings::SettingsContent, _: &mut App) {
if let Some(more) = &content.project.git_hosting_providers {
self.git_hosting_providers.extend_from_slice(&more.clone());
}
}
fn import_from_vscode(_: &settings::VsCodeSettings, _: &mut settings::SettingsContent) {}
}