This commit is contained in:
Conrad Irwin
2024-09-13 13:44:58 -04:00
parent 14b4dc9a3a
commit cdb88f52b7
4 changed files with 76 additions and 4 deletions

View File

@@ -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

View File

@@ -75,6 +75,8 @@ pub struct ExtensionManifest {
#[serde(default)]
pub language_servers: BTreeMap<LanguageServerName, LanguageServerManifestEntry>,
#[serde(default)]
pub actions: BTreeMap<ActionName, ActionManifestEntry>,
#[serde(default)]
pub slash_commands: BTreeMap<Arc<str>, SlashCommandManifestEntry>,
#[serde(default)]
pub indexed_docs_providers: BTreeMap<Arc<str>, IndexedDocsProviderEntry>,
@@ -119,6 +121,9 @@ pub struct LanguageServerManifestEntry {
pub code_action_kinds: Option<Vec<lsp::CodeActionKind>>,
}
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct ActionManifestEntry {}
impl LanguageServerManifestEntry {
/// Returns the list of languages for the language server.
///

View File

@@ -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<str>,
name: Arc<str>,
}
impl gpui::Action for ExtensionAction {
fn boxed_clone(&self) -> Box<dyn gpui::Action> {
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::<ExtensionAction>() 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<Box<dyn gpui::Action>>
where
Self: Sized {
todo!()
}
}
pub struct EditorActionRegistry {
wasm_host: Arc<WasmHost>,
editors: Vec<WeakModel<Editor>>,
actions: Vec<String>,
}
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<ExtensionBuilder>,
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

View File

@@ -141,6 +141,9 @@ pub trait ToLspPosition {
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
pub struct LanguageServerName(pub Arc<str>);
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
pub struct ActionName(Arc<str>);
impl LanguageServerName {
pub fn from_proto(s: String) -> Self {
Self(Arc::from(s))