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:
1 parent
4353d8f0f7
commit
f75211df7d
41 files changed
+109
-69
No files matched your search
Generated
+12
@@ -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",
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
]
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -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;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "assets"]
|
||||
#[folder = "../../assets"]
|
||||
#[exclude = "*.DS_Store"]
|
||||
pub struct Assets;
|
||||
|
||||
@@ -11,6 +11,7 @@ doctest = false
|
||||
test-support = []
|
||||
|
||||
[dependencies]
|
||||
assets = { path = "../assets" }
|
||||
collections = { path = "../collections" }
|
||||
gpui = { path = "../gpui" }
|
||||
theme = { path = "../theme" }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -8,6 +8,7 @@ path = "src/vim.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
assets = { path = "../assets" }
|
||||
collections = { path = "../collections" }
|
||||
editor = { path = "../editor" }
|
||||
gpui = { path = "../gpui" }
|
||||
|
||||
@@ -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| {
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -29,6 +29,7 @@ test-support = [
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
assets = { path = "../assets" }
|
||||
breadcrumbs = { path = "../breadcrumbs" }
|
||||
chat_panel = { path = "../chat_panel" }
|
||||
collections = { path = "../collections" }
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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`);
|
||||
|
||||
Reference in new issue
Block a user