Thanks to @Zertsov for #37932 which caused me to consider this implementation approach. One known issue with this is that it will not wait for actions that do async work to complete. Supporting this would require quite a lot of code change. It also doesn't affect the main usecase of sequencing editor actions, since few are async. Another caveat is that this is implemented as an action handler on workspace and so won't work in other types of windows. This seems fine for now, since action sequences don't seem useful in other window types. The command palette isn't accessible in non-workspace windows. Alternatives considered: * Add `cx: &App` to `Action::build`. This would allow removal of the special case in keymap parsing. Decided not to do this, since ideally `build` is a pure function of the input json. * Build it more directly into GPUI. The main advantage of this would be the potential to handle non-workspace windows. Since it's possible to do outside of GPUI, seems better to do so. While some aspects of the GPUI action system are pretty directly informed by the specifics of Zed's keymap files, it seems to avoid this as much as possible. * Bake it more directly into keymap syntax like in #37932. While I think it would be good for this to be a primitive in the JSON syntax, it seems like it would better fit in a more comprehensive change to provide better JSON structure. So in the meantime it seems better to keep the structure the same and just add a new action. - Another reason to not bake it in yet is that this provides a place to document the caveat about async actions. Closes #17710 Release Notes: - Added support for action sequences in keymaps. Example: `["action::Sequence", [ ["editor::SelectLargerSyntaxNode", "editor::Copy", "editor::UndoSelection"]` --------- Co-authored-by: Mitchel Vostrez <mitch@voz.dev>
137 lines
3.6 KiB
Rust
137 lines
3.6 KiB
Rust
mod base_keymap_setting;
|
|
mod editable_setting_control;
|
|
mod keymap_file;
|
|
pub mod merge_from;
|
|
mod settings_content;
|
|
mod settings_file;
|
|
mod settings_json;
|
|
mod settings_store;
|
|
mod vscode_import;
|
|
|
|
pub use settings_content::*;
|
|
|
|
use gpui::{App, Global};
|
|
use rust_embed::RustEmbed;
|
|
use std::{borrow::Cow, fmt, str};
|
|
use util::asset_str;
|
|
|
|
pub use base_keymap_setting::*;
|
|
pub use editable_setting_control::*;
|
|
pub use keymap_file::{
|
|
KeyBindingValidator, KeyBindingValidatorRegistration, KeybindSource, KeybindUpdateOperation,
|
|
KeybindUpdateTarget, KeymapFile, KeymapFileLoadResult,
|
|
};
|
|
pub use settings_file::*;
|
|
pub use settings_json::*;
|
|
pub use settings_store::{
|
|
InvalidSettingsError, LocalSettingsKind, Settings, SettingsFile, SettingsKey, SettingsLocation,
|
|
SettingsStore,
|
|
};
|
|
|
|
pub use vscode_import::{VsCodeSettings, VsCodeSettingsSource};
|
|
|
|
pub use keymap_file::ActionSequence;
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct ActiveSettingsProfileName(pub String);
|
|
|
|
impl Global for ActiveSettingsProfileName {}
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
|
|
pub struct WorktreeId(usize);
|
|
|
|
impl From<WorktreeId> for usize {
|
|
fn from(value: WorktreeId) -> Self {
|
|
value.0
|
|
}
|
|
}
|
|
|
|
impl WorktreeId {
|
|
pub fn from_usize(handle_id: usize) -> Self {
|
|
Self(handle_id)
|
|
}
|
|
|
|
pub fn from_proto(id: u64) -> Self {
|
|
Self(id as usize)
|
|
}
|
|
|
|
pub fn to_proto(self) -> u64 {
|
|
self.0 as u64
|
|
}
|
|
|
|
pub fn to_usize(self) -> usize {
|
|
self.0
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for WorktreeId {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
std::fmt::Display::fmt(&self.0, f)
|
|
}
|
|
}
|
|
|
|
#[derive(RustEmbed)]
|
|
#[folder = "../../assets"]
|
|
#[include = "settings/*"]
|
|
#[include = "keymaps/*"]
|
|
#[exclude = "*.DS_Store"]
|
|
pub struct SettingsAssets;
|
|
|
|
pub fn init(cx: &mut App) {
|
|
let settings = SettingsStore::new(cx, &default_settings());
|
|
cx.set_global(settings);
|
|
BaseKeymap::register(cx);
|
|
SettingsStore::observe_active_settings_profile_name(cx).detach();
|
|
}
|
|
|
|
pub fn default_settings() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/default.json")
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-macos.json";
|
|
|
|
#[cfg(target_os = "windows")]
|
|
pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-windows.json";
|
|
|
|
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
|
pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-linux.json";
|
|
|
|
pub fn default_keymap() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>(DEFAULT_KEYMAP_PATH)
|
|
}
|
|
|
|
pub const VIM_KEYMAP_PATH: &str = "keymaps/vim.json";
|
|
|
|
pub fn vim_keymap() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>(VIM_KEYMAP_PATH)
|
|
}
|
|
|
|
pub fn initial_user_settings_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_user_settings.json")
|
|
}
|
|
|
|
pub fn initial_server_settings_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_server_settings.json")
|
|
}
|
|
|
|
pub fn initial_project_settings_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_local_settings.json")
|
|
}
|
|
|
|
pub fn initial_keymap_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("keymaps/initial.json")
|
|
}
|
|
|
|
pub fn initial_tasks_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_tasks.json")
|
|
}
|
|
|
|
pub fn initial_debug_tasks_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_debug_tasks.json")
|
|
}
|
|
|
|
pub fn initial_local_debug_tasks_content() -> Cow<'static, str> {
|
|
asset_str::<SettingsAssets>("settings/initial_local_debug_tasks.json")
|
|
}
|