theme: Turn ThemeRegistry into a trait (#20076)

This PR converts the `ThemeRegistry` type into a trait instead of a
concrete implementation.

This allows for the extension store to depend on an abstraction rather
than the concrete theme registry implementation.

We currently have two `ThemeRegistry` implementations:

- `RealThemeRegistry` — this was previously the `ThemeRegistry` and
contains the real implementation of the registry.
- `VoidThemeRegistry` — a null object that doesn't have any behavior.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-11-01 10:19:09 -04:00 committed by GitHub
parent c04c439d23
commit af9e7f1f96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 184 additions and 118 deletions

View file

@ -114,7 +114,7 @@ pub struct ExtensionStore {
outstanding_operations: BTreeMap<Arc<str>, ExtensionOperation>,
index_path: PathBuf,
language_registry: Arc<LanguageRegistry>,
theme_registry: Arc<ThemeRegistry>,
theme_registry: Arc<dyn ThemeRegistry>,
slash_command_registry: Arc<SlashCommandRegistry>,
indexed_docs_registry: Arc<IndexedDocsRegistry>,
snippet_registry: Arc<SnippetRegistry>,
@ -179,7 +179,7 @@ pub fn init(
client: Arc<Client>,
node_runtime: NodeRuntime,
language_registry: Arc<LanguageRegistry>,
theme_registry: Arc<ThemeRegistry>,
theme_registry: Arc<dyn ThemeRegistry>,
cx: &mut AppContext,
) {
ExtensionSettings::register(cx);
@ -230,7 +230,7 @@ impl ExtensionStore {
telemetry: Option<Arc<Telemetry>>,
node_runtime: NodeRuntime,
language_registry: Arc<LanguageRegistry>,
theme_registry: Arc<ThemeRegistry>,
theme_registry: Arc<dyn ThemeRegistry>,
slash_command_registry: Arc<SlashCommandRegistry>,
indexed_docs_registry: Arc<IndexedDocsRegistry>,
snippet_registry: Arc<SnippetRegistry>,
@ -1358,7 +1358,7 @@ impl ExtensionStore {
continue;
};
let Some(theme_family) = ThemeRegistry::read_user_theme(&theme_path, fs.clone())
let Some(theme_family) = theme::read_user_theme(&theme_path, fs.clone())
.await
.log_err()
else {

View file

@ -27,7 +27,7 @@ use std::{
path::{Path, PathBuf},
sync::Arc,
};
use theme::ThemeRegistry;
use theme::{RealThemeRegistry, ThemeRegistry};
use util::test::temp_tree;
#[cfg(test)]
@ -260,7 +260,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
};
let language_registry = Arc::new(LanguageRegistry::test(cx.executor()));
let theme_registry = Arc::new(ThemeRegistry::new(Box::new(())));
let theme_registry = Arc::new(RealThemeRegistry::new(Box::new(())));
let slash_command_registry = SlashCommandRegistry::new();
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
let snippet_registry = Arc::new(SnippetRegistry::new());
@ -486,7 +486,7 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
let project = Project::test(fs.clone(), [project_dir.as_path()], cx).await;
let language_registry = project.read_with(cx, |project, _cx| project.languages().clone());
let theme_registry = Arc::new(ThemeRegistry::new(Box::new(())));
let theme_registry = Arc::new(RealThemeRegistry::new(Box::new(())));
let slash_command_registry = SlashCommandRegistry::new();
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
let snippet_registry = Arc::new(SnippetRegistry::new());