From cdb88f52b7b73d42efc2b62065e2a4e9fa5ba884 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 13 Sep 2024 13:44:58 -0400 Subject: [PATCH] temp --- crates/editor/src/editor.rs | 2 +- crates/extension/src/extension_manifest.rs | 5 ++ crates/extension/src/extension_store.rs | 70 +++++++++++++++++++++- crates/language/src/language.rs | 3 + 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 515cde1908..9bf364a388 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -277,7 +277,7 @@ pub enum Navigated { impl Navigated { pub fn from_bool(yes: bool) -> Navigated { - if yes { + if yes {_a Navigated::Yes } else { Navigated::No diff --git a/crates/extension/src/extension_manifest.rs b/crates/extension/src/extension_manifest.rs index e23350d767..be2e4bbc5f 100644 --- a/crates/extension/src/extension_manifest.rs +++ b/crates/extension/src/extension_manifest.rs @@ -75,6 +75,8 @@ pub struct ExtensionManifest { #[serde(default)] pub language_servers: BTreeMap, #[serde(default)] + pub actions: BTreeMap, + #[serde(default)] pub slash_commands: BTreeMap, SlashCommandManifestEntry>, #[serde(default)] pub indexed_docs_providers: BTreeMap, IndexedDocsProviderEntry>, @@ -119,6 +121,9 @@ pub struct LanguageServerManifestEntry { pub code_action_kinds: Option>, } +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct ActionManifestEntry {} + impl LanguageServerManifestEntry { /// Returns the list of languages for the language server. /// diff --git a/crates/extension/src/extension_store.rs b/crates/extension/src/extension_store.rs index 3ebc4f20d3..3414fa3c7e 100644 --- a/crates/extension/src/extension_store.rs +++ b/crates/extension/src/extension_store.rs @@ -30,8 +30,8 @@ use futures::{ select_biased, AsyncReadExt as _, Future, FutureExt as _, StreamExt as _, }; use gpui::{ - actions, AppContext, AsyncAppContext, Context, EventEmitter, Global, Model, ModelContext, Task, - WeakModel, + actions, AppContext, AsyncAppContext, Context, EventEmitter, Global, Model, ModelContext, + Subscription, Task, WeakModel, }; use http_client::{AsyncBody, HttpClient, HttpClientWithUrl}; use indexed_docs::{IndexedDocsRegistry, ProviderId}; @@ -102,6 +102,64 @@ pub fn is_version_compatible( true } +#[derive(Clone, PartialEq, Eq)] +pub struct ExtensionAction { + extension: Arc, + name: Arc, +} + +impl gpui::Action for ExtensionAction { + fn boxed_clone(&self) -> Box { + Box::new(self.clone()) + } + + fn as_any(&self) -> &dyn std::any::Any { + self as _ + } + + fn partial_eq(&self, action: &dyn gpui::Action) -> bool { + if let Some(other) = action.as_any().downcast_ref::() else { + return false + } + other == self + } + + fn name(&self) -> &str { + "extension::Action" + } + + fn debug_name() -> &'static str + where + Self: Sized { + "extension::ActionDebugName" + } + + fn build(value: serde_json::Value) -> Result> + where + Self: Sized { + todo!() + } +} + +pub struct EditorActionRegistry { + wasm_host: Arc, + editors: Vec>, + actions: Vec, +} + +impl EditorActionRegistry { + fn add_action(&self,action: String) -> { + self.wasm_host.on_main_thread(|cx| { + for editor in self.editors { + editor.update(&mut cx, |editor, cx| { + editor.register_action + }) + + } + }) + } +} + pub struct ExtensionStore { builder: Arc, extension_index: ExtensionIndex, @@ -939,7 +997,7 @@ impl ExtensionStore { /// /// First, this unloads any themes, languages, or grammars that are /// no longer in the manifest, or whose files have changed on disk. - /// Then it loads any themes, languages, or grammars that are newly + /// Then it loads any themes, languages, edits, or grammars that are newly /// added to the manifest, or whose files have changed on disk. fn extensions_updated( &mut self, @@ -1064,6 +1122,7 @@ impl ExtensionStore { let mut grammars_to_add = Vec::new(); let mut themes_to_add = Vec::new(); let mut snippets_to_add = Vec::new(); + let mut actions_to_add = Vec::new(); for extension_id in &extensions_to_load { let Some(extension) = new_index.extensions.get(extension_id) else { continue; @@ -1086,6 +1145,11 @@ impl ExtensionStore { path.extend([Path::new(extension_id.as_ref()), snippets_path.as_path()]); path })); + actions_to_add.extend(extension.manifest.actions.iter().map(|actions_path| { + let mut path = self.installed_dir.clone(); + path.extend([Path::new(extension_id.as_ref()), actions_path.as_path()]); + path + })); } self.language_registry diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index cd39490d0b..564eb52f19 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -141,6 +141,9 @@ pub trait ToLspPosition { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] pub struct LanguageServerName(pub Arc); +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] +pub struct ActionName(Arc); + impl LanguageServerName { pub fn from_proto(s: String) -> Self { Self(Arc::from(s))