Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer extensions #17809

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ members = [
"extensions/terraform",
"extensions/test-extension",
"extensions/toml",
"extensions/uppercase",
"extensions/uiua",
"extensions/vue",
"extensions/zig",
Expand Down
7 changes: 3 additions & 4 deletions crates/command_palette/src/command_palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ impl CommandPaletteDelegate {
positions,
}) = intercept_result
{
if let Some(idx) = matches
.iter()
.position(|m| commands[m.candidate_id].action.type_id() == action.type_id())
{
if let Some(idx) = matches.iter().position(|m| {
commands[m.candidate_id].action.action_type_id() == action.action_type_id()
}) {
matches.remove(idx);
}
commands.push(Command {
Expand Down
15 changes: 7 additions & 8 deletions crates/command_palette_hooks/src/command_palette_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

#![deny(missing_docs)]

use std::any::TypeId;

use collections::HashSet;
use derive_more::{Deref, DerefMut};
use gpui::{Action, AppContext, BorrowAppContext, Global};
use gpui::{Action, ActionTypeId, AppContext, BorrowAppContext, Global};

/// Initializes the command palette hooks.
pub fn init(cx: &mut AppContext) {
Expand All @@ -18,7 +16,7 @@ pub fn init(cx: &mut AppContext) {
#[derive(Default)]
pub struct CommandPaletteFilter {
hidden_namespaces: HashSet<&'static str>,
hidden_action_types: HashSet<TypeId>,
hidden_action_types: HashSet<ActionTypeId>,
}

#[derive(Deref, DerefMut, Default)]
Expand Down Expand Up @@ -52,7 +50,7 @@ impl CommandPaletteFilter {
let namespace = name.split("::").next().unwrap_or("malformed action name");

self.hidden_namespaces.contains(namespace)
|| self.hidden_action_types.contains(&action.type_id())
|| self.hidden_action_types.contains(&action.action_type_id())
}

/// Hides all actions in the given namespace.
Expand All @@ -66,12 +64,13 @@ impl CommandPaletteFilter {
}

/// Hides all actions with the given types.
pub fn hide_action_types(&mut self, action_types: &[TypeId]) {
self.hidden_action_types.extend(action_types);
pub fn hide_action_types(&mut self, action_types: &[ActionTypeId]) {
self.hidden_action_types
.extend(action_types.iter().cloned());
}

/// Shows all actions with the given types.
pub fn show_action_types<'a>(&mut self, action_types: impl Iterator<Item = &'a TypeId>) {
pub fn show_action_types<'a>(&mut self, action_types: impl Iterator<Item = &'a ActionTypeId>) {
for action_type in action_types {
self.hidden_action_types.remove(action_type);
}
Expand Down
16 changes: 8 additions & 8 deletions crates/copilot/src/copilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use collections::{HashMap, HashSet};
use command_palette_hooks::CommandPaletteFilter;
use futures::{channel::oneshot, future::Shared, Future, FutureExt, TryFutureExt};
use gpui::{
actions, AppContext, AsyncAppContext, Context, Entity, EntityId, EventEmitter, Global, Model,
ModelContext, Task, WeakModel,
actions, ActionTypeId, AppContext, AsyncAppContext, Context, Entity, EntityId, EventEmitter,
Global, Model, ModelContext, Task, WeakModel,
};
use http_client::github::latest_github_release;
use http_client::HttpClient;
Expand Down Expand Up @@ -69,13 +69,13 @@ pub fn init(
Copilot::set_global(copilot.clone(), cx);
cx.observe(&copilot, |handle, cx| {
let copilot_action_types = [
TypeId::of::<Suggest>(),
TypeId::of::<NextSuggestion>(),
TypeId::of::<PreviousSuggestion>(),
TypeId::of::<Reinstall>(),
ActionTypeId::of::<Suggest>(),
ActionTypeId::of::<NextSuggestion>(),
ActionTypeId::of::<PreviousSuggestion>(),
ActionTypeId::of::<Reinstall>(),
];
let copilot_auth_action_types = [TypeId::of::<SignOut>()];
let copilot_no_auth_action_types = [TypeId::of::<SignIn>()];
let copilot_auth_action_types = [ActionTypeId::of::<SignOut>()];
let copilot_no_auth_action_types = [ActionTypeId::of::<SignIn>()];
let status = handle.read(cx).status();
let filter = CommandPaletteFilter::global_mut(cx);

Expand Down
37 changes: 25 additions & 12 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ use fuzzy::{StringMatch, StringMatchCandidate};
use git::blame::GitBlame;
use git::diff_hunk_to_display;
use gpui::{
div, impl_actions, point, prelude::*, px, relative, size, uniform_list, Action, AnyElement,
AppContext, AsyncWindowContext, AvailableSpace, BackgroundExecutor, Bounds, ClipboardEntry,
ClipboardItem, Context, DispatchPhase, ElementId, EntityId, EventEmitter, FocusHandle,
FocusOutEvent, FocusableView, FontId, FontWeight, HighlightStyle, Hsla, InteractiveText,
KeyContext, ListSizingBehavior, Model, MouseButton, PaintQuad, ParentElement, Pixels, Render,
SharedString, Size, StrikethroughStyle, Styled, StyledText, Subscription, Task, TextStyle,
UTF16Selection, UnderlineStyle, UniformListScrollHandle, View, ViewContext, ViewInputHandler,
VisualContext, WeakFocusHandle, WeakView, WindowContext,
div, impl_actions, point, prelude::*, px, relative, size, uniform_list, Action, ActionTypeId,
AnyElement, AppContext, AsyncWindowContext, AvailableSpace, BackgroundExecutor, Bounds,
ClipboardEntry, ClipboardItem, Context, DispatchPhase, ElementId, EntityId, EventEmitter,
FocusHandle, FocusOutEvent, FocusableView, FontId, FontWeight, HighlightStyle, Hsla,
InteractiveText, KeyContext, ListSizingBehavior, Model, MouseButton, PaintQuad, ParentElement,
Pixels, Render, SharedString, Size, StrikethroughStyle, Styled, StyledText, Subscription, Task,
TextStyle, UTF16Selection, UnderlineStyle, UniformListScrollHandle, View, ViewContext,
ViewInputHandler, VisualContext, WeakFocusHandle, WeakView, WindowContext,
};
use highlight_matching_bracket::refresh_matching_bracket_highlights;
use hover_popover::{hide_hover, HoverState};
Expand Down Expand Up @@ -128,6 +128,7 @@ use serde::{Deserialize, Serialize};
use settings::{update_settings_file, Settings, SettingsLocation, SettingsStore};
use smallvec::SmallVec;
use snippet::Snippet;
use std::any::Any;
use std::{
any::TypeId,
borrow::Cow,
Expand Down Expand Up @@ -12051,19 +12052,21 @@ impl Editor {
cx.notify();
}

pub fn register_action<A: Action>(
pub fn register_runtime_action(
&mut self,
listener: impl Fn(&A, &mut WindowContext) + 'static,
action_type_id: ActionTypeId,
listener: impl Fn(&dyn Any, &mut WindowContext) + 'static,
) -> Subscription {
dbg!("register runtime action", action_type_id.clone());
let id = self.next_editor_action_id.post_inc();
let listener = Arc::new(listener);
self.editor_actions.borrow_mut().insert(
id,
Box::new(move |cx| {
let cx = cx.window_context();
let listener = listener.clone();
cx.on_action(TypeId::of::<A>(), move |action, phase, cx| {
let action = action.downcast_ref().unwrap();
cx.on_action(action_type_id.clone(), move |action, phase, cx| {
eprintln!("Action fired; phase is {phase:?}");
if phase == DispatchPhase::Bubble {
listener(action, cx)
}
Expand All @@ -12077,6 +12080,16 @@ impl Editor {
})
}

pub fn register_action<A: Action>(
&mut self,
listener: impl Fn(&A, &mut WindowContext) + 'static,
) -> Subscription {
self.register_runtime_action(ActionTypeId::of::<A>(), move |action, cx| {
let action = action.downcast_ref().unwrap();
listener(action, cx)
})
}

pub fn file_header_size(&self) -> u32 {
self.file_header_size
}
Expand Down
4 changes: 2 additions & 2 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use crate::{
use client::ParticipantIndex;
use collections::{BTreeMap, HashMap};
use git::{blame::BlameEntry, diff::DiffHunkStatus, Oid};
use gpui::Subscription;
use gpui::{
anchored, deferred, div, fill, outline, point, px, quad, relative, size, svg,
transparent_black, Action, AnchorCorner, AnyElement, AvailableSpace, Bounds, ClipboardItem,
Expand All @@ -40,6 +39,7 @@ use gpui::{
StatefulInteractiveElement, Style, Styled, TextRun, TextStyle, TextStyleRefinement, View,
ViewContext, WeakView, WindowContext,
};
use gpui::{ActionTypeId, Subscription};
use itertools::Itertools;
use language::{
language_settings::{
Expand Down Expand Up @@ -6258,7 +6258,7 @@ pub fn register_action<T: Action>(
listener: impl Fn(&mut Editor, &T, &mut ViewContext<Editor>) + 'static,
) {
let view = view.clone();
cx.on_action(TypeId::of::<T>(), move |action, phase, cx| {
cx.on_action(ActionTypeId::of::<T>(), move |action, phase, cx| {
let action = action.downcast_ref().unwrap();
if phase == DispatchPhase::Bubble {
view.update(cx, |editor, cx| {
Expand Down
3 changes: 3 additions & 0 deletions crates/extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async-trait.workspace = true
client.workspace = true
collections.workspace = true
fs.workspace = true
editor.workspace = true
futures.workspace = true
gpui.workspace = true
http_client.workspace = true
Expand All @@ -32,7 +33,9 @@ isahc.workspace = true
language.workspace = true
log.workspace = true
lsp.workspace = true
multi_buffer.workspace = true
node_runtime.workspace = true
parking_lot.workspace = true
paths.workspace = true
project.workspace = true
release_channel.workspace = true
Expand Down
11 changes: 11 additions & 0 deletions crates/extension/src/extension_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct ExtensionManifest {
pub indexed_docs_providers: BTreeMap<Arc<str>, IndexedDocsProviderEntry>,
#[serde(default)]
pub snippets: Option<PathBuf>,
#[serde(default)]
pub editor_actions: BTreeMap<Arc<str>, EditorActionManifestEntry>,
}

#[derive(Clone, Default, PartialEq, Eq, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -116,6 +118,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.
///
Expand All @@ -140,6 +145,11 @@ pub struct SlashCommandManifestEntry {
pub requires_argument: bool,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct EditorActionManifestEntry {
pub name: String, // <extension_id>:: "Name"
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct IndexedDocsProviderEntry {}

Expand Down Expand Up @@ -187,6 +197,7 @@ fn manifest_from_old_manifest(
authors: manifest_json.authors,
schema_version: SchemaVersion::ZERO,
lib: Default::default(),
editor_actions: Default::default(),
themes: {
let mut themes = manifest_json.themes.into_values().collect::<Vec<_>>();
themes.sort();
Expand Down
Loading
Loading