From c065f283aa4214c4a59766832f864a0d931a78a8 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 11 Apr 2022 15:54:52 -0700 Subject: [PATCH] Move assets to their own crate, load keymaps in vim tests Also, move assets folder to the top-level. Co-authored-by: Keith Simmons --- Cargo.lock | 12 ++++ .../fonts/zed-mono/zed-mono-extended.ttf | Bin .../fonts/zed-mono/zed-mono-extendedbold.ttf | Bin .../zed-mono/zed-mono-extendedbolditalic.ttf | Bin .../zed-mono/zed-mono-extendeditalic.ttf | Bin .../fonts/zed-sans/zed-sans-extended.ttf | Bin .../fonts/zed-sans/zed-sans-extendedbold.ttf | Bin .../zed-sans/zed-sans-extendedbolditalic.ttf | Bin .../zed-sans/zed-sans-extendeditalic.ttf | Bin .../assets => assets}/icons/broadcast-24.svg | 0 .../assets => assets}/icons/comment-16.svg | 0 .../icons/diagnostic-error-10.svg | 0 .../icons/diagnostic-summary-error.svg | 0 .../icons/diagnostic-summary-warning.svg | 0 .../icons/diagnostic-warning-10.svg | 0 .../icons/disclosure-closed.svg | 0 .../icons/disclosure-open.svg | 0 .../zed/assets => assets}/icons/file-16.svg | 0 .../icons/folder-tree-16.svg | 0 .../zed/assets => assets}/icons/magnifier.svg | 0 .../assets => assets}/icons/offline-14.svg | 0 .../assets => assets}/icons/signed-out-12.svg | 0 .../zed/assets => assets}/icons/user-16.svg | 0 {crates/zed/assets => assets}/icons/x.svg | 0 {crates/zed/assets => assets}/icons/zap.svg | 0 .../assets => assets}/keymaps/default.json | 56 ----------------- assets/keymaps/vim.json | 58 ++++++++++++++++++ .../zed/assets => assets}/themes/dark.json | 0 .../zed/assets => assets}/themes/light.json | 0 crates/assets/Cargo.toml | 14 +++++ crates/{zed => assets}/src/assets.rs | 2 +- crates/settings/Cargo.toml | 1 + crates/settings/src/keymap_file.rs | 11 ++++ crates/vim/Cargo.toml | 1 + crates/vim/src/vim_test_context.rs | 3 + crates/workspace/Cargo.toml | 2 +- crates/zed/Cargo.toml | 1 + crates/zed/src/main.rs | 2 +- crates/zed/src/test.rs | 3 +- crates/zed/src/zed.rs | 10 +-- styles/src/buildThemes.ts | 2 +- 41 files changed, 109 insertions(+), 69 deletions(-) rename {crates/zed/assets => assets}/fonts/zed-mono/zed-mono-extended.ttf (100%) rename {crates/zed/assets => assets}/fonts/zed-mono/zed-mono-extendedbold.ttf (100%) rename {crates/zed/assets => assets}/fonts/zed-mono/zed-mono-extendedbolditalic.ttf (100%) rename {crates/zed/assets => assets}/fonts/zed-mono/zed-mono-extendeditalic.ttf (100%) rename {crates/zed/assets => assets}/fonts/zed-sans/zed-sans-extended.ttf (100%) rename {crates/zed/assets => assets}/fonts/zed-sans/zed-sans-extendedbold.ttf (100%) rename {crates/zed/assets => assets}/fonts/zed-sans/zed-sans-extendedbolditalic.ttf (100%) rename {crates/zed/assets => assets}/fonts/zed-sans/zed-sans-extendeditalic.ttf (100%) rename {crates/zed/assets => assets}/icons/broadcast-24.svg (100%) rename {crates/zed/assets => assets}/icons/comment-16.svg (100%) rename {crates/zed/assets => assets}/icons/diagnostic-error-10.svg (100%) rename {crates/zed/assets => assets}/icons/diagnostic-summary-error.svg (100%) rename {crates/zed/assets => assets}/icons/diagnostic-summary-warning.svg (100%) rename {crates/zed/assets => assets}/icons/diagnostic-warning-10.svg (100%) rename {crates/zed/assets => assets}/icons/disclosure-closed.svg (100%) rename {crates/zed/assets => assets}/icons/disclosure-open.svg (100%) rename {crates/zed/assets => assets}/icons/file-16.svg (100%) rename {crates/zed/assets => assets}/icons/folder-tree-16.svg (100%) rename {crates/zed/assets => assets}/icons/magnifier.svg (100%) rename {crates/zed/assets => assets}/icons/offline-14.svg (100%) rename {crates/zed/assets => assets}/icons/signed-out-12.svg (100%) rename {crates/zed/assets => assets}/icons/user-16.svg (100%) rename {crates/zed/assets => assets}/icons/x.svg (100%) rename {crates/zed/assets => assets}/icons/zap.svg (100%) rename {crates/zed/assets => assets}/keymaps/default.json (87%) create mode 100644 assets/keymaps/vim.json rename {crates/zed/assets => assets}/themes/dark.json (100%) rename {crates/zed/assets => assets}/themes/light.json (100%) create mode 100644 crates/assets/Cargo.toml rename crates/{zed => assets}/src/assets.rs (95%) diff --git a/Cargo.lock b/Cargo.lock index 4cd3be4969..8917fcac2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,6 +168,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbf56136a5198c7b01a49e3afcbef6cf84597273d298f54432926024107b0109" +[[package]] +name = "assets" +version = "0.1.0" +dependencies = [ + "anyhow", + "gpui", + "rust-embed", +] + [[package]] name = "async-attributes" version = "1.1.2" @@ -4425,6 +4434,7 @@ name = "settings" version = "0.1.0" dependencies = [ "anyhow", + "assets", "collections", "gpui", "schemars", @@ -5743,6 +5753,7 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" name = "vim" version = "0.1.0" dependencies = [ + "assets", "collections", "editor", "gpui", @@ -6018,6 +6029,7 @@ name = "zed" version = "0.25.0" dependencies = [ "anyhow", + "assets", "async-compression", "async-recursion", "async-trait", diff --git a/crates/zed/assets/fonts/zed-mono/zed-mono-extended.ttf b/assets/fonts/zed-mono/zed-mono-extended.ttf similarity index 100% rename from crates/zed/assets/fonts/zed-mono/zed-mono-extended.ttf rename to assets/fonts/zed-mono/zed-mono-extended.ttf diff --git a/crates/zed/assets/fonts/zed-mono/zed-mono-extendedbold.ttf b/assets/fonts/zed-mono/zed-mono-extendedbold.ttf similarity index 100% rename from crates/zed/assets/fonts/zed-mono/zed-mono-extendedbold.ttf rename to assets/fonts/zed-mono/zed-mono-extendedbold.ttf diff --git a/crates/zed/assets/fonts/zed-mono/zed-mono-extendedbolditalic.ttf b/assets/fonts/zed-mono/zed-mono-extendedbolditalic.ttf similarity index 100% rename from crates/zed/assets/fonts/zed-mono/zed-mono-extendedbolditalic.ttf rename to assets/fonts/zed-mono/zed-mono-extendedbolditalic.ttf diff --git a/crates/zed/assets/fonts/zed-mono/zed-mono-extendeditalic.ttf b/assets/fonts/zed-mono/zed-mono-extendeditalic.ttf similarity index 100% rename from crates/zed/assets/fonts/zed-mono/zed-mono-extendeditalic.ttf rename to assets/fonts/zed-mono/zed-mono-extendeditalic.ttf diff --git a/crates/zed/assets/fonts/zed-sans/zed-sans-extended.ttf b/assets/fonts/zed-sans/zed-sans-extended.ttf similarity index 100% rename from crates/zed/assets/fonts/zed-sans/zed-sans-extended.ttf rename to assets/fonts/zed-sans/zed-sans-extended.ttf diff --git a/crates/zed/assets/fonts/zed-sans/zed-sans-extendedbold.ttf b/assets/fonts/zed-sans/zed-sans-extendedbold.ttf similarity index 100% rename from crates/zed/assets/fonts/zed-sans/zed-sans-extendedbold.ttf rename to assets/fonts/zed-sans/zed-sans-extendedbold.ttf diff --git a/crates/zed/assets/fonts/zed-sans/zed-sans-extendedbolditalic.ttf b/assets/fonts/zed-sans/zed-sans-extendedbolditalic.ttf similarity index 100% rename from crates/zed/assets/fonts/zed-sans/zed-sans-extendedbolditalic.ttf rename to assets/fonts/zed-sans/zed-sans-extendedbolditalic.ttf diff --git a/crates/zed/assets/fonts/zed-sans/zed-sans-extendeditalic.ttf b/assets/fonts/zed-sans/zed-sans-extendeditalic.ttf similarity index 100% rename from crates/zed/assets/fonts/zed-sans/zed-sans-extendeditalic.ttf rename to assets/fonts/zed-sans/zed-sans-extendeditalic.ttf diff --git a/crates/zed/assets/icons/broadcast-24.svg b/assets/icons/broadcast-24.svg similarity index 100% rename from crates/zed/assets/icons/broadcast-24.svg rename to assets/icons/broadcast-24.svg diff --git a/crates/zed/assets/icons/comment-16.svg b/assets/icons/comment-16.svg similarity index 100% rename from crates/zed/assets/icons/comment-16.svg rename to assets/icons/comment-16.svg diff --git a/crates/zed/assets/icons/diagnostic-error-10.svg b/assets/icons/diagnostic-error-10.svg similarity index 100% rename from crates/zed/assets/icons/diagnostic-error-10.svg rename to assets/icons/diagnostic-error-10.svg diff --git a/crates/zed/assets/icons/diagnostic-summary-error.svg b/assets/icons/diagnostic-summary-error.svg similarity index 100% rename from crates/zed/assets/icons/diagnostic-summary-error.svg rename to assets/icons/diagnostic-summary-error.svg diff --git a/crates/zed/assets/icons/diagnostic-summary-warning.svg b/assets/icons/diagnostic-summary-warning.svg similarity index 100% rename from crates/zed/assets/icons/diagnostic-summary-warning.svg rename to assets/icons/diagnostic-summary-warning.svg diff --git a/crates/zed/assets/icons/diagnostic-warning-10.svg b/assets/icons/diagnostic-warning-10.svg similarity index 100% rename from crates/zed/assets/icons/diagnostic-warning-10.svg rename to assets/icons/diagnostic-warning-10.svg diff --git a/crates/zed/assets/icons/disclosure-closed.svg b/assets/icons/disclosure-closed.svg similarity index 100% rename from crates/zed/assets/icons/disclosure-closed.svg rename to assets/icons/disclosure-closed.svg diff --git a/crates/zed/assets/icons/disclosure-open.svg b/assets/icons/disclosure-open.svg similarity index 100% rename from crates/zed/assets/icons/disclosure-open.svg rename to assets/icons/disclosure-open.svg diff --git a/crates/zed/assets/icons/file-16.svg b/assets/icons/file-16.svg similarity index 100% rename from crates/zed/assets/icons/file-16.svg rename to assets/icons/file-16.svg diff --git a/crates/zed/assets/icons/folder-tree-16.svg b/assets/icons/folder-tree-16.svg similarity index 100% rename from crates/zed/assets/icons/folder-tree-16.svg rename to assets/icons/folder-tree-16.svg diff --git a/crates/zed/assets/icons/magnifier.svg b/assets/icons/magnifier.svg similarity index 100% rename from crates/zed/assets/icons/magnifier.svg rename to assets/icons/magnifier.svg diff --git a/crates/zed/assets/icons/offline-14.svg b/assets/icons/offline-14.svg similarity index 100% rename from crates/zed/assets/icons/offline-14.svg rename to assets/icons/offline-14.svg diff --git a/crates/zed/assets/icons/signed-out-12.svg b/assets/icons/signed-out-12.svg similarity index 100% rename from crates/zed/assets/icons/signed-out-12.svg rename to assets/icons/signed-out-12.svg diff --git a/crates/zed/assets/icons/user-16.svg b/assets/icons/user-16.svg similarity index 100% rename from crates/zed/assets/icons/user-16.svg rename to assets/icons/user-16.svg diff --git a/crates/zed/assets/icons/x.svg b/assets/icons/x.svg similarity index 100% rename from crates/zed/assets/icons/x.svg rename to assets/icons/x.svg diff --git a/crates/zed/assets/icons/zap.svg b/assets/icons/zap.svg similarity index 100% rename from crates/zed/assets/icons/zap.svg rename to assets/icons/zap.svg diff --git a/crates/zed/assets/keymaps/default.json b/assets/keymaps/default.json similarity index 87% rename from crates/zed/assets/keymaps/default.json rename to assets/keymaps/default.json index 98a9901bd3..6b5511dbce 100644 --- a/crates/zed/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -255,61 +255,5 @@ "ProjectPanel": { "left": "project_panel::CollapseSelectedEntry", "right": "project_panel::ExpandSelectedEntry" - }, - "Editor && vim_mode == insert": { - "escape": "vim::NormalBefore", - "ctrl-c": "vim::NormalBefore" - }, - "Editor && vim_mode == normal && vim_submode == g": { - "g": "vim::MoveToStart", - "escape": [ - "vim::SwitchMode", - { - "Normal": "None" - } - ] - }, - "Editor && vim_mode == normal": { - "i": [ - "vim::SwitchMode", - "Insert" - ], - "g": [ - "vim::SwitchMode", - { - "Normal": "GPrefix" - } - ], - "h": "vim::MoveLeft", - "j": "vim::MoveDown", - "k": "vim::MoveUp", - "l": "vim::MoveRight", - "0": "vim::MoveToStartOfLine", - "shift-$": "vim::MoveToEndOfLine", - "shift-G": "vim::MoveToEnd", - "w": [ - "vim::MoveToNextWordStart", - false - ], - "shift-W": [ - "vim::MoveToNextWordStart", - true - ], - "e": [ - "vim::MoveToNextWordEnd", - false - ], - "shift-E": [ - "vim::MoveToNextWordEnd", - true - ], - "b": [ - "vim::MoveToPreviousWordStart", - false - ], - "shift-B": [ - "vim::MoveToPreviousWordStart", - true - ] } } \ No newline at end of file diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.json new file mode 100644 index 0000000000..f8273286df --- /dev/null +++ b/assets/keymaps/vim.json @@ -0,0 +1,58 @@ +{ + "Editor && vim_mode == insert": { + "escape": "vim::NormalBefore", + "ctrl-c": "vim::NormalBefore" + }, + "Editor && vim_mode == normal && vim_submode == g": { + "g": "vim::MoveToStart", + "escape": [ + "vim::SwitchMode", + { + "Normal": "None" + } + ] + }, + "Editor && vim_mode == normal": { + "i": [ + "vim::SwitchMode", + "Insert" + ], + "g": [ + "vim::SwitchMode", + { + "Normal": "GPrefix" + } + ], + "h": "vim::MoveLeft", + "j": "vim::MoveDown", + "k": "vim::MoveUp", + "l": "vim::MoveRight", + "0": "vim::MoveToStartOfLine", + "shift-$": "vim::MoveToEndOfLine", + "shift-G": "vim::MoveToEnd", + "w": [ + "vim::MoveToNextWordStart", + false + ], + "shift-W": [ + "vim::MoveToNextWordStart", + true + ], + "e": [ + "vim::MoveToNextWordEnd", + false + ], + "shift-E": [ + "vim::MoveToNextWordEnd", + true + ], + "b": [ + "vim::MoveToPreviousWordStart", + false + ], + "shift-B": [ + "vim::MoveToPreviousWordStart", + true + ] + } +} \ No newline at end of file diff --git a/crates/zed/assets/themes/dark.json b/assets/themes/dark.json similarity index 100% rename from crates/zed/assets/themes/dark.json rename to assets/themes/dark.json diff --git a/crates/zed/assets/themes/light.json b/assets/themes/light.json similarity index 100% rename from crates/zed/assets/themes/light.json rename to assets/themes/light.json diff --git a/crates/assets/Cargo.toml b/crates/assets/Cargo.toml new file mode 100644 index 0000000000..71db57f320 --- /dev/null +++ b/crates/assets/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "assets" +version = "0.1.0" +edition = "2021" + +[lib] +path = "src/assets.rs" +doctest = false + +[dependencies] +gpui = { path = "../gpui" } +anyhow = "1.0.38" +rust-embed = { version = "6.3", features = ["include-exclude"] } + diff --git a/crates/zed/src/assets.rs b/crates/assets/src/assets.rs similarity index 95% rename from crates/zed/src/assets.rs rename to crates/assets/src/assets.rs index c0f3a1fbfc..7d5748e43b 100644 --- a/crates/zed/src/assets.rs +++ b/crates/assets/src/assets.rs @@ -3,7 +3,7 @@ use gpui::AssetSource; use rust_embed::RustEmbed; #[derive(RustEmbed)] -#[folder = "assets"] +#[folder = "../../assets"] #[exclude = "*.DS_Store"] pub struct Assets; diff --git a/crates/settings/Cargo.toml b/crates/settings/Cargo.toml index 11487af0af..cc37b1bcfd 100644 --- a/crates/settings/Cargo.toml +++ b/crates/settings/Cargo.toml @@ -11,6 +11,7 @@ doctest = false test-support = [] [dependencies] +assets = { path = "../assets" } collections = { path = "../collections" } gpui = { path = "../gpui" } theme = { path = "../theme" } diff --git a/crates/settings/src/keymap_file.rs b/crates/settings/src/keymap_file.rs index 7d9423719e..621310c220 100644 --- a/crates/settings/src/keymap_file.rs +++ b/crates/settings/src/keymap_file.rs @@ -1,4 +1,5 @@ use anyhow::{Context, Result}; +use assets::Assets; use collections::BTreeMap; use gpui::{keymap::Binding, MutableAppContext}; use serde::Deserialize; @@ -9,6 +10,16 @@ struct ActionWithData<'a>(#[serde(borrow)] &'a str, #[serde(borrow)] &'a RawValu type ActionSetsByContext<'a> = BTreeMap<&'a str, ActionsByKeystroke<'a>>; type ActionsByKeystroke<'a> = BTreeMap<&'a str, &'a RawValue>; +pub fn load_built_in_keymaps(cx: &mut MutableAppContext) { + for path in ["keymaps/default.json", "keymaps/vim.json"] { + load_keymap( + cx, + std::str::from_utf8(Assets::get(path).unwrap().data.as_ref()).unwrap(), + ) + .unwrap(); + } +} + pub fn load_keymap(cx: &mut MutableAppContext, content: &str) -> Result<()> { let actions: ActionSetsByContext = serde_json::from_str(content)?; for (context, actions) in actions { diff --git a/crates/vim/Cargo.toml b/crates/vim/Cargo.toml index f1413d7c51..aeda009ba4 100644 --- a/crates/vim/Cargo.toml +++ b/crates/vim/Cargo.toml @@ -8,6 +8,7 @@ path = "src/vim.rs" doctest = false [dependencies] +assets = { path = "../assets" } collections = { path = "../collections" } editor = { path = "../editor" } gpui = { path = "../gpui" } diff --git a/crates/vim/src/vim_test_context.rs b/crates/vim/src/vim_test_context.rs index 91acc8de6c..5818bdad65 100644 --- a/crates/vim/src/vim_test_context.rs +++ b/crates/vim/src/vim_test_context.rs @@ -23,7 +23,10 @@ impl<'a> VimTestContext<'a> { cx.update(|cx| { editor::init(cx); crate::init(cx); + + settings::keymap_file::load_built_in_keymaps(cx); }); + let params = cx.update(WorkspaceParams::test); cx.update(|cx| { diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.toml index 75d1b1b8f2..d9deef146b 100644 --- a/crates/workspace/Cargo.toml +++ b/crates/workspace/Cargo.toml @@ -8,7 +8,7 @@ path = "src/workspace.rs" doctest = false [features] -test-support = ["client/test-support", "project/test-support"] +test-support = ["client/test-support", "project/test-support", "settings/test-support"] [dependencies] client = { path = "../client" } diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index f87046b05e..b0fbe48fe5 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -29,6 +29,7 @@ test-support = [ ] [dependencies] +assets = { path = "../assets" } breadcrumbs = { path = "../breadcrumbs" } chat_panel = { path = "../chat_panel" } collections = { path = "../collections" } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index bfb1b34256..112de01898 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -15,9 +15,9 @@ use std::{env, fs, path::PathBuf, sync::Arc}; use theme::{ThemeRegistry, DEFAULT_THEME_NAME}; use util::ResultExt; use workspace::{self, AppState, OpenNew, OpenPaths}; +use assets::Assets; use zed::{ self, - assets::Assets, build_window_options, build_workspace, fs::RealFs, languages, menus, diff --git a/crates/zed/src/test.rs b/crates/zed/src/test.rs index 363c852c35..0b81c4361b 100644 --- a/crates/zed/src/test.rs +++ b/crates/zed/src/test.rs @@ -1,4 +1,5 @@ -use crate::{assets::Assets, build_window_options, build_workspace, AppState}; +use crate::{build_window_options, build_workspace, AppState}; +use assets::Assets; use client::{test::FakeHttpClient, ChannelList, Client, UserStore}; use gpui::MutableAppContext; use language::LanguageRegistry; diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 5d5c065b5e..6ab9619016 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -1,11 +1,9 @@ -pub mod assets; pub mod languages; pub mod menus; pub mod settings_file; #[cfg(any(test, feature = "test-support"))] pub mod test; -use assets::Assets; use breadcrumbs::Breadcrumbs; use chat_panel::ChatPanel; pub use client; @@ -104,11 +102,7 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { workspace::lsp_status::init(cx); - settings::keymap_file::load_keymap( - cx, - std::str::from_utf8(Assets::get("keymaps/default.json").unwrap().data.as_ref()).unwrap(), - ) - .unwrap(); + settings::keymap_file::load_built_in_keymaps(cx); } pub fn build_workspace( @@ -209,7 +203,7 @@ fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) { #[cfg(test)] mod tests { use super::*; - use crate::assets::Assets; + use assets::Assets; use editor::{DisplayPoint, Editor}; use gpui::{AssetSource, MutableAppContext, TestAppContext, ViewHandle}; use project::{Fs, ProjectPath}; diff --git a/styles/src/buildThemes.ts b/styles/src/buildThemes.ts index ccbaf82c7f..ce8812ebda 100644 --- a/styles/src/buildThemes.ts +++ b/styles/src/buildThemes.ts @@ -10,7 +10,7 @@ for (let theme of themes) { let styleTree = snakeCase(app(theme)); let styleTreeJSON = JSON.stringify(styleTree, null, 2); let outPath = path.resolve( - `${__dirname}/../../crates/zed/assets/themes/${theme.name}.json` + `${__dirname}/../assets/themes/${theme.name}.json` ); fs.writeFileSync(outPath, styleTreeJSON); console.log(`- ${outPath} created`);