mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
1cfcdfa7ac
This PR overhauls extension registration in order to make it more modular. The `extension` crate now contains an `ExtensionHostProxy` that can be used to register various proxies that the extension host can use to interact with the rest of the system. There are now a number of different proxy traits representing the various pieces of functionality that can be provided by an extension. The respective crates that provide this functionality can implement their corresponding proxy trait in order to register a proxy that the extension host will use to register the bits of functionality provided by the extension. Release Notes: - N/A
26 lines
701 B
Rust
26 lines
701 B
Rust
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
|
|
use anyhow::Result;
|
|
use extension::{ExtensionHostProxy, ExtensionSnippetProxy};
|
|
use gpui::AppContext;
|
|
|
|
use crate::SnippetRegistry;
|
|
|
|
pub fn init(cx: &mut AppContext) {
|
|
let proxy = ExtensionHostProxy::default_global(cx);
|
|
proxy.register_snippet_proxy(SnippetRegistryProxy {
|
|
snippet_registry: SnippetRegistry::global(cx),
|
|
});
|
|
}
|
|
|
|
struct SnippetRegistryProxy {
|
|
snippet_registry: Arc<SnippetRegistry>,
|
|
}
|
|
|
|
impl ExtensionSnippetProxy for SnippetRegistryProxy {
|
|
fn register_snippet(&self, path: &PathBuf, snippet_contents: &str) -> Result<()> {
|
|
self.snippet_registry
|
|
.register_snippets(path, snippet_contents)
|
|
}
|
|
}
|