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>
12
Cargo.lock
generated
|
@ -168,6 +168,15 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bbf56136a5198c7b01a49e3afcbef6cf84597273d298f54432926024107b0109"
|
checksum = "bbf56136a5198c7b01a49e3afcbef6cf84597273d298f54432926024107b0109"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "assets"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"gpui",
|
||||||
|
"rust-embed",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-attributes"
|
name = "async-attributes"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
|
@ -4425,6 +4434,7 @@ name = "settings"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"assets",
|
||||||
"collections",
|
"collections",
|
||||||
"gpui",
|
"gpui",
|
||||||
"schemars",
|
"schemars",
|
||||||
|
@ -5743,6 +5753,7 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||||
name = "vim"
|
name = "vim"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"assets",
|
||||||
"collections",
|
"collections",
|
||||||
"editor",
|
"editor",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
@ -6018,6 +6029,7 @@ name = "zed"
|
||||||
version = "0.25.0"
|
version = "0.25.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"assets",
|
||||||
"async-compression",
|
"async-compression",
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|
Before Width: | Height: | Size: 879 B After Width: | Height: | Size: 879 B |
Before Width: | Height: | Size: 979 B After Width: | Height: | Size: 979 B |
Before Width: | Height: | Size: 464 B After Width: | Height: | Size: 464 B |
Before Width: | Height: | Size: 499 B After Width: | Height: | Size: 499 B |
Before Width: | Height: | Size: 317 B After Width: | Height: | Size: 317 B |
Before Width: | Height: | Size: 284 B After Width: | Height: | Size: 284 B |
Before Width: | Height: | Size: 512 B After Width: | Height: | Size: 512 B |
Before Width: | Height: | Size: 516 B After Width: | Height: | Size: 516 B |
Before Width: | Height: | Size: 445 B After Width: | Height: | Size: 445 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 776 B After Width: | Height: | Size: 776 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 733 B After Width: | Height: | Size: 733 B |
Before Width: | Height: | Size: 676 B After Width: | Height: | Size: 676 B |
Before Width: | Height: | Size: 322 B After Width: | Height: | Size: 322 B |
|
@ -255,61 +255,5 @@
|
||||||
"ProjectPanel": {
|
"ProjectPanel": {
|
||||||
"left": "project_panel::CollapseSelectedEntry",
|
"left": "project_panel::CollapseSelectedEntry",
|
||||||
"right": "project_panel::ExpandSelectedEntry"
|
"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
|
@ -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
|
@ -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"] }
|
||||||
|
|
|
@ -3,7 +3,7 @@ use gpui::AssetSource;
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
#[folder = "assets"]
|
#[folder = "../../assets"]
|
||||||
#[exclude = "*.DS_Store"]
|
#[exclude = "*.DS_Store"]
|
||||||
pub struct Assets;
|
pub struct Assets;
|
||||||
|
|
|
@ -11,6 +11,7 @@ doctest = false
|
||||||
test-support = []
|
test-support = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
assets = { path = "../assets" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
theme = { path = "../theme" }
|
theme = { path = "../theme" }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use assets::Assets;
|
||||||
use collections::BTreeMap;
|
use collections::BTreeMap;
|
||||||
use gpui::{keymap::Binding, MutableAppContext};
|
use gpui::{keymap::Binding, MutableAppContext};
|
||||||
use serde::Deserialize;
|
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 ActionSetsByContext<'a> = BTreeMap<&'a str, ActionsByKeystroke<'a>>;
|
||||||
type ActionsByKeystroke<'a> = BTreeMap<&'a str, &'a RawValue>;
|
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<()> {
|
pub fn load_keymap(cx: &mut MutableAppContext, content: &str) -> Result<()> {
|
||||||
let actions: ActionSetsByContext = serde_json::from_str(content)?;
|
let actions: ActionSetsByContext = serde_json::from_str(content)?;
|
||||||
for (context, actions) in actions {
|
for (context, actions) in actions {
|
||||||
|
|
|
@ -8,6 +8,7 @@ path = "src/vim.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
assets = { path = "../assets" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
editor = { path = "../editor" }
|
editor = { path = "../editor" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
|
|
|
@ -23,7 +23,10 @@ impl<'a> VimTestContext<'a> {
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
editor::init(cx);
|
editor::init(cx);
|
||||||
crate::init(cx);
|
crate::init(cx);
|
||||||
|
|
||||||
|
settings::keymap_file::load_built_in_keymaps(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
let params = cx.update(WorkspaceParams::test);
|
let params = cx.update(WorkspaceParams::test);
|
||||||
|
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
|
|
|
@ -8,7 +8,7 @@ path = "src/workspace.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
test-support = ["client/test-support", "project/test-support"]
|
test-support = ["client/test-support", "project/test-support", "settings/test-support"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
client = { path = "../client" }
|
client = { path = "../client" }
|
||||||
|
|
|
@ -29,6 +29,7 @@ test-support = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
assets = { path = "../assets" }
|
||||||
breadcrumbs = { path = "../breadcrumbs" }
|
breadcrumbs = { path = "../breadcrumbs" }
|
||||||
chat_panel = { path = "../chat_panel" }
|
chat_panel = { path = "../chat_panel" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
|
|
|
@ -15,9 +15,9 @@ use std::{env, fs, path::PathBuf, sync::Arc};
|
||||||
use theme::{ThemeRegistry, DEFAULT_THEME_NAME};
|
use theme::{ThemeRegistry, DEFAULT_THEME_NAME};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::{self, AppState, OpenNew, OpenPaths};
|
use workspace::{self, AppState, OpenNew, OpenPaths};
|
||||||
|
use assets::Assets;
|
||||||
use zed::{
|
use zed::{
|
||||||
self,
|
self,
|
||||||
assets::Assets,
|
|
||||||
build_window_options, build_workspace,
|
build_window_options, build_workspace,
|
||||||
fs::RealFs,
|
fs::RealFs,
|
||||||
languages, menus,
|
languages, menus,
|
||||||
|
|
|
@ -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 client::{test::FakeHttpClient, ChannelList, Client, UserStore};
|
||||||
use gpui::MutableAppContext;
|
use gpui::MutableAppContext;
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
pub mod assets;
|
|
||||||
pub mod languages;
|
pub mod languages;
|
||||||
pub mod menus;
|
pub mod menus;
|
||||||
pub mod settings_file;
|
pub mod settings_file;
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub mod test;
|
pub mod test;
|
||||||
|
|
||||||
use assets::Assets;
|
|
||||||
use breadcrumbs::Breadcrumbs;
|
use breadcrumbs::Breadcrumbs;
|
||||||
use chat_panel::ChatPanel;
|
use chat_panel::ChatPanel;
|
||||||
pub use client;
|
pub use client;
|
||||||
|
@ -104,11 +102,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
|
||||||
|
|
||||||
workspace::lsp_status::init(cx);
|
workspace::lsp_status::init(cx);
|
||||||
|
|
||||||
settings::keymap_file::load_keymap(
|
settings::keymap_file::load_built_in_keymaps(cx);
|
||||||
cx,
|
|
||||||
std::str::from_utf8(Assets::get("keymaps/default.json").unwrap().data.as_ref()).unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_workspace(
|
pub fn build_workspace(
|
||||||
|
@ -209,7 +203,7 @@ fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::assets::Assets;
|
use assets::Assets;
|
||||||
use editor::{DisplayPoint, Editor};
|
use editor::{DisplayPoint, Editor};
|
||||||
use gpui::{AssetSource, MutableAppContext, TestAppContext, ViewHandle};
|
use gpui::{AssetSource, MutableAppContext, TestAppContext, ViewHandle};
|
||||||
use project::{Fs, ProjectPath};
|
use project::{Fs, ProjectPath};
|
||||||
|
|
|
@ -10,7 +10,7 @@ for (let theme of themes) {
|
||||||
let styleTree = snakeCase(app(theme));
|
let styleTree = snakeCase(app(theme));
|
||||||
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
|
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
|
||||||
let outPath = path.resolve(
|
let outPath = path.resolve(
|
||||||
`${__dirname}/../../crates/zed/assets/themes/${theme.name}.json`
|
`${__dirname}/../assets/themes/${theme.name}.json`
|
||||||
);
|
);
|
||||||
fs.writeFileSync(outPath, styleTreeJSON);
|
fs.writeFileSync(outPath, styleTreeJSON);
|
||||||
console.log(`- ${outPath} created`);
|
console.log(`- ${outPath} created`);
|
||||||
|
|