Move assets to their own crate, load keymaps in vim tests

Also, move assets folder to the top-level.

Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-04-11 15:54:52 -07:00
parent e0096ec1eb
commit c065f283aa
41 changed files with 109 additions and 69 deletions

12
Cargo.lock generated
View File

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

View File

Before

Width:  |  Height:  |  Size: 879 B

After

Width:  |  Height:  |  Size: 879 B

View File

Before

Width:  |  Height:  |  Size: 979 B

After

Width:  |  Height:  |  Size: 979 B

View File

Before

Width:  |  Height:  |  Size: 464 B

After

Width:  |  Height:  |  Size: 464 B

View File

Before

Width:  |  Height:  |  Size: 499 B

After

Width:  |  Height:  |  Size: 499 B

View File

Before

Width:  |  Height:  |  Size: 317 B

After

Width:  |  Height:  |  Size: 317 B

View File

Before

Width:  |  Height:  |  Size: 284 B

After

Width:  |  Height:  |  Size: 284 B

View File

Before

Width:  |  Height:  |  Size: 512 B

After

Width:  |  Height:  |  Size: 512 B

View File

Before

Width:  |  Height:  |  Size: 516 B

After

Width:  |  Height:  |  Size: 516 B

View File

Before

Width:  |  Height:  |  Size: 445 B

After

Width:  |  Height:  |  Size: 445 B

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 776 B

After

Width:  |  Height:  |  Size: 776 B

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 733 B

After

Width:  |  Height:  |  Size: 733 B

View File

Before

Width:  |  Height:  |  Size: 676 B

After

Width:  |  Height:  |  Size: 676 B

View File

Before

Width:  |  Height:  |  Size: 322 B

After

Width:  |  Height:  |  Size: 322 B

View File

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

58
assets/keymaps/vim.json Normal file
View File

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

14
crates/assets/Cargo.toml Normal file
View File

@ -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"] }

View File

@ -3,7 +3,7 @@ use gpui::AssetSource;
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "assets"]
#[folder = "../../assets"]
#[exclude = "*.DS_Store"]
pub struct Assets;

View File

@ -11,6 +11,7 @@ doctest = false
test-support = []
[dependencies]
assets = { path = "../assets" }
collections = { path = "../collections" }
gpui = { path = "../gpui" }
theme = { path = "../theme" }

View File

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

View File

@ -8,6 +8,7 @@ path = "src/vim.rs"
doctest = false
[dependencies]
assets = { path = "../assets" }
collections = { path = "../collections" }
editor = { path = "../editor" }
gpui = { path = "../gpui" }

View File

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

View File

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

View File

@ -29,6 +29,7 @@ test-support = [
]
[dependencies]
assets = { path = "../assets" }
breadcrumbs = { path = "../breadcrumbs" }
chat_panel = { path = "../chat_panel" }
collections = { path = "../collections" }

View File

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

View File

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

View File

@ -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<AppState>, 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};

View File

@ -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`);