From cb8762d855d27de1a422090fd4a1fabb8944152b Mon Sep 17 00:00:00 2001 From: Sergey Onufrienko Date: Mon, 17 Jul 2023 17:54:37 +0100 Subject: [PATCH 01/52] chore: add theme types docs --- docs/theme/generating-theme-types.md | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docs/theme/generating-theme-types.md diff --git a/docs/theme/generating-theme-types.md b/docs/theme/generating-theme-types.md new file mode 100644 index 0000000000000000000000000000000000000000..efebc8d21df7e52dcc2c64b9a78602251b4847c5 --- /dev/null +++ b/docs/theme/generating-theme-types.md @@ -0,0 +1,29 @@ +[⬅ Back to Index](../index.md) + +# Generating Theme Types + + +## How to generate theme types: + +Run a script + +```bash +./script/build-theme-types +``` + +Types are generated in `styles/src/types/zed.ts` + + +## How it works: + +1. Rust types + + The `crates/theme` contains theme types. + Crate `schemars` used to generate a JSON schema from the theme structs. + Every struct that represent theme type has a `#[derive(JsonSchema)]` attribute. + + Task lotaked at `crates/xtask/src/main.rs` generates a JSON schema from the theme structs. + +2. TypeScript types + + Script `npm run build-types` from `styles` package generates TypeScript types from the JSON schema and saves them to `styles/src/types/zed.ts`. From 1610e270d6422271bd39006214c2a5410bc320c9 Mon Sep 17 00:00:00 2001 From: Alex Viscreanu Date: Fri, 21 Jul 2023 13:16:00 +0200 Subject: [PATCH 02/52] feat(workspace): add action for closing inactive editors on all panes --- assets/keymaps/default.json | 1 + crates/workspace/src/workspace.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 883b0c1872a47ea9242716cfbd39298ccdfacb94..5c841d19b2ca1b5bf54e5ca93c5f7d10341876b5 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -22,6 +22,7 @@ "alt-cmd-right": "pane::ActivateNextItem", "cmd-w": "pane::CloseActiveItem", "alt-cmd-t": "pane::CloseInactiveItems", + "ctrl-alt-cmd-w": "workspace::CloseInactiveEditors", "cmd-k u": "pane::CloseCleanItems", "cmd-k cmd-w": "pane::CloseAllItems", "cmd-shift-w": "workspace::CloseWindow", diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 0ebd01e1f7a706e1e2baf3b15ff1f35a51a3fb7f..6694cc06a32ff416323cea047539759a8ee62e39 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -122,6 +122,7 @@ actions!( NewFile, NewWindow, CloseWindow, + CloseInactiveEditors, AddFolderToProject, Unfollow, Save, @@ -239,6 +240,7 @@ pub fn init(app_state: Arc, cx: &mut AppContext) { cx.add_async_action(Workspace::follow_next_collaborator); cx.add_async_action(Workspace::close); + cx.add_async_action(Workspace::close_inactive_editors); cx.add_global_action(Workspace::close_global); cx.add_global_action(restart); cx.add_async_action(Workspace::save_all); @@ -1633,6 +1635,34 @@ impl Workspace { } } + pub fn close_inactive_editors( + &mut self, + _: &CloseInactiveEditors, + cx: &mut ViewContext, + ) -> Option>> { + let current_pane = self.active_pane(); + + // let mut tasks: Vec>> = Vec::new(); + current_pane + .update(cx, |pane, cx| { + pane.close_inactive_items(&CloseInactiveItems, cx).unwrap() + }) + .detach_and_log_err(cx); + + for pane in self.panes() { + if pane.id() == current_pane.id() { + continue; + } + + pane.update(cx, |pane: &mut Pane, cx| { + pane.close_all_items(&CloseAllItems, cx).unwrap() + }) + .detach_and_log_err(cx); + } + + Some(Task::ready(Ok(()))) + } + pub fn toggle_dock(&mut self, dock_side: DockPosition, cx: &mut ViewContext) { let dock = match dock_side { DockPosition::Left => &self.left_dock, From fe388ed71ef9d8877fbef216061ac807acc1ba3d Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Sun, 23 Jul 2023 14:39:43 -0700 Subject: [PATCH 03/52] Add tree-sitter-nix --- Cargo.lock | 10 +++ Cargo.toml | 1 + crates/zed/Cargo.toml | 1 + crates/zed/src/languages.rs | 1 + crates/zed/src/languages/nix/config.toml | 11 +++ crates/zed/src/languages/nix/highlights.scm | 95 +++++++++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 crates/zed/src/languages/nix/config.toml create mode 100644 crates/zed/src/languages/nix/highlights.scm diff --git a/Cargo.lock b/Cargo.lock index f0c8917aa28d300e1aea521f7c936c3ce918a984..175b3d931532bce1fbe9c4f41bbcfab557e88fdf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8065,6 +8065,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-nix" +version = "0.0.1" +source = "git+https://github.com/nix-community/tree-sitter-nix?rev=66e3e9ce9180ae08fc57372061006ef83f0abde7#66e3e9ce9180ae08fc57372061006ef83f0abde7" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-php" version = "0.19.1" @@ -9550,6 +9559,7 @@ dependencies = [ "tree-sitter-json 0.20.0", "tree-sitter-lua", "tree-sitter-markdown", + "tree-sitter-nix", "tree-sitter-php", "tree-sitter-python", "tree-sitter-racket", diff --git a/Cargo.toml b/Cargo.toml index fa824115cb82b02c2428f2f1bd9889a0b93a5757..ca13a4eb2fd2b0af34a115274ea4347c57883259 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -129,6 +129,7 @@ tree-sitter-svelte = { git = "https://github.com/Himujjal/tree-sitter-svelte", r tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a"} tree-sitter-yaml = { git = "https://github.com/zed-industries/tree-sitter-yaml", rev = "f545a41f57502e1b5ddf2a6668896c1b0620f930"} tree-sitter-lua = "0.0.14" +tree-sitter-nix = { git = "https://github.com/nix-community/tree-sitter-nix", rev = "66e3e9ce9180ae08fc57372061006ef83f0abde7" } [patch.crates-io] tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "49226023693107fba9a1191136a4f47f38cdca73" } diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index c5bf313701e76f1ea7084f7299f7596b7b0306df..88185acfc29f03f8e3cae0e51488c3e2234a684b 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -126,6 +126,7 @@ tree-sitter-svelte.workspace = true tree-sitter-racket.workspace = true tree-sitter-yaml.workspace = true tree-sitter-lua.workspace = true +tree-sitter-nix.workspace = true url = "2.2" urlencoding = "2.1.2" diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index 365e8a30232e5dc9193b1077b16186f3c44e9d19..9ba0f2755240e0e22357ffc2b8ea2fd6dda02dd3 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -152,6 +152,7 @@ pub fn init(languages: Arc, node_runtime: Arc) { tree_sitter_php::language(), vec![Arc::new(php::IntelephenseLspAdapter::new(node_runtime))], ); + language("nix", tree_sitter_nix::language(), vec![]) } #[cfg(any(test, feature = "test-support"))] diff --git a/crates/zed/src/languages/nix/config.toml b/crates/zed/src/languages/nix/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..778f0a6f050a72eb231d374eeff09bff3591cbdd --- /dev/null +++ b/crates/zed/src/languages/nix/config.toml @@ -0,0 +1,11 @@ +name = "Nix" +path_suffixes = ["nix"] +line_comment = "# " +block_comment = ["/* ", " */"] +autoclose_before = ";:.,=}])>` \n\t\"" +brackets = [ + { start = "{", end = "}", close = true, newline = true }, + { start = "[", end = "]", close = true, newline = true }, + { start = "(", end = ")", close = true, newline = true }, + { start = "<", end = ">", close = true, newline = true }, +] diff --git a/crates/zed/src/languages/nix/highlights.scm b/crates/zed/src/languages/nix/highlights.scm new file mode 100644 index 0000000000000000000000000000000000000000..d63a46411ae830a0b86d55a18e405a8086af6548 --- /dev/null +++ b/crates/zed/src/languages/nix/highlights.scm @@ -0,0 +1,95 @@ +(comment) @comment + +[ + "if" + "then" + "else" + "let" + "inherit" + "in" + "rec" + "with" + "assert" + "or" +] @keyword + +[ + (string_expression) + (indented_string_expression) +] @string + +[ + (path_expression) + (hpath_expression) + (spath_expression) +] @string.special.path + +(uri_expression) @link_uri + +[ + (integer_expression) + (float_expression) +] @number + +(interpolation + "${" @punctuation.special + "}" @punctuation.special) @embedded + +(escape_sequence) @escape +(dollar_escape) @escape + +(function_expression + universal: (identifier) @parameter +) + +(formal + name: (identifier) @parameter + "?"? @punctuation.delimiter) + +(select_expression + attrpath: (attrpath (identifier)) @property) + +(apply_expression + function: [ + (variable_expression (identifier)) @function + (select_expression + attrpath: (attrpath + attr: (identifier) @function .))]) + +(unary_expression + operator: _ @operator) + +(binary_expression + operator: _ @operator) + +(variable_expression (identifier) @variable) + +(binding + attrpath: (attrpath (identifier)) @property) + +"=" @operator + +[ + ";" + "." + "," +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(identifier) @variable + +((identifier) @function.builtin + (#match? @function.builtin "^(__add|__addErrorContext|__all|__any|__appendContext|__attrNames|__attrValues|__bitAnd|__bitOr|__bitXor|__catAttrs|__compareVersions|__concatLists|__concatMap|__concatStringsSep|__deepSeq|__div|__elem|__elemAt|__fetchurl|__filter|__filterSource|__findFile|__foldl'|__fromJSON|__functionArgs|__genList|__genericClosure|__getAttr|__getContext|__getEnv|__hasAttr|__hasContext|__hashFile|__hashString|__head|__intersectAttrs|__isAttrs|__isBool|__isFloat|__isFunction|__isInt|__isList|__isPath|__isString|__langVersion|__length|__lessThan|__listToAttrs|__mapAttrs|__match|__mul|__parseDrvName|__partition|__path|__pathExists|__readDir|__readFile|__replaceStrings|__seq|__sort|__split|__splitVersion|__storePath|__stringLength|__sub|__substring|__tail|__toFile|__toJSON|__toPath|__toXML|__trace|__tryEval|__typeOf|__unsafeDiscardOutputDependency|__unsafeDiscardStringContext|__unsafeGetAttrPos|__valueSize|abort|baseNameOf|derivation|derivationStrict|dirOf|fetchGit|fetchMercurial|fetchTarball|fromTOML|import|isNull|map|placeholder|removeAttrs|scopedImport|throw|toString)$") + (#is-not? local)) + +((identifier) @variable.builtin + (#match? @variable.builtin "^(__currentSystem|__currentTime|__nixPath|__nixVersion|__storeDir|builtins|false|null|true)$") + (#is-not? local)) From 2e0d051a787fa04f7e59ea14798a458533b059cf Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 27 Jul 2023 12:34:03 +0200 Subject: [PATCH 04/52] Maintain cursor stack's position correctly when ascending the tree This fixes a bug that could cause the cursor to incorrectly report its start when using `slice` or `seek_forward`, and then calling `prev`. We didn't notice this because we were not testing those three methods together. I suppose this could explain some of the panics we've observed because we do use `slice`/`seek_forward` followed by `prev` calls in production. --- crates/sum_tree/src/cursor.rs | 1 + crates/sum_tree/src/sum_tree.rs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/sum_tree/src/cursor.rs b/crates/sum_tree/src/cursor.rs index 59165283f6642fc2ea097113a61255cc98a6c25b..efd6ac145e0978ffc65cb5261bcd616b51aa71a6 100644 --- a/crates/sum_tree/src/cursor.rs +++ b/crates/sum_tree/src/cursor.rs @@ -438,6 +438,7 @@ where } => { if ascending { entry.index += 1; + entry.position = self.position.clone(); } for (child_tree, child_summary) in child_trees[entry.index..] diff --git a/crates/sum_tree/src/sum_tree.rs b/crates/sum_tree/src/sum_tree.rs index 8d219ca02110827d4c76fe170f6c541651148170..24a443051a4dede1a9b236c73c94b54c4ed9dd12 100644 --- a/crates/sum_tree/src/sum_tree.rs +++ b/crates/sum_tree/src/sum_tree.rs @@ -738,7 +738,7 @@ mod tests { for _ in 0..num_operations { let splice_end = rng.gen_range(0..tree.extent::(&()).0 + 1); let splice_start = rng.gen_range(0..splice_end + 1); - let count = rng.gen_range(0..3); + let count = rng.gen_range(0..10); let tree_end = tree.extent::(&()); let new_items = rng .sample_iter(distributions::Standard) @@ -805,10 +805,12 @@ mod tests { } assert_eq!(filter_cursor.item(), None); - let mut pos = rng.gen_range(0..tree.extent::(&()).0 + 1); let mut before_start = false; let mut cursor = tree.cursor::(); - cursor.seek(&Count(pos), Bias::Right, &()); + let start_pos = rng.gen_range(0..=reference_items.len()); + cursor.seek(&Count(start_pos), Bias::Right, &()); + let mut pos = rng.gen_range(start_pos..=reference_items.len()); + cursor.seek_forward(&Count(pos), Bias::Right, &()); for i in 0..10 { assert_eq!(cursor.start().0, pos); From 0ab1c6ac8ee896864ad3e3e45b30d0cf5b8c53f9 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 27 Jul 2023 10:25:46 -0400 Subject: [PATCH 05/52] Make LSP status message match new font size of diagnostic message --- styles/src/style_tree/status_bar.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles/src/style_tree/status_bar.ts b/styles/src/style_tree/status_bar.ts index 06afc378235ec843d64a28313a38c05d395f1962..6261939994ac4e7ae7e06090912218d5dcfb7f54 100644 --- a/styles/src/style_tree/status_bar.ts +++ b/styles/src/style_tree/status_bar.ts @@ -44,7 +44,7 @@ export default function status_bar(): any { icon_spacing: 4, icon_width: 14, height: 18, - message: text(layer, "sans"), + message: text(layer, "sans", { size: "xs" }), icon_color: foreground(layer), }, state: { From 8c9c8362ec1acfeb3f5e98215b961089f0cad336 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 27 Jul 2023 12:19:07 -0400 Subject: [PATCH 06/52] Update Alacritty --- Cargo.lock | 338 +++++++++++++++++++++++-- crates/terminal/Cargo.toml | 2 +- crates/terminal/src/mappings/colors.rs | 6 +- 3 files changed, 316 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 05c5faa787cf29f52b9150c4a224e98c653b2f2f..bc47e4dc0b5e1d114535b5b0bf77b95d05ff30b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,50 +125,52 @@ dependencies = [ [[package]] name = "alacritty_config" -version = "0.1.1-dev" -source = "git+https://github.com/zed-industries/alacritty?rev=a51dbe25d67e84d6ed4261e640d3954fbdd9be45#a51dbe25d67e84d6ed4261e640d3954fbdd9be45" +version = "0.1.2-dev" +source = "git+https://github.com/alacritty/alacritty?rev=7b9f32300ee0a249c0872302c97635b460e45ba5#7b9f32300ee0a249c0872302c97635b460e45ba5" dependencies = [ "log", "serde", - "serde_yaml", + "toml 0.7.6", + "winit", ] [[package]] name = "alacritty_config_derive" -version = "0.2.1-dev" -source = "git+https://github.com/zed-industries/alacritty?rev=a51dbe25d67e84d6ed4261e640d3954fbdd9be45#a51dbe25d67e84d6ed4261e640d3954fbdd9be45" +version = "0.2.2-dev" +source = "git+https://github.com/alacritty/alacritty?rev=7b9f32300ee0a249c0872302c97635b460e45ba5#7b9f32300ee0a249c0872302c97635b460e45ba5" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.27", ] [[package]] name = "alacritty_terminal" -version = "0.17.1-dev" -source = "git+https://github.com/zed-industries/alacritty?rev=a51dbe25d67e84d6ed4261e640d3954fbdd9be45#a51dbe25d67e84d6ed4261e640d3954fbdd9be45" +version = "0.20.0-dev" +source = "git+https://github.com/alacritty/alacritty?rev=7b9f32300ee0a249c0872302c97635b460e45ba5#7b9f32300ee0a249c0872302c97635b460e45ba5" dependencies = [ "alacritty_config", "alacritty_config_derive", "base64 0.13.1", - "bitflags 1.3.2", - "dirs 4.0.0", + "bitflags 2.3.3", + "home", "libc", "log", "mio 0.6.23", "mio-anonymous-pipes", "mio-extras", "miow 0.3.7", - "nix", + "nix 0.26.2", "parking_lot 0.12.1", "regex-automata 0.1.10", "serde", "serde_yaml", "signal-hook", "signal-hook-mio", + "toml 0.7.6", "unicode-width", "vte", - "winapi 0.3.9", + "windows-sys", ] [[package]] @@ -192,7 +194,7 @@ dependencies = [ "alsa-sys", "bitflags 1.3.2", "libc", - "nix", + "nix 0.24.3", ] [[package]] @@ -211,6 +213,30 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec8ad6edb4840b78c5c3d88de606b22252d552b55f3a4699fbb10fc070ec3049" +[[package]] +name = "android-activity" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40bc1575e653f158cbdc6ebcd917b9564e66321c5325c232c3591269c257be69" +dependencies = [ + "android-properties", + "bitflags 1.3.2", + "cc", + "jni-sys", + "libc", + "log", + "ndk", + "ndk-context", + "ndk-sys", + "num_enum 0.6.1", +] + +[[package]] +name = "android-properties" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -860,6 +886,9 @@ name = "bitflags" version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +dependencies = [ + "serde", +] [[package]] name = "bitvec" @@ -897,6 +926,25 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-sys" +version = "0.1.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146" +dependencies = [ + "objc-sys", +] + +[[package]] +name = "block2" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42" +dependencies = [ + "block-sys", + "objc2-encode", +] + [[package]] name = "blocking" version = "1.3.1" @@ -1078,6 +1126,20 @@ dependencies = [ "util", ] +[[package]] +name = "calloop" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e0d00eb1ea24371a97d2da6201c6747a633dc6dc1988ef503403b4c59504a8" +dependencies = [ + "bitflags 1.3.2", + "log", + "nix 0.25.1", + "slotmap", + "thiserror", + "vec_map", +] + [[package]] name = "cap-fs-ext" version = "0.24.4" @@ -1186,6 +1248,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chrono" version = "0.4.26" @@ -1462,7 +1530,7 @@ dependencies = [ "time 0.3.23", "tokio", "tokio-tungstenite", - "toml", + "toml 0.5.11", "tonic", "tower", "tracing", @@ -1987,6 +2055,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "cursor-icon" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf" +dependencies = [ + "serde", +] + [[package]] name = "dashmap" version = "5.5.0" @@ -2171,6 +2248,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" + [[package]] name = "dlib" version = "0.5.2" @@ -3230,6 +3313,15 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys", +] + [[package]] name = "hound" version = "3.5.0" @@ -4399,7 +4491,7 @@ dependencies = [ "bitflags 1.3.2", "jni-sys", "ndk-sys", - "num_enum", + "num_enum 0.5.11", "raw-window-handle", "thiserror", ] @@ -4439,9 +4531,33 @@ dependencies = [ "bitflags 1.3.2", "cfg-if 1.0.0", "libc", +] + +[[package]] +name = "nix" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if 1.0.0", + "libc", "memoffset 0.6.5", ] +[[package]] +name = "nix" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +dependencies = [ + "bitflags 1.3.2", + "cfg-if 1.0.0", + "libc", + "static_assertions", +] + [[package]] name = "node_runtime" version = "0.1.0" @@ -4595,7 +4711,16 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" dependencies = [ - "num_enum_derive", + "num_enum_derive 0.5.11", +] + +[[package]] +name = "num_enum" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +dependencies = [ + "num_enum_derive 0.6.1", ] [[package]] @@ -4610,6 +4735,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "num_enum_derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 2.0.27", +] + [[package]] name = "nvim-rs" version = "0.5.0" @@ -4635,6 +4772,32 @@ dependencies = [ "objc_exception", ] +[[package]] +name = "objc-sys" +version = "0.2.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7" + +[[package]] +name = "objc2" +version = "0.3.0-beta.3.patch-leaks.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e01640f9f2cb1220bbe80325e179e532cb3379ebcd1bf2279d703c19fe3a468" +dependencies = [ + "block2", + "objc-sys", + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "2.0.0-pre.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" +dependencies = [ + "objc-sys", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -4753,6 +4916,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "orbclient" +version = "0.3.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "221d488cd70617f1bd599ed8ceb659df2147d9393717954d82a0f5e8032a6ab1" +dependencies = [ + "redox_syscall 0.3.5", +] + [[package]] name = "ordered-float" version = "2.10.0" @@ -5182,7 +5354,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "toml", + "toml 0.5.11", ] [[package]] @@ -5287,7 +5459,7 @@ dependencies = [ "terminal", "text", "thiserror", - "toml", + "toml 0.5.11", "unindent", "util", ] @@ -6623,6 +6795,15 @@ dependencies = [ "syn 2.0.27", ] +[[package]] +name = "serde_spanned" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -6669,7 +6850,7 @@ dependencies = [ "smallvec", "sqlez", "staff_mode", - "toml", + "toml 0.5.11", "tree-sitter", "tree-sitter-json 0.19.0", "unindent", @@ -6855,6 +7036,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" +[[package]] +name = "slotmap" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +dependencies = [ + "version_check", +] + [[package]] name = "sluice" version = "0.5.5" @@ -6899,6 +7089,15 @@ dependencies = [ "pin-project-lite 0.1.12", ] +[[package]] +name = "smol_str" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c" +dependencies = [ + "serde", +] + [[package]] name = "snippet" version = "0.1.0" @@ -7502,7 +7701,7 @@ dependencies = [ "serde_derive", "serde_json", "settings", - "toml", + "toml 0.5.11", "util", ] @@ -7817,11 +8016,26 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -7830,6 +8044,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" dependencies = [ "indexmap 2.0.0", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] @@ -8589,6 +8805,12 @@ dependencies = [ "workspace", ] +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.4" @@ -8627,10 +8849,12 @@ dependencies = [ [[package]] name = "vte" -version = "0.10.1" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cbce692ab4ca2f1f3047fcf732430249c0e971bfdd2b234cf2c47ad93af5983" +checksum = "f5022b5fbf9407086c180e9557be968742d839e68346af7792b8592489732197" dependencies = [ + "log", + "serde", "utf8parse", "vte_generate_state_changes", ] @@ -8863,7 +9087,7 @@ dependencies = [ "rustix 0.33.7", "serde", "sha2 0.9.9", - "toml", + "toml 0.5.11", "winapi 0.3.9", "zstd", ] @@ -9051,6 +9275,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19353897b48e2c4d849a2d73cb0aeb16dc2be4e00c565abfc11eb65a806e47de" +dependencies = [ + "js-sys", + "once_cell", + "wasm-bindgen", +] + [[package]] name = "webpki" version = "0.21.4" @@ -9366,6 +9601,42 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "winit" +version = "0.29.0-beta.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f1afaf8490cc3f1309520ebb53a4cd3fc3642c7df8064a4b074bb9867998d44" +dependencies = [ + "android-activity", + "atomic-waker", + "bitflags 2.3.3", + "calloop", + "cfg_aliases", + "core-foundation", + "core-graphics", + "cursor-icon", + "dispatch", + "js-sys", + "libc", + "log", + "ndk", + "ndk-sys", + "objc2", + "once_cell", + "orbclient", + "raw-window-handle", + "redox_syscall 0.3.5", + "serde", + "smol_str", + "unicode-segmentation", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "web-time", + "windows-sys", + "xkbcommon-dl", +] + [[package]] name = "winnow" version = "0.5.1" @@ -9483,6 +9754,25 @@ dependencies = [ "libc", ] +[[package]] +name = "xkbcommon-dl" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6924668544c48c0133152e7eec86d644a056ca3d09275eb8d5cdb9855f9d8699" +dependencies = [ + "bitflags 2.3.3", + "dlib", + "log", + "once_cell", + "xkeysym", +] + +[[package]] +name = "xkeysym" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054a8e68b76250b253f671d1268cb7f1ae089ec35e195b2efb2a4e9a836d0621" + [[package]] name = "xmlparser" version = "0.13.5" @@ -9618,7 +9908,7 @@ dependencies = [ "theme_selector", "thiserror", "tiny_http", - "toml", + "toml 0.5.11", "tree-sitter", "tree-sitter-bash", "tree-sitter-c", diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml index a2902234c5fc2909b9974de0beba72b2bc973d64..fbcf0ec4b9e57267a55d8a6d5a7dee490ba403a9 100644 --- a/crates/terminal/Cargo.toml +++ b/crates/terminal/Cargo.toml @@ -16,7 +16,7 @@ db = { path = "../db" } theme = { path = "../theme" } util = { path = "../util" } -alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" } +alacritty_terminal = { git = "https://github.com/alacritty/alacritty", rev = "7b9f32300ee0a249c0872302c97635b460e45ba5" } procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false } smallvec.workspace = true smol.workspace = true diff --git a/crates/terminal/src/mappings/colors.rs b/crates/terminal/src/mappings/colors.rs index 3f776251b52693893f58eb6868a53ad995f5ab84..5f34327ea0370e2621274a99cfc249fc6d3f0e5b 100644 --- a/crates/terminal/src/mappings/colors.rs +++ b/crates/terminal/src/mappings/colors.rs @@ -114,11 +114,7 @@ fn rgb_for_index(i: &u8) -> (u8, u8, u8) { //Convenience method to convert from a GPUI color to an alacritty Rgb pub fn to_alac_rgb(color: Color) -> AlacRgb { - AlacRgb { - r: color.r, - g: color.g, - b: color.g, - } + AlacRgb::new(color.r, color.g, color.g) } #[cfg(test)] From 85f193dd09a099741cfb2c527c925cc20f0b9f6b Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 27 Jul 2023 12:25:53 -0400 Subject: [PATCH 07/52] Extract syntax highlighting properties from tree-sitter highlight queries --- crates/zed/src/languages/lua/highlights.scm | 4 +- crates/zed/src/languages/php/highlights.scm | 4 +- .../src/languages/typescript/highlights.scm | 6 +- styles/src/style_tree/editor.ts | 30 +- styles/src/theme/create_theme.ts | 11 +- styles/src/theme/syntax.ts | 382 +++--------------- styles/src/theme/theme_config.ts | 4 +- styles/src/theme/tokens/theme.ts | 6 +- styles/src/themes/atelier/common.ts | 5 +- styles/src/themes/ayu/common.ts | 6 +- styles/src/themes/gruvbox/gruvbox-common.ts | 6 +- styles/src/themes/one/one-dark.ts | 4 +- styles/src/themes/one/one-light.ts | 2 - styles/src/themes/rose-pine/common.ts | 4 +- styles/src/types/extract_syntax_types.ts | 102 +++++ styles/src/types/syntax.ts | 203 ++++++++++ 16 files changed, 419 insertions(+), 360 deletions(-) create mode 100644 styles/src/types/extract_syntax_types.ts create mode 100644 styles/src/types/syntax.ts diff --git a/crates/zed/src/languages/lua/highlights.scm b/crates/zed/src/languages/lua/highlights.scm index f061bbf8f91651605a7bcf946dcb576a82045aa6..60ca9de36b15098e9c76eaddff20238d5056adea 100644 --- a/crates/zed/src/languages/lua/highlights.scm +++ b/crates/zed/src/languages/lua/highlights.scm @@ -158,7 +158,7 @@ [ "{" "}" -] @constructor) +] @method.constructor) ;; Functions @@ -195,4 +195,4 @@ (number) @number -(string) @string \ No newline at end of file +(string) @string diff --git a/crates/zed/src/languages/php/highlights.scm b/crates/zed/src/languages/php/highlights.scm index fcb087c47d14dbc036ed79a50be7ff1b57ebc4e8..cfb03cbccad037d207ff1a1388c12eec22644f48 100644 --- a/crates/zed/src/languages/php/highlights.scm +++ b/crates/zed/src/languages/php/highlights.scm @@ -47,8 +47,8 @@ ((name) @constant.builtin (#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) -((name) @constructor - (#match? @constructor "^[A-Z]")) +((name) @method.constructor +(#match? @method.constructor "^[A-Z]")) ((name) @variable.builtin (#eq? @variable.builtin "this")) diff --git a/crates/zed/src/languages/typescript/highlights.scm b/crates/zed/src/languages/typescript/highlights.scm index bf086ea156f6ee9c2aca6bb9d2ebdd3f91997999..ba6b329e0e0def9c5d0c31d0df94525825ed2c45 100644 --- a/crates/zed/src/languages/typescript/highlights.scm +++ b/crates/zed/src/languages/typescript/highlights.scm @@ -43,8 +43,8 @@ ; Special identifiers -((identifier) @constructor - (#match? @constructor "^[A-Z]")) +((identifier) @method.constructor + (#match? @method.constructor "^[A-Z]")) ((identifier) @type (#match? @type "^[A-Z]")) @@ -218,4 +218,4 @@ "type" "readonly" "override" -] @keyword \ No newline at end of file +] @keyword diff --git a/styles/src/style_tree/editor.ts b/styles/src/style_tree/editor.ts index acf983e8bee13f24d2897191c283217e1ee2ee55..ccbb33e21dd8459f665531b9b4b19af8831946bd 100644 --- a/styles/src/style_tree/editor.ts +++ b/styles/src/style_tree/editor.ts @@ -9,9 +9,9 @@ import { } from "./components" import hover_popover from "./hover_popover" -import { build_syntax } from "../theme/syntax" import { interactive, toggleable } from "../element" import { useTheme } from "../theme" +import chroma from "chroma-js" export default function editor(): any { const theme = useTheme() @@ -48,16 +48,28 @@ export default function editor(): any { } } - const syntax = build_syntax() - return { - text_color: syntax.primary.color, + text_color: theme.syntax.primary.color, background: background(layer), active_line_background: with_opacity(background(layer, "on"), 0.75), highlighted_line_background: background(layer, "on"), // Inline autocomplete suggestions, Co-pilot suggestions, etc. - hint: syntax.hint, - suggestion: syntax.predictive, + hint: chroma + .mix( + theme.ramps.neutral(0.6).hex(), + theme.ramps.blue(0.4).hex(), + 0.45, + "lch" + ) + .hex(), + suggestion: chroma + .mix( + theme.ramps.neutral(0.4).hex(), + theme.ramps.blue(0.4).hex(), + 0.45, + "lch" + ) + .hex(), code_actions: { indicator: toggleable({ base: interactive({ @@ -255,8 +267,8 @@ export default function editor(): any { invalid_warning_diagnostic: diagnostic(theme.middle, "base"), hover_popover: hover_popover(), link_definition: { - color: syntax.link_uri.color, - underline: syntax.link_uri.underline, + color: theme.syntax.link_uri.color, + underline: theme.syntax.link_uri.underline, }, jump_icon: interactive({ base: { @@ -314,6 +326,6 @@ export default function editor(): any { color: border_color(layer), }, }, - syntax, + syntax: theme.syntax, } } diff --git a/styles/src/theme/create_theme.ts b/styles/src/theme/create_theme.ts index d2701f8341af973a3a4511c149c983cb221fa14d..e52c4dc95b361572d8cbdc388c04146cecc81e8c 100644 --- a/styles/src/theme/create_theme.ts +++ b/styles/src/theme/create_theme.ts @@ -1,12 +1,12 @@ import { Scale, Color } from "chroma-js" -import { Syntax, ThemeSyntax, SyntaxHighlightStyle } from "./syntax" -export { Syntax, ThemeSyntax, SyntaxHighlightStyle } import { ThemeConfig, ThemeAppearance, - ThemeConfigInputColors, + ThemeConfigInputColors } from "./theme_config" import { get_ramps } from "./ramps" +import { syntaxStyle } from "./syntax" +import { Syntax } from "../types/syntax" export interface Theme { name: string @@ -31,7 +31,7 @@ export interface Theme { modal_shadow: Shadow players: Players - syntax?: Partial + syntax: Syntax } export interface Meta { @@ -119,7 +119,6 @@ export function create_theme(theme: ThemeConfig): Theme { name, appearance, input_color, - override: { syntax }, } = theme const is_light = appearance === ThemeAppearance.Light @@ -162,6 +161,8 @@ export function create_theme(theme: ThemeConfig): Theme { "7": player(ramps.yellow), } + const syntax = syntaxStyle(ramps, theme.override.syntax ? theme.override.syntax : {}) + return { name, is_light, diff --git a/styles/src/theme/syntax.ts b/styles/src/theme/syntax.ts index 540a1d0ff9822d5a8c2cf292ddba5ace6839ac6d..d39496a412904647ea2deb8c74048c864ab31550 100644 --- a/styles/src/theme/syntax.ts +++ b/styles/src/theme/syntax.ts @@ -1,332 +1,80 @@ import deepmerge from "deepmerge" -import { FontWeight, font_weights, useTheme } from "../common" -import chroma from "chroma-js" +import { font_weights, ThemeConfigInputSyntax, RampSet } from "../common" +import { Syntax, SyntaxHighlightStyle, allSyntaxKeys } from "../types/syntax" -export interface SyntaxHighlightStyle { - color?: string - weight?: FontWeight - underline?: boolean - italic?: boolean -} - -export interface Syntax { - // == Text Styles ====== / - comment: SyntaxHighlightStyle - // elixir: doc comment - "comment.doc": SyntaxHighlightStyle - primary: SyntaxHighlightStyle - predictive: SyntaxHighlightStyle - hint: SyntaxHighlightStyle - - // === Formatted Text ====== / - emphasis: SyntaxHighlightStyle - "emphasis.strong": SyntaxHighlightStyle - title: SyntaxHighlightStyle - link_uri: SyntaxHighlightStyle - link_text: SyntaxHighlightStyle - /** md: indented_code_block, fenced_code_block, code_span */ - "text.literal": SyntaxHighlightStyle - - // == Punctuation ====== / - punctuation: SyntaxHighlightStyle - /** Example: `(`, `[`, `{`...*/ - "punctuation.bracket": SyntaxHighlightStyle - /**., ;*/ - "punctuation.delimiter": SyntaxHighlightStyle - // js, ts: ${, } in a template literal - // yaml: *, &, ---, ... - "punctuation.special": SyntaxHighlightStyle - // md: list_marker_plus, list_marker_dot, etc - "punctuation.list_marker": SyntaxHighlightStyle - - // == Strings ====== / - - string: SyntaxHighlightStyle - // css: color_value - // js: this, super - // toml: offset_date_time, local_date_time... - "string.special": SyntaxHighlightStyle - // elixir: atom, quoted_atom, keyword, quoted_keyword - // ruby: simple_symbol, delimited_symbol... - "string.special.symbol"?: SyntaxHighlightStyle - // elixir, python, yaml...: escape_sequence - "string.escape"?: SyntaxHighlightStyle - // Regular expressions - "string.regex"?: SyntaxHighlightStyle - - // == Types ====== / - // We allow Function here because all JS objects literals have this property - constructor: SyntaxHighlightStyle | Function // eslint-disable-line @typescript-eslint/ban-types - variant: SyntaxHighlightStyle - type: SyntaxHighlightStyle - // js: predefined_type - "type.builtin"?: SyntaxHighlightStyle - - // == Values - variable: SyntaxHighlightStyle - // this, ... - // css: -- (var(--foo)) - // lua: self - "variable.special"?: SyntaxHighlightStyle - // c: statement_identifier, - label: SyntaxHighlightStyle - // css: tag_name, nesting_selector, universal_selector... - tag: SyntaxHighlightStyle - // css: attribute, pseudo_element_selector (tag_name), - attribute: SyntaxHighlightStyle - // css: class_name, property_name, namespace_name... - property: SyntaxHighlightStyle - // true, false, null, nullptr - constant: SyntaxHighlightStyle - // css: @media, @import, @supports... - // js: declare, implements, interface, keyof, public... - keyword: SyntaxHighlightStyle - // note: js enum is currently defined as a keyword - enum: SyntaxHighlightStyle - // -, --, ->, !=, &&, ||, <=... - operator: SyntaxHighlightStyle - number: SyntaxHighlightStyle - boolean: SyntaxHighlightStyle - // elixir: __MODULE__, __DIR__, __ENV__, etc - // go: nil, iota - "constant.builtin"?: SyntaxHighlightStyle - - // == Functions ====== / - - function: SyntaxHighlightStyle - // lua: assert, error, loadfile, tostring, unpack... - "function.builtin"?: SyntaxHighlightStyle - // go: call_expression, method_declaration - // js: call_expression, method_definition, pair (key, arrow function) - // rust: function_item name: (identifier) - "function.definition"?: SyntaxHighlightStyle - // rust: macro_definition name: (identifier) - "function.special.definition"?: SyntaxHighlightStyle - "function.method"?: SyntaxHighlightStyle - // ruby: identifier/"defined?" // Nate note: I don't fully understand this one. - "function.method.builtin"?: SyntaxHighlightStyle - - // == Unsorted ====== / - // lua: hash_bang_line - preproc: SyntaxHighlightStyle - // elixir, python: interpolation (ex: foo in ${foo}) - // js: template_substitution - embedded: SyntaxHighlightStyle -} - -export type ThemeSyntax = Partial +// Apply defaults to any missing syntax properties that are not defined manually +function apply_defaults(ramps: RampSet, syntax_highlights: Partial): Syntax { + const restKeys: (keyof Syntax)[] = allSyntaxKeys.filter(key => !syntax_highlights[key]) -const default_syntax_highlight_style: Omit = { - weight: "normal", - underline: false, - italic: false, -} - -function build_default_syntax(): Syntax { - const theme = useTheme() + const completeSyntax: Syntax = {} as Syntax - // Make a temporary object that is allowed to be missing - // the "color" property for each style - const syntax: { - [key: string]: Omit - } = {} + const defaults: SyntaxHighlightStyle = { + color: ramps.neutral(1).hex(), + } - // then spread the default to each style - for (const key of Object.keys({} as Syntax)) { - syntax[key as keyof Syntax] = { - ...default_syntax_highlight_style, + for (const key of restKeys) { + { + completeSyntax[key] = { + ...defaults, + } } } - // Mix the neutral and blue colors to get a - // predictive color distinct from any other color in the theme - const predictive = chroma - .mix( - theme.ramps.neutral(0.4).hex(), - theme.ramps.blue(0.4).hex(), - 0.45, - "lch" - ) - .hex() - // Mix the neutral and green colors to get a - // hint color distinct from any other color in the theme - const hint = chroma - .mix( - theme.ramps.neutral(0.6).hex(), - theme.ramps.blue(0.4).hex(), - 0.45, - "lch" - ) - .hex() + const mergedBaseSyntax = Object.assign(completeSyntax, syntax_highlights) - const color = { - primary: theme.ramps.neutral(1).hex(), - comment: theme.ramps.neutral(0.71).hex(), - punctuation: theme.ramps.neutral(0.86).hex(), - predictive: predictive, - hint: hint, - emphasis: theme.ramps.blue(0.5).hex(), - string: theme.ramps.orange(0.5).hex(), - function: theme.ramps.yellow(0.5).hex(), - type: theme.ramps.cyan(0.5).hex(), - constructor: theme.ramps.blue(0.5).hex(), - variant: theme.ramps.blue(0.5).hex(), - property: theme.ramps.blue(0.5).hex(), - enum: theme.ramps.orange(0.5).hex(), - operator: theme.ramps.orange(0.5).hex(), - number: theme.ramps.green(0.5).hex(), - boolean: theme.ramps.green(0.5).hex(), - constant: theme.ramps.green(0.5).hex(), - keyword: theme.ramps.blue(0.5).hex(), - } - - // Then assign colors and use Syntax to enforce each style getting it's own color - const default_syntax: Syntax = { - ...syntax, - comment: { - color: color.comment, - }, - "comment.doc": { - color: color.comment, - }, - primary: { - color: color.primary, - }, - predictive: { - color: color.predictive, - italic: true, - }, - hint: { - color: color.hint, - weight: font_weights.bold, - }, - emphasis: { - color: color.emphasis, - }, - "emphasis.strong": { - color: color.emphasis, - weight: font_weights.bold, - }, - title: { - color: color.primary, - weight: font_weights.bold, - }, - link_uri: { - color: theme.ramps.green(0.5).hex(), - underline: true, - }, - link_text: { - color: theme.ramps.orange(0.5).hex(), - italic: true, - }, - "text.literal": { - color: color.string, - }, - punctuation: { - color: color.punctuation, - }, - "punctuation.bracket": { - color: color.punctuation, - }, - "punctuation.delimiter": { - color: color.punctuation, - }, - "punctuation.special": { - color: theme.ramps.neutral(0.86).hex(), - }, - "punctuation.list_marker": { - color: color.punctuation, - }, - string: { - color: color.string, - }, - "string.special": { - color: color.string, - }, - "string.special.symbol": { - color: color.string, - }, - "string.escape": { - color: color.comment, - }, - "string.regex": { - color: color.string, - }, - constructor: { - color: theme.ramps.blue(0.5).hex(), - }, - variant: { - color: theme.ramps.blue(0.5).hex(), - }, - type: { - color: color.type, - }, - variable: { - color: color.primary, - }, - label: { - color: theme.ramps.blue(0.5).hex(), - }, - tag: { - color: theme.ramps.blue(0.5).hex(), - }, - attribute: { - color: theme.ramps.blue(0.5).hex(), - }, - property: { - color: theme.ramps.blue(0.5).hex(), - }, - constant: { - color: color.constant, - }, - keyword: { - color: color.keyword, - }, - enum: { - color: color.enum, - }, - operator: { - color: color.operator, - }, - number: { - color: color.number, - }, - boolean: { - color: color.boolean, - }, - function: { - color: color.function, - }, - preproc: { - color: color.primary, - }, - embedded: { - color: color.primary, - }, - } - - return default_syntax + return mergedBaseSyntax } -export function build_syntax(): Syntax { - const theme = useTheme() - - const default_syntax: Syntax = build_default_syntax() +// Merge the base syntax with the theme syntax overrides +// This is a deep merge, so any nested properties will be merged as well +// This allows for a theme to only override a single property of a syntax highlight style +const merge_syntax = (baseSyntax: Syntax, theme_syntax_overrides: ThemeConfigInputSyntax): Syntax => { + return deepmerge(baseSyntax, theme_syntax_overrides, { + arrayMerge: (destinationArray, sourceArray) => [ + ...destinationArray, + ...sourceArray, + ], + }) +} - if (!theme.syntax) { - return default_syntax +/** Returns a complete Syntax object of the combined styles of a theme's syntax overrides and the default syntax styles */ +export const syntaxStyle = (ramps: RampSet, theme_syntax_overrides: ThemeConfigInputSyntax): Syntax => { + const syntax_highlights: Partial = { + "comment": { color: ramps.neutral(0.71).hex() }, + "comment.doc": { color: ramps.neutral(0.71).hex() }, + primary: { color: ramps.neutral(1).hex() }, + emphasis: { color: ramps.blue(0.5).hex() }, + "emphasis.strong": { color: ramps.blue(0.5).hex(), weight: font_weights.bold }, + link_uri: { color: ramps.green(0.5).hex(), underline: true }, + link_text: { color: ramps.orange(0.5).hex(), italic: true }, + "text.literal": { color: ramps.orange(0.5).hex() }, + punctuation: { color: ramps.neutral(0.86).hex() }, + "punctuation.bracket": { color: ramps.neutral(0.86).hex() }, + "punctuation.special": { color: ramps.neutral(0.86).hex() }, + "punctuation.delimiter": { color: ramps.neutral(0.86).hex() }, + "punctuation.list_marker": { color: ramps.neutral(0.86).hex() }, + string: { color: ramps.orange(0.5).hex() }, + "string.special": { color: ramps.orange(0.5).hex() }, + "string.special.symbol": { color: ramps.orange(0.5).hex() }, + "string.escape": { color: ramps.neutral(0.71).hex() }, + "string.regex": { color: ramps.orange(0.5).hex() }, + "method.constructor": { color: ramps.blue(0.5).hex() }, + type: { color: ramps.cyan(0.5).hex() }, + variable: { color: ramps.neutral(1).hex() }, + label: { color: ramps.blue(0.5).hex() }, + attribute: { color: ramps.blue(0.5).hex() }, + property: { color: ramps.blue(0.5).hex() }, + constant: { color: ramps.green(0.5).hex() }, + keyword: { color: ramps.blue(0.5).hex() }, + operator: { color: ramps.orange(0.5).hex() }, + number: { color: ramps.green(0.5).hex() }, + boolean: { color: ramps.green(0.5).hex() }, + function: { color: ramps.yellow(0.5).hex() }, + preproc: { color: ramps.neutral(1).hex() }, + embedded: { color: ramps.neutral(1).hex() }, } - const syntax = deepmerge>( - default_syntax, - theme.syntax, - { - arrayMerge: (destinationArray, sourceArray) => [ - ...destinationArray, - ...sourceArray, - ], - } - ) - - return syntax + const baseSyntax = apply_defaults(ramps, syntax_highlights) + const mergedSyntax = merge_syntax(baseSyntax, theme_syntax_overrides) + return mergedSyntax } diff --git a/styles/src/theme/theme_config.ts b/styles/src/theme/theme_config.ts index bc8f07425f9e676a27d36ec929ea9a116006c694..8473bbb600608cac6157f894f3e9ac5d91c31a31 100644 --- a/styles/src/theme/theme_config.ts +++ b/styles/src/theme/theme_config.ts @@ -1,5 +1,5 @@ import { Scale, Color } from "chroma-js" -import { Syntax } from "./syntax" +import { SyntaxHighlightStyle, SyntaxProperty } from "../types/syntax" interface ThemeMeta { /** The name of the theme */ @@ -55,7 +55,7 @@ export type ThemeConfigInputColorsKeys = keyof ThemeConfigInputColors * } * ``` */ -export type ThemeConfigInputSyntax = Partial +export type ThemeConfigInputSyntax = Partial>> interface ThemeConfigOverrides { syntax: ThemeConfigInputSyntax diff --git a/styles/src/theme/tokens/theme.ts b/styles/src/theme/tokens/theme.ts index f759bc813910416d88a2097134dc95654d6ab3b3..f9e83e0512012e0c5d699ac432869a70520a9839 100644 --- a/styles/src/theme/tokens/theme.ts +++ b/styles/src/theme/tokens/theme.ts @@ -6,15 +6,13 @@ import { } from "@tokens-studio/types" import { Shadow, - SyntaxHighlightStyle, - ThemeSyntax, } from "../create_theme" import { LayerToken, layer_token } from "./layer" import { PlayersToken, players_token } from "./players" import { color_token } from "./token" -import { Syntax } from "../syntax" import editor from "../../style_tree/editor" import { useTheme } from "../../../src/common" +import { Syntax, SyntaxHighlightStyle } from "../../types/syntax" interface ThemeTokens { name: SingleOtherToken @@ -51,7 +49,7 @@ const modal_shadow_token = (): SingleBoxShadowToken => { return create_shadow_token(shadow, "modal_shadow") } -type ThemeSyntaxColorTokens = Record +type ThemeSyntaxColorTokens = Record function syntax_highlight_style_color_tokens( syntax: Syntax diff --git a/styles/src/themes/atelier/common.ts b/styles/src/themes/atelier/common.ts index b76ccc5b607a2f149a35114a519ddaaf2d1b254d..09226b336c0aae3d42a4e99130e1c46875d6065b 100644 --- a/styles/src/themes/atelier/common.ts +++ b/styles/src/themes/atelier/common.ts @@ -1,4 +1,4 @@ -import { ThemeLicenseType, ThemeSyntax, ThemeFamilyMeta } from "../../common" +import { ThemeLicenseType, ThemeFamilyMeta, ThemeConfigInputSyntax } from "../../common" export interface Variant { colors: { @@ -29,7 +29,7 @@ export const meta: ThemeFamilyMeta = { "https://atelierbram.github.io/syntax-highlighting/atelier-schemes/cave/", } -export const build_syntax = (variant: Variant): ThemeSyntax => { +export const build_syntax = (variant: Variant): ThemeConfigInputSyntax => { const { colors } = variant return { primary: { color: colors.base06 }, @@ -50,7 +50,6 @@ export const build_syntax = (variant: Variant): ThemeSyntax => { property: { color: colors.base08 }, variable: { color: colors.base06 }, "variable.special": { color: colors.base0E }, - variant: { color: colors.base0A }, keyword: { color: colors.base0E }, } } diff --git a/styles/src/themes/ayu/common.ts b/styles/src/themes/ayu/common.ts index 2bd0bbf259aef2d9fc6c084f1da3c72379927026..870445588646b57f347fe9e90e07b286b3b73790 100644 --- a/styles/src/themes/ayu/common.ts +++ b/styles/src/themes/ayu/common.ts @@ -3,8 +3,8 @@ import { chroma, color_ramp, ThemeLicenseType, - ThemeSyntax, ThemeFamilyMeta, + ThemeConfigInputSyntax, } from "../../common" export const ayu = { @@ -27,7 +27,7 @@ export const build_theme = (t: typeof dark, light: boolean) => { purple: t.syntax.constant.hex(), } - const syntax: ThemeSyntax = { + const syntax: ThemeConfigInputSyntax = { constant: { color: t.syntax.constant.hex() }, "string.regex": { color: t.syntax.regexp.hex() }, string: { color: t.syntax.string.hex() }, @@ -61,7 +61,7 @@ export const build_theme = (t: typeof dark, light: boolean) => { } } -export const build_syntax = (t: typeof dark): ThemeSyntax => { +export const build_syntax = (t: typeof dark): ThemeConfigInputSyntax => { return { constant: { color: t.syntax.constant.hex() }, "string.regex": { color: t.syntax.regexp.hex() }, diff --git a/styles/src/themes/gruvbox/gruvbox-common.ts b/styles/src/themes/gruvbox/gruvbox-common.ts index 2fa6b58faadb91b5689c5eac93baf706f6faa391..95e45efa95122ec3ca37d2dc57360ca55ec83e85 100644 --- a/styles/src/themes/gruvbox/gruvbox-common.ts +++ b/styles/src/themes/gruvbox/gruvbox-common.ts @@ -4,8 +4,8 @@ import { ThemeAppearance, ThemeLicenseType, ThemeConfig, - ThemeSyntax, ThemeFamilyMeta, + ThemeConfigInputSyntax, } from "../../common" const meta: ThemeFamilyMeta = { @@ -214,7 +214,7 @@ const build_variant = (variant: Variant): ThemeConfig => { magenta: color_ramp(chroma(variant.colors.gray)), } - const syntax: ThemeSyntax = { + const syntax: ThemeConfigInputSyntax = { primary: { color: neutral[is_light ? 0 : 8] }, "text.literal": { color: colors.blue }, comment: { color: colors.gray }, @@ -229,7 +229,7 @@ const build_variant = (variant: Variant): ThemeConfig => { "string.special.symbol": { color: colors.aqua }, "string.regex": { color: colors.orange }, type: { color: colors.yellow }, - enum: { color: colors.orange }, + // enum: { color: colors.orange }, tag: { color: colors.aqua }, constant: { color: colors.yellow }, keyword: { color: colors.red }, diff --git a/styles/src/themes/one/one-dark.ts b/styles/src/themes/one/one-dark.ts index f672b892ee040e60745f3d0f8bd6875c743ed46a..97f3922f36f57c7452c8face077a8b2bc8997858 100644 --- a/styles/src/themes/one/one-dark.ts +++ b/styles/src/themes/one/one-dark.ts @@ -54,7 +54,6 @@ export const theme: ThemeConfig = { syntax: { boolean: { color: color.orange }, comment: { color: color.grey }, - enum: { color: color.red }, "emphasis.strong": { color: color.orange }, function: { color: color.blue }, keyword: { color: color.purple }, @@ -73,8 +72,7 @@ export const theme: ThemeConfig = { "text.literal": { color: color.green }, type: { color: color.teal }, "variable.special": { color: color.orange }, - variant: { color: color.blue }, - constructor: { color: color.blue }, + "method.constructor": { color: color.blue }, }, }, } diff --git a/styles/src/themes/one/one-light.ts b/styles/src/themes/one/one-light.ts index c3de7826c96679fb1c1f2b1a9d81324687d919b9..655428757898a7f07f4524377721ab62ef1f5b53 100644 --- a/styles/src/themes/one/one-light.ts +++ b/styles/src/themes/one/one-light.ts @@ -55,7 +55,6 @@ export const theme: ThemeConfig = { syntax: { boolean: { color: color.orange }, comment: { color: color.grey }, - enum: { color: color.red }, "emphasis.strong": { color: color.orange }, function: { color: color.blue }, keyword: { color: color.purple }, @@ -73,7 +72,6 @@ export const theme: ThemeConfig = { "text.literal": { color: color.green }, type: { color: color.teal }, "variable.special": { color: color.orange }, - variant: { color: color.blue }, }, }, } diff --git a/styles/src/themes/rose-pine/common.ts b/styles/src/themes/rose-pine/common.ts index 5c5482a754a634bd2338af2613327554ec36d13c..decccc0a6dc8b1062ec8d5a88a699350a79bf322 100644 --- a/styles/src/themes/rose-pine/common.ts +++ b/styles/src/themes/rose-pine/common.ts @@ -1,4 +1,4 @@ -import { ThemeSyntax } from "../../common" +import { ThemeConfigInputSyntax } from "../../common" export const color = { default: { @@ -54,7 +54,7 @@ export const color = { }, } -export const syntax = (c: typeof color.default): Partial => { +export const syntax = (c: typeof color.default): ThemeConfigInputSyntax => { return { comment: { color: c.muted }, operator: { color: c.pine }, diff --git a/styles/src/types/extract_syntax_types.ts b/styles/src/types/extract_syntax_types.ts new file mode 100644 index 0000000000000000000000000000000000000000..3bf089518233a8b264e71853ad83e2634f9c1ab3 --- /dev/null +++ b/styles/src/types/extract_syntax_types.ts @@ -0,0 +1,102 @@ +import fs from 'fs' +import path from 'path' +import readline from 'readline' + +function escapeTypeName(name: string): string { + return `'${name.replace('@', '').toLowerCase()}'` +} + +const generatedNote = `// This file is generated by extract_syntax_types.ts +// Do not edit this file directly +// It is generated from the highlight.scm files in the zed crate + +// To regenerate this file manually: +// 'npm run extract-syntax-types' from ./styles` + +const defaultTextProperty = ` /** Default text color */ + | 'primary'` + +const main = async () => { + const pathFromRoot = 'crates/zed/src/languages' + const directoryPath = path.join(__dirname, '../../../', pathFromRoot) + const stylesMap: Record> = {} + const propertyLanguageMap: Record> = {} + + const processFile = async (filePath: string, language: string) => { + const fileStream = fs.createReadStream(filePath) + const rl = readline.createInterface({ + input: fileStream, + crlfDelay: Infinity, + }) + + for await (const line of rl) { + const cleanedLine = line.replace(/"@[a-zA-Z0-9_.]*"/g, "") + const match = cleanedLine.match(/@(\w+\.*)*/g) + if (match) { + match.forEach((property) => { + const formattedProperty = escapeTypeName(property) + // Only add non-empty properties + if (formattedProperty !== "''") { + if (!propertyLanguageMap[formattedProperty]) { + propertyLanguageMap[formattedProperty] = new Set() + } + propertyLanguageMap[formattedProperty].add(language) + } + }) + } + } + } + + const directories = fs.readdirSync(directoryPath, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => dirent.name) + + for (const dir of directories) { + const highlightsFilePath = path.join(directoryPath, dir, 'highlights.scm') + if (fs.existsSync(highlightsFilePath)) { + await processFile(highlightsFilePath, dir) + } + } + + for (const [language, properties] of Object.entries(stylesMap)) { + console.log(`${language}: ${Array.from(properties).join(', ')}`) + } + + const sortedProperties = Object.entries(propertyLanguageMap).sort(([propA], [propB]) => propA.localeCompare(propB)) + + const outStream = fs.createWriteStream(path.join(__dirname, 'syntax.ts')) + let allProperties = "" + const syntaxKeys = [] + for (const [property, languages] of sortedProperties) { + let languagesArray = Array.from(languages) + const moreThanSeven = languagesArray.length > 7 + // Limit to the first 7 languages, append "..." if more than 7 + languagesArray = languagesArray.slice(0, 7) + if (moreThanSeven) { + languagesArray.push('...') + } + const languagesString = languagesArray.join(', ') + const comment = `/** ${languagesString} */` + allProperties += ` ${comment}\n | ${property} \n` + syntaxKeys.push(property) + } + outStream.write(`${generatedNote} + +export type SyntaxHighlightStyle = { + color: string, + fade_out?: number, + italic?: boolean, + underline?: boolean, + weight?: string, +} + +export type Syntax = Record +export type SyntaxOverride = Partial + +export type SyntaxProperty = \n${defaultTextProperty}\n\n${allProperties} + +export const allSyntaxKeys: SyntaxProperty[] = [\n ${syntaxKeys.join(',\n ')}\n]`) + outStream.end() +} + +main().catch(console.error) diff --git a/styles/src/types/syntax.ts b/styles/src/types/syntax.ts new file mode 100644 index 0000000000000000000000000000000000000000..b74edfdf8463e510c40fee84c35e5d22d6586d83 --- /dev/null +++ b/styles/src/types/syntax.ts @@ -0,0 +1,203 @@ +// This file is generated by extract_syntax_types.ts +// Do not edit this file directly +// It is generated from the highlight.scm files in the zed crate + +// To regenerate this file manually: +// 'npm run extract-syntax-types' from ./styles + +export type SyntaxHighlightStyle = { + color: string, + fade_out?: number, + italic?: boolean, + underline?: boolean, + weight?: string, +} + +export type Syntax = Record +export type SyntaxOverride = Partial + +export type SyntaxProperty = + /** Default text color */ + | 'primary' + + /** elixir */ + | '__attribute__' + /** elixir */ + | '__name__' + /** elixir */ + | '_sigil_name' + /** css, heex, lua */ + | 'attribute' + /** javascript, lua, tsx, typescript, yaml */ + | 'boolean' + /** elixir */ + | 'comment.doc' + /** elixir */ + | 'comment.unused' + /** bash, c, cpp, css, elixir, elm, erb, ... */ + | 'comment' + /** elixir, go, javascript, lua, php, python, racket, ... */ + | 'constant.builtin' + /** bash, c, cpp, elixir, elm, glsl, heex, ... */ + | 'constant' + /** glsl */ + | 'delimiter' + /** bash, elixir, javascript, python, ruby, tsx, typescript */ + | 'embedded' + /** markdown */ + | 'emphasis.strong' + /** markdown */ + | 'emphasis' + /** go, python, racket, ruby, scheme */ + | 'escape' + /** lua */ + | 'field' + /** lua, php, python */ + | 'function.builtin' + /** elm, lua, rust */ + | 'function.definition' + /** ruby */ + | 'function.method.builtin' + /** go, javascript, php, python, ruby, rust, tsx, ... */ + | 'function.method' + /** rust */ + | 'function.special.definition' + /** c, cpp, glsl, rust */ + | 'function.special' + /** bash, c, cpp, css, elixir, elm, glsl, ... */ + | 'function' + /** elm */ + | 'identifier' + /** glsl */ + | 'keyword.function' + /** bash, c, cpp, css, elixir, elm, erb, ... */ + | 'keyword' + /** c, cpp, glsl */ + | 'label' + /** markdown */ + | 'link_text' + /** markdown */ + | 'link_uri' + /** lua, php, tsx, typescript */ + | 'method.constructor' + /** lua */ + | 'method' + /** heex */ + | 'module' + /** svelte */ + | 'none' + /** bash, c, cpp, css, elixir, glsl, go, ... */ + | 'number' + /** bash, c, cpp, css, elixir, elm, glsl, ... */ + | 'operator' + /** lua */ + | 'parameter' + /** lua */ + | 'preproc' + /** bash, c, cpp, css, glsl, go, html, ... */ + | 'property' + /** c, cpp, elixir, elm, heex, html, javascript, ... */ + | 'punctuation.bracket' + /** c, cpp, css, elixir, elm, heex, javascript, ... */ + | 'punctuation.delimiter' + /** markdown */ + | 'punctuation.list_marker' + /** elixir, javascript, python, ruby, tsx, typescript, yaml */ + | 'punctuation.special' + /** elixir */ + | 'punctuation' + /** glsl */ + | 'storageclass' + /** elixir, elm, yaml */ + | 'string.escape' + /** elixir, javascript, racket, ruby, tsx, typescript */ + | 'string.regex' + /** elixir, ruby */ + | 'string.special.symbol' + /** css, elixir, toml */ + | 'string.special' + /** bash, c, cpp, css, elixir, elm, glsl, ... */ + | 'string' + /** svelte */ + | 'tag.delimiter' + /** css, heex, php, svelte */ + | 'tag' + /** markdown */ + | 'text.literal' + /** markdown */ + | 'title' + /** javascript, php, rust, tsx, typescript */ + | 'type.builtin' + /** glsl */ + | 'type.qualifier' + /** c, cpp, css, elixir, elm, glsl, go, ... */ + | 'type' + /** glsl, php */ + | 'variable.builtin' + /** cpp, css, javascript, lua, racket, ruby, rust, ... */ + | 'variable.special' + /** c, cpp, elm, glsl, go, javascript, lua, ... */ + | 'variable' + + +export const allSyntaxKeys: SyntaxProperty[] = [ + '__attribute__', + '__name__', + '_sigil_name', + 'attribute', + 'boolean', + 'comment.doc', + 'comment.unused', + 'comment', + 'constant.builtin', + 'constant', + 'delimiter', + 'embedded', + 'emphasis.strong', + 'emphasis', + 'escape', + 'field', + 'function.builtin', + 'function.definition', + 'function.method.builtin', + 'function.method', + 'function.special.definition', + 'function.special', + 'function', + 'identifier', + 'keyword.function', + 'keyword', + 'label', + 'link_text', + 'link_uri', + 'method.constructor', + 'method', + 'module', + 'none', + 'number', + 'operator', + 'parameter', + 'preproc', + 'property', + 'punctuation.bracket', + 'punctuation.delimiter', + 'punctuation.list_marker', + 'punctuation.special', + 'punctuation', + 'storageclass', + 'string.escape', + 'string.regex', + 'string.special.symbol', + 'string.special', + 'string', + 'tag.delimiter', + 'tag', + 'text.literal', + 'title', + 'type.builtin', + 'type.qualifier', + 'type', + 'variable.builtin', + 'variable.special', + 'variable' +] \ No newline at end of file From 86fa27eb54838e69292307c30ac611e0d32993c5 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 27 Jul 2023 12:41:19 -0400 Subject: [PATCH 08/52] Update uses of `#` to `.` in our scheme files where they are interchangeable. uses of `#` cause ERRORs in our scheme highlighting --- crates/zed/src/languages/bash/highlights.scm | 2 +- crates/zed/src/languages/c/highlights.scm | 3 +-- crates/zed/src/languages/c/injections.scm | 4 ++-- crates/zed/src/languages/cpp/highlights.scm | 4 ++-- crates/zed/src/languages/cpp/injections.scm | 4 ++-- crates/zed/src/languages/css/highlights.scm | 2 +- crates/zed/src/languages/elixir/embedding.scm | 6 +++--- crates/zed/src/languages/elixir/highlights.scm | 18 +++++++++--------- crates/zed/src/languages/elixir/injections.scm | 4 ++-- crates/zed/src/languages/elixir/outline.scm | 4 ++-- crates/zed/src/languages/elm/injections.scm | 2 +- crates/zed/src/languages/erb/injections.scm | 8 ++++---- crates/zed/src/languages/glsl/highlights.scm | 4 ++-- crates/zed/src/languages/heex/injections.scm | 6 +++--- crates/zed/src/languages/html/injections.scm | 4 ++-- .../src/languages/javascript/highlights.scm | 6 +++--- crates/zed/src/languages/lua/highlights.scm | 6 +++--- crates/zed/src/languages/php/highlights.scm | 8 ++++---- crates/zed/src/languages/php/injections.scm | 4 ++-- crates/zed/src/languages/python/highlights.scm | 8 ++++---- crates/zed/src/languages/racket/highlights.scm | 7 +++---- crates/zed/src/languages/racket/outline.scm | 4 ++-- crates/zed/src/languages/ruby/brackets.scm | 2 +- crates/zed/src/languages/ruby/highlights.scm | 8 ++++---- crates/zed/src/languages/rust/highlights.scm | 4 ++-- crates/zed/src/languages/rust/injections.scm | 4 ++-- crates/zed/src/languages/scheme/highlights.scm | 4 ++-- crates/zed/src/languages/scheme/outline.scm | 4 ++-- crates/zed/src/languages/svelte/injections.scm | 14 +++++++------- .../src/languages/typescript/highlights.scm | 6 +++--- 30 files changed, 81 insertions(+), 83 deletions(-) diff --git a/crates/zed/src/languages/bash/highlights.scm b/crates/zed/src/languages/bash/highlights.scm index a72c5468edd911b60b31c8ae07041c3f733f3497..f3e0c9529a1d7c19777e40c28f934c0b57e10941 100644 --- a/crates/zed/src/languages/bash/highlights.scm +++ b/crates/zed/src/languages/bash/highlights.scm @@ -54,5 +54,5 @@ ( (command (_) @constant) - (#match? @constant "^-") + (.match? @constant "^-") ) diff --git a/crates/zed/src/languages/c/highlights.scm b/crates/zed/src/languages/c/highlights.scm index 064ec61a378beb00417e6b6716a6f1358daa5cbf..5245e53a052578a62f8d4cddab8141bb0d80d288 100644 --- a/crates/zed/src/languages/c/highlights.scm +++ b/crates/zed/src/languages/c/highlights.scm @@ -86,7 +86,7 @@ (identifier) @variable ((identifier) @constant - (#match? @constant "^_*[A-Z][A-Z\\d_]*$")) + (.match? @constant "^_*[A-Z][A-Z\\d_]*$")) (call_expression function: (identifier) @function) @@ -106,4 +106,3 @@ (primitive_type) (sized_type_specifier) ] @type - diff --git a/crates/zed/src/languages/c/injections.scm b/crates/zed/src/languages/c/injections.scm index 845a63bd1bd4e700df0fd1eb3c5d10d31e2ab0e4..fbc7d83f8211836067a08cf05fae1b7b66170d12 100644 --- a/crates/zed/src/languages/c/injections.scm +++ b/crates/zed/src/languages/c/injections.scm @@ -1,7 +1,7 @@ (preproc_def value: (preproc_arg) @content - (#set! "language" "c")) + (.set! "language" "c")) (preproc_function_def value: (preproc_arg) @content - (#set! "language" "c")) \ No newline at end of file + (.set! "language" "c")) diff --git a/crates/zed/src/languages/cpp/highlights.scm b/crates/zed/src/languages/cpp/highlights.scm index bcfa01ca5c6aca231d444026af94c7f6c6b32f51..a040b1d053cd714a5576c8a6d9f13304c6c1392c 100644 --- a/crates/zed/src/languages/cpp/highlights.scm +++ b/crates/zed/src/languages/cpp/highlights.scm @@ -31,13 +31,13 @@ declarator: (field_identifier) @function) ((namespace_identifier) @type - (#match? @type "^[A-Z]")) + (.match? @type "^[A-Z]")) (auto) @type (type_identifier) @type ((identifier) @constant - (#match? @constant "^_*[A-Z][A-Z\\d_]*$")) + (.match? @constant "^_*[A-Z][A-Z\\d_]*$")) (field_identifier) @property (statement_identifier) @label diff --git a/crates/zed/src/languages/cpp/injections.scm b/crates/zed/src/languages/cpp/injections.scm index eca372d577be30c352a2b7f7d93505a3b869e293..3c94ba4061f6942fd88c7b09279b4f40a1709d14 100644 --- a/crates/zed/src/languages/cpp/injections.scm +++ b/crates/zed/src/languages/cpp/injections.scm @@ -1,7 +1,7 @@ (preproc_def value: (preproc_arg) @content - (#set! "language" "c++")) + (.set! "language" "c++")) (preproc_function_def value: (preproc_arg) @content - (#set! "language" "c++")) \ No newline at end of file + (.set! "language" "c++")) diff --git a/crates/zed/src/languages/css/highlights.scm b/crates/zed/src/languages/css/highlights.scm index e271d8583c661b62f1a0bf5f4c848ca34cdbdc9d..83f99861c59e19b9e60335f2f4cc10231d00e31b 100644 --- a/crates/zed/src/languages/css/highlights.scm +++ b/crates/zed/src/languages/css/highlights.scm @@ -46,7 +46,7 @@ (property_name) (plain_value) ] @variable.special - (#match? @variable.special "^--") + (.match? @variable.special "^--") ) [ diff --git a/crates/zed/src/languages/elixir/embedding.scm b/crates/zed/src/languages/elixir/embedding.scm index 16ad20746d4b0c8697ff126fcc5150636cb8b794..3c523c248767dff3b855f9c623e66e5b3e03a4ae 100644 --- a/crates/zed/src/languages/elixir/embedding.scm +++ b/crates/zed/src/languages/elixir/embedding.scm @@ -3,7 +3,7 @@ operator: "@" operand: (call target: (identifier) @unary - (#match? @unary "^(doc)$")) + (.match? @unary "^(doc)$")) ) @context . (call @@ -18,10 +18,10 @@ target: (identifier) @name) operator: "when") ]) - (#match? @name "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item + (.match? @name "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item ) (call target: (identifier) @name (arguments (alias) @name) - (#match? @name "^(defmodule|defprotocol)$")) @item + (.match? @name "^(defmodule|defprotocol)$")) @item diff --git a/crates/zed/src/languages/elixir/highlights.scm b/crates/zed/src/languages/elixir/highlights.scm index 0e779d195c5e6e03404c783d9675fc223232c84d..a8fd7eb45a6c04de64f1c7aa00fbeeecb535a316 100644 --- a/crates/zed/src/languages/elixir/highlights.scm +++ b/crates/zed/src/languages/elixir/highlights.scm @@ -54,13 +54,13 @@ (sigil_name) @__name__ quoted_start: _ @string quoted_end: _ @string - (#match? @__name__ "^[sS]$")) @string + (.match? @__name__ "^[sS]$")) @string (sigil (sigil_name) @__name__ quoted_start: _ @string.regex quoted_end: _ @string.regex - (#match? @__name__ "^[rR]$")) @string.regex + (.match? @__name__ "^[rR]$")) @string.regex (sigil (sigil_name) @__name__ @@ -69,7 +69,7 @@ ( (identifier) @comment.unused - (#match? @comment.unused "^_") + (.match? @comment.unused "^_") ) (call @@ -91,7 +91,7 @@ operator: "|>" right: (identifier)) ]) - (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$")) + (.match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$")) (binary_operator operator: "|>" @@ -99,15 +99,15 @@ (call target: (identifier) @keyword - (#match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$")) + (.match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$")) (call target: (identifier) @keyword - (#match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$")) + (.match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$")) ( (identifier) @constant.builtin - (#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$") + (.match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$") ) (unary_operator @@ -121,7 +121,7 @@ (sigil) (boolean) ] @comment.doc)) - (#match? @__attribute__ "^(moduledoc|typedoc|doc)$")) + (.match? @__attribute__ "^(moduledoc|typedoc|doc)$")) (comment) @comment @@ -150,4 +150,4 @@ ((sigil (sigil_name) @_sigil_name (quoted_content) @embedded) - (#eq? @_sigil_name "H")) + (.eq? @_sigil_name "H")) diff --git a/crates/zed/src/languages/elixir/injections.scm b/crates/zed/src/languages/elixir/injections.scm index 4de229f1046ca39264ffb23dc98e565bfd74185b..5d445a7b820ed480a9545c638ba6e685be7c244a 100644 --- a/crates/zed/src/languages/elixir/injections.scm +++ b/crates/zed/src/languages/elixir/injections.scm @@ -3,5 +3,5 @@ ((sigil (sigil_name) @_sigil_name (quoted_content) @content) - (#eq? @_sigil_name "H") - (#set! language "heex")) + (.eq? @_sigil_name "H") + (.set! language "heex")) diff --git a/crates/zed/src/languages/elixir/outline.scm b/crates/zed/src/languages/elixir/outline.scm index a3311fb6d4640aa4ff5469c638022c1fde02e912..756d39651039c002ef79ec818ba63aee20523c20 100644 --- a/crates/zed/src/languages/elixir/outline.scm +++ b/crates/zed/src/languages/elixir/outline.scm @@ -1,7 +1,7 @@ (call target: (identifier) @context (arguments (alias) @name) - (#match? @context "^(defmodule|defprotocol)$")) @item + (.match? @context "^(defmodule|defprotocol)$")) @item (call target: (identifier) @context @@ -23,4 +23,4 @@ ")" @context.extra)) operator: "when") ]) - (#match? @context "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item + (.match? @context "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item diff --git a/crates/zed/src/languages/elm/injections.scm b/crates/zed/src/languages/elm/injections.scm index 0567320675a89c6649a191fdef950c6670d65707..3456f59a04af62c95fc26c7cec085123eb8b567d 100644 --- a/crates/zed/src/languages/elm/injections.scm +++ b/crates/zed/src/languages/elm/injections.scm @@ -1,2 +1,2 @@ ((glsl_content) @content - (#set! "language" "glsl")) + (.set! "language" "glsl")) diff --git a/crates/zed/src/languages/erb/injections.scm b/crates/zed/src/languages/erb/injections.scm index 7a69a818ef31d7fa3822466209b08c15280c6f5b..d9801015b7ca1f41f94b8be516f79b4c3c9365f6 100644 --- a/crates/zed/src/languages/erb/injections.scm +++ b/crates/zed/src/languages/erb/injections.scm @@ -1,7 +1,7 @@ ((code) @content - (#set! "language" "ruby") - (#set! "combined")) + (.set! "language" "ruby") + (.set! "combined")) ((content) @content - (#set! "language" "html") - (#set! "combined")) + (.set! "language" "html") + (.set! "combined")) diff --git a/crates/zed/src/languages/glsl/highlights.scm b/crates/zed/src/languages/glsl/highlights.scm index e4503c6fbba298afb1f2eddb82ce960af74b03c0..2378b8449b594d883ba19a0e5515369f5725522f 100644 --- a/crates/zed/src/languages/glsl/highlights.scm +++ b/crates/zed/src/languages/glsl/highlights.scm @@ -74,7 +74,7 @@ (sized_type_specifier) @type ((identifier) @constant - (#match? @constant "^[A-Z][A-Z\\d_]*$")) + (.match? @constant "^[A-Z][A-Z\\d_]*$")) (identifier) @variable @@ -114,5 +114,5 @@ ( (identifier) @variable.builtin - (#match? @variable.builtin "^gl_") + (.match? @variable.builtin "^gl_") ) diff --git a/crates/zed/src/languages/heex/injections.scm b/crates/zed/src/languages/heex/injections.scm index b503bcb28dc10911b9e57e74f7217a21ece549fb..1b63005cbfa02189e19a6a202c5beea0112c0946 100644 --- a/crates/zed/src/languages/heex/injections.scm +++ b/crates/zed/src/languages/heex/injections.scm @@ -5,9 +5,9 @@ (expression_value) (ending_expression_value) ] @content) - (#set! language "elixir") - (#set! combined) + (.set! language "elixir") + (.set! combined) ) ((expression (expression_value) @content) - (#set! language "elixir")) + (.set! language "elixir")) diff --git a/crates/zed/src/languages/html/injections.scm b/crates/zed/src/languages/html/injections.scm index 9084e373f217b95cf70bad9cc907d5d9cd127391..7d2ed0a225e7555c6f12a9b902863a2e9e2e0939 100644 --- a/crates/zed/src/languages/html/injections.scm +++ b/crates/zed/src/languages/html/injections.scm @@ -1,7 +1,7 @@ (script_element (raw_text) @content - (#set! "language" "javascript")) + (.set! "language" "javascript")) (style_element (raw_text) @content - (#set! "language" "css")) + (.set! "language" "css")) diff --git a/crates/zed/src/languages/javascript/highlights.scm b/crates/zed/src/languages/javascript/highlights.scm index 36ab21ca1ec854566ad716a13f5ab5725fa1acc9..7761bbb3a2dbdf0a66536f233be1df85c0724a11 100644 --- a/crates/zed/src/languages/javascript/highlights.scm +++ b/crates/zed/src/languages/javascript/highlights.scm @@ -44,7 +44,7 @@ ; Special identifiers ((identifier) @type - (#match? @type "^[A-Z]")) + (.match? @type "^[A-Z]")) (type_identifier) @type (predefined_type) @type.builtin @@ -53,7 +53,7 @@ (shorthand_property_identifier) (shorthand_property_identifier_pattern) ] @constant - (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) +(.match? @constant "^_*[A-Z_][A-Z\\d_]*$")) ; Literals @@ -214,4 +214,4 @@ "type" "readonly" "override" -] @keyword \ No newline at end of file +] @keyword diff --git a/crates/zed/src/languages/lua/highlights.scm b/crates/zed/src/languages/lua/highlights.scm index 60ca9de36b15098e9c76eaddff20238d5056adea..e00d0b9557c86bb6a6d395a727dae2a1f2593210 100644 --- a/crates/zed/src/languages/lua/highlights.scm +++ b/crates/zed/src/languages/lua/highlights.scm @@ -127,7 +127,7 @@ (identifier) @variable ((identifier) @variable.special - (#eq? @variable.special "self")) + (.eq? @variable.special "self")) (variable_list attribute: (attribute @@ -137,7 +137,7 @@ ;; Constants ((identifier) @constant - (#match? @constant "^[A-Z][A-Z_0-9]*$")) + (.match? @constant "^[A-Z][A-Z_0-9]*$")) (vararg_expression) @constant @@ -180,7 +180,7 @@ (function_call (identifier) @function.builtin - (#any-of? @function.builtin + (.any-of? @function.builtin ;; built-in functions in Lua 5.1 "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print" diff --git a/crates/zed/src/languages/php/highlights.scm b/crates/zed/src/languages/php/highlights.scm index cfb03cbccad037d207ff1a1388c12eec22644f48..fb85d997fad6585066ac621253fe9694467e8517 100644 --- a/crates/zed/src/languages/php/highlights.scm +++ b/crates/zed/src/languages/php/highlights.scm @@ -43,15 +43,15 @@ (relative_scope) @variable.builtin ((name) @constant - (#match? @constant "^_?[A-Z][A-Z\\d_]+$")) + (.match? @constant "^_?[A-Z][A-Z\\d_]+$")) ((name) @constant.builtin - (#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) + (.match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) ((name) @method.constructor -(#match? @method.constructor "^[A-Z]")) +(.match? @method.constructor "^[A-Z]")) ((name) @variable.builtin - (#eq? @variable.builtin "this")) + (.eq? @variable.builtin "this")) (variable_name) @variable diff --git a/crates/zed/src/languages/php/injections.scm b/crates/zed/src/languages/php/injections.scm index 57abd8ea2b0576e7b936788b4a9880bc57fea798..725729337b240a9e58b1e392ab645809d235314e 100644 --- a/crates/zed/src/languages/php/injections.scm +++ b/crates/zed/src/languages/php/injections.scm @@ -1,3 +1,3 @@ ((text) @content - (#set! "language" "html") - (#set! "combined")) + (.set! "language" "html") + (.set! "combined")) diff --git a/crates/zed/src/languages/python/highlights.scm b/crates/zed/src/languages/python/highlights.scm index 71ab963d82664db4dd9a66b9e9ac0e85449caf57..b31bddaeb501158c8bf6370ca0de37a1d73b7a6a 100644 --- a/crates/zed/src/languages/python/highlights.scm +++ b/crates/zed/src/languages/python/highlights.scm @@ -18,16 +18,16 @@ ; Identifier naming conventions ((identifier) @type - (#match? @type "^[A-Z]")) + (.match? @type "^[A-Z]")) ((identifier) @constant - (#match? @constant "^_*[A-Z][A-Z\\d_]*$")) + (.match? @constant "^_*[A-Z][A-Z\\d_]*$")) ; Builtin functions ((call function: (identifier) @function.builtin) - (#match? + (.match? @function.builtin "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$")) @@ -122,4 +122,4 @@ "yield" "match" "case" -] @keyword \ No newline at end of file +] @keyword diff --git a/crates/zed/src/languages/racket/highlights.scm b/crates/zed/src/languages/racket/highlights.scm index 2c0caf89357cfbe8f966bffbbc712272b3c1e59d..304b10a018b23eebcea9248d33e0f43edd50ea29 100644 --- a/crates/zed/src/languages/racket/highlights.scm +++ b/crates/zed/src/languages/racket/highlights.scm @@ -22,7 +22,7 @@ (lang_name) @variable.special ((symbol) @operator - (#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) + (.match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) (list . @@ -31,10 +31,9 @@ (list . (symbol) @keyword - (#match? @keyword + (.match? @keyword "^(unit-from-context|for/last|syntax-case|match-let\\*-values|define-for-syntax|define/subexpression-pos-prop|set-field!|class-field-accessor|invoke-unit|#%stratified-body|for\\*/and|for\\*/weak-set|flat-rec-contract|for\\*/stream|planet|for/mutable-seteqv|log-error|delay|#%declare|prop:dict/contract|->d|lib|override\\*|define-local-member-name|send-generic|for\\*/hasheq|define-syntax|submod|except|include-at/relative-to/reader|public\\*|define-member-name|define/public|let\\*|for/and|for\\*/first|for|delay/strict|define-values-for-export|==|match-define-values|for/weak-seteq|for\\*/async|for/stream|for/weak-seteqv|set!-values|lambda|for\\*/product|augment-final\\*|pubment\\*|command-line|contract|case|struct-field-index|contract-struct|unless|for/hasheq|for/seteqv|with-method|define-values-for-syntax|for-template|pubment|for\\*/list|syntax-case\\*|init-field|define-serializable-class|=>|for/foldr/derived|letrec-syntaxes|overment\\*|unquote-splicing|_|inherit-field|for\\*|stream-lazy|match-lambda\\*|contract-pos/neg-doubling|unit/c|match-define|for\\*/set|unit/s|nor|#%expression|class/c|this%|place/context|super-make-object|when|set!|parametric->/c|syntax-id-rules|include/reader|compound-unit|override-final|get-field|gen:dict|for\\*/seteqv|for\\*/hash|#%provide|combine-out|link|with-contract-continuation-mark|define-struct/derived|stream\\*|λ|rename-out|define-serializable-class\\*|augment|define/augment|let|define-signature-form|letrec-syntax|abstract|define-namespace-anchor|#%module-begin|#%top-interaction|for\\*/weak-seteqv|do|define/subexpression-pos-prop/name|absent|send/apply|with-handlers\\*|all-from-out|provide-signature-elements|gen:stream|define/override-final|for\\*/mutable-seteqv|rename|quasisyntax/loc|instantiate|for/list|extends|include-at/relative-to|mixin|define/pubment|#%plain-lambda|except-out|#%plain-module-begin|init|for\\*/last|relative-in|define-unit/new-import-export|->dm|member-name-key|nand|interface\\*|struct|define/override|else|define/augment-final|failure-cont|open|log-info|define/final-prop|all-defined-out|for/sum|for\\*/sum|recursive-contract|define|define-logger|match\\*|log-debug|rename-inner|->|struct/derived|unit|class\\*|prefix-out|any|define/overment|define-signature|match-letrec-values|let-syntaxes|for/mutable-set|define/match|cond|super-instantiate|define-contract-struct|import|hash/dc|define-custom-set-types|public-final|for/vector|for-label|prefix-in|for\\*/foldr/derived|define-unit-binding|object-contract|syntax-rules|augride|for\\*/mutable-seteq|quasisyntax|inner|for-syntax|overment|send/keyword-apply|generic|let\\*-values|->m|define-values|struct-copy|init-depend|struct/ctc|match-lambda|#%printing-module-begin|match\\*/derived|case->m|this|file|stream-cons|inspect|field|for/weak-set|struct\\*|gen:custom-write|thunk\\*|combine-in|unquote|for/lists|define/private|for\\*/foldr|define-unit/s|with-continuation-mark|begin|prefix|quote-syntax/prune|object/c|interface|match/derived|for/hasheqv|current-contract-region|define-compound-unit|override|define/public-final|recontract-out|let/cc|augride\\*|inherit|send|define-values/invoke-unit|for/mutable-seteq|#%datum|for/first|match-let\\*|invoke-unit/infer|define/contract|syntax/loc|for\\*/hasheqv|define-sequence-syntax|let/ec|for/product|for\\*/fold/derived|define-syntax-rule|lazy|unconstrained-domain->|augment-final|private|class|define-splicing-for-clause-syntax|for\\*/fold|prompt-tag/c|contract-out|match/values|public-final\\*|case-lambda|for/fold|unsyntax|for/set|begin0|#%require|time|public|define-struct|include|define-values/invoke-unit/infer|only-space-in|struct/c|only-meta-in|unit/new-import-export|place|begin-for-syntax|shared|inherit/super|quote|for/or|struct/contract|export|inherit/inner|struct-out|let-syntax|augment\\*|for\\*/vector|rename-in|match-let|define-unit|:do-in|~@|for\\*/weak-seteq|private\\*|and|except-in|log-fatal|gen:equal\\+hash|provide|require|thunk|invariant-assertion|define-match-expander|init-rest|->\\*|class/derived|super-new|for/fold/derived|for\\*/mutable-set|match-lambda\\*\\*|only|with-contract|~\\?|opt/c|let-values|delay/thread|->i|for/foldr|for-meta|only-in|send\\+|\\.\\.\\.|struct-guard/c|->\\*m|gen:set|struct/dc|define-syntaxes|if|parameterize|module\\*|module|send\\*|#%variable-reference|compound-unit/infer|#%plain-app|for/hash|contracted|case->|match|for\\*/lists|#%app|letrec-values|log-warning|super|define/augride|local-require|provide/contract|define-struct/contract|match-let-values|quote-syntax|for\\*/seteq|define-compound-unit/infer|parameterize\\*|values/drop|for/seteq|tag|stream|delay/idle|module\\+|define-custom-hash-types|cons/dc|define-module-boundary-contract|or|protect-out|define-opt/c|implies|letrec-syntaxes\\+values|for\\*/or|unsyntax-splicing|override-final\\*|for/async|parameterize-break|syntax|place\\*|for-space|quasiquote|with-handlers|delay/sync|define-unit-from-context|match-letrec|#%top|define-unit/contract|delay/name|new|field-bound\\?|letrec|class-field-mutator|with-syntax|flat-murec-contract|rename-super|local)$" )) ((symbol) @comment - (#match? @comment "^#[cC][iIsS]$")) - + (.match? @comment "^#[cC][iIsS]$")) diff --git a/crates/zed/src/languages/racket/outline.scm b/crates/zed/src/languages/racket/outline.scm index 604e052a63f71badbe98ec1debc96a519dc49256..188067078de2676ebaeaba90fe98d508dc7d19e0 100644 --- a/crates/zed/src/languages/racket/outline.scm +++ b/crates/zed/src/languages/racket/outline.scm @@ -6,5 +6,5 @@ (symbol) @name (list . (symbol) @name) ] - (#match? @start-symbol "^define") -) @item \ No newline at end of file + (.match? @start-symbol "^define") +) @item diff --git a/crates/zed/src/languages/ruby/brackets.scm b/crates/zed/src/languages/ruby/brackets.scm index 957b20ecdb4524920ba30b9d202d94d101215ed5..f5129f8f310ce4b533c29c5e3fdb465844e5e68e 100644 --- a/crates/zed/src/languages/ruby/brackets.scm +++ b/crates/zed/src/languages/ruby/brackets.scm @@ -11,4 +11,4 @@ (begin "begin" @open "end" @close) (module "module" @open "end" @close) (_ . "def" @open "end" @close) -(_ . "class" @open "end" @close) \ No newline at end of file +(_ . "class" @open "end" @close) diff --git a/crates/zed/src/languages/ruby/highlights.scm b/crates/zed/src/languages/ruby/highlights.scm index 2610cfa1ccf07254c68c87d2e8013741d7d6969f..93cf2608f4ee7829c55718c42075b6cb986805a1 100644 --- a/crates/zed/src/languages/ruby/highlights.scm +++ b/crates/zed/src/languages/ruby/highlights.scm @@ -33,12 +33,12 @@ (identifier) @variable ((identifier) @keyword - (#match? @keyword "^(private|protected|public)$")) + (.match? @keyword "^(private|protected|public)$")) ; Function calls ((identifier) @function.method.builtin - (#eq? @function.method.builtin "require")) + (.eq? @function.method.builtin "require")) "defined?" @function.method.builtin @@ -60,7 +60,7 @@ ] @property ((identifier) @constant.builtin - (#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$")) + (.match? @constant.builtin "^__(FILE|LINE|ENCODING)__$")) (file) @constant.builtin (line) @constant.builtin @@ -71,7 +71,7 @@ ) @constant.builtin ((constant) @constant - (#match? @constant "^[A-Z\\d_]+$")) + (.match? @constant "^[A-Z\\d_]+$")) (constant) @type diff --git a/crates/zed/src/languages/rust/highlights.scm b/crates/zed/src/languages/rust/highlights.scm index 7240173a89260b22a9508a9984e40dc8b1ab7410..54dbfa00bd3195efadc965d3dca490d8c00b74bd 100644 --- a/crates/zed/src/languages/rust/highlights.scm +++ b/crates/zed/src/languages/rust/highlights.scm @@ -38,11 +38,11 @@ ; Assume uppercase names are types/enum-constructors ((identifier) @type - (#match? @type "^[A-Z]")) + (.match? @type "^[A-Z]")) ; Assume all-caps names are constants ((identifier) @constant - (#match? @constant "^_*[A-Z][A-Z\\d_]*$")) + (.match? @constant "^_*[A-Z][A-Z\\d_]*$")) [ "(" diff --git a/crates/zed/src/languages/rust/injections.scm b/crates/zed/src/languages/rust/injections.scm index 57ebea8539345c72145eaa44cffb09845f913406..78fde3752fd9722e33daf4ad747b4e557044d353 100644 --- a/crates/zed/src/languages/rust/injections.scm +++ b/crates/zed/src/languages/rust/injections.scm @@ -1,7 +1,7 @@ (macro_invocation (token_tree) @content - (#set! "language" "rust")) + (.set! "language" "rust")) (macro_rule (token_tree) @content - (#set! "language" "rust")) \ No newline at end of file + (.set! "language" "rust")) diff --git a/crates/zed/src/languages/scheme/highlights.scm b/crates/zed/src/languages/scheme/highlights.scm index 40ba61cd055948195023e2aa25db6f032acd674e..201b0e9276870afeb4f3ed7eb68de302af929b33 100644 --- a/crates/zed/src/languages/scheme/highlights.scm +++ b/crates/zed/src/languages/scheme/highlights.scm @@ -14,7 +14,7 @@ (directive)] @comment ((symbol) @operator - (#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) + (.match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) (list . @@ -23,6 +23,6 @@ (list . (symbol) @keyword - (#match? @keyword + (.match? @keyword "^(define-syntax|let\\*|lambda|λ|case|=>|quote-splicing|unquote-splicing|set!|let|letrec|letrec-syntax|let-values|let\\*-values|do|else|define|cond|syntax-rules|unquote|begin|quote|let-syntax|and|if|quasiquote|letrec|delay|or|when|unless|identifier-syntax|assert|library|export|import|rename|only|except|prefix)$" )) diff --git a/crates/zed/src/languages/scheme/outline.scm b/crates/zed/src/languages/scheme/outline.scm index 604e052a63f71badbe98ec1debc96a519dc49256..188067078de2676ebaeaba90fe98d508dc7d19e0 100644 --- a/crates/zed/src/languages/scheme/outline.scm +++ b/crates/zed/src/languages/scheme/outline.scm @@ -6,5 +6,5 @@ (symbol) @name (list . (symbol) @name) ] - (#match? @start-symbol "^define") -) @item \ No newline at end of file + (.match? @start-symbol "^define") +) @item diff --git a/crates/zed/src/languages/svelte/injections.scm b/crates/zed/src/languages/svelte/injections.scm index 8c1ac9fcd0bb16cf59e792487985ac64d6a43f88..17719b325c0c3632e1f6d9bbf7cd131ed9362dcb 100755 --- a/crates/zed/src/languages/svelte/injections.scm +++ b/crates/zed/src/languages/svelte/injections.scm @@ -2,27 +2,27 @@ ; -------------- (script_element (raw_text) @content - (#set! "language" "javascript")) + (.set! "language" "javascript")) ((script_element (start_tag (attribute (quoted_attribute_value (attribute_value) @_language))) (raw_text) @content) - (#eq? @_language "ts") - (#set! "language" "typescript")) + (.eq? @_language "ts") + (.set! "language" "typescript")) ((script_element (start_tag (attribute (quoted_attribute_value (attribute_value) @_language))) (raw_text) @content) - (#eq? @_language "typescript") - (#set! "language" "typescript")) + (.eq? @_language "typescript") + (.set! "language" "typescript")) (style_element (raw_text) @content - (#set! "language" "css")) + (.set! "language" "css")) ((raw_text_expr) @content - (#set! "language" "javascript")) + (.set! "language" "javascript")) diff --git a/crates/zed/src/languages/typescript/highlights.scm b/crates/zed/src/languages/typescript/highlights.scm index ba6b329e0e0def9c5d0c31d0df94525825ed2c45..9272108670ac2729dd39f4b54f90b81eeb3218a4 100644 --- a/crates/zed/src/languages/typescript/highlights.scm +++ b/crates/zed/src/languages/typescript/highlights.scm @@ -44,10 +44,10 @@ ; Special identifiers ((identifier) @method.constructor - (#match? @method.constructor "^[A-Z]")) + (.match? @method.constructor "^[A-Z]")) ((identifier) @type - (#match? @type "^[A-Z]")) + (.match? @type "^[A-Z]")) (type_identifier) @type (predefined_type) @type.builtin @@ -56,7 +56,7 @@ (shorthand_property_identifier) (shorthand_property_identifier_pattern) ] @constant - (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) +(.match? @constant "^_*[A-Z_][A-Z\\d_]*$")) ; Literals From 0b7e75c25a6d98649e92aa5d6e4f709f7bd754d2 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 27 Jul 2023 12:55:32 -0400 Subject: [PATCH 09/52] Add the `generate-syntax` action --- styles/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/styles/package.json b/styles/package.json index 16e95d90d5bebb18e7cfffe88e8d0098b48eb00f..3a50ac537166bcde6c30b0bc822481a823cfc8a2 100644 --- a/styles/package.json +++ b/styles/package.json @@ -8,6 +8,7 @@ "build-licenses": "ts-node ./src/build_licenses.ts", "build-tokens": "ts-node ./src/build_tokens.ts", "build-types": "ts-node ./src/build_types.ts", + "generate-syntax": "ts-node ./src/types/extract_syntax_types.ts", "test": "vitest" }, "author": "Zed Industries (https://github.com/zed-industries/)", From b9d5cc5828617fb0e973c121f09645cb7e98fb62 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 27 Jul 2023 12:56:54 -0400 Subject: [PATCH 10/52] Format --- styles/src/build_themes.ts | 9 +- styles/src/build_tokens.ts | 4 +- styles/src/component/icon_button.ts | 5 +- styles/src/component/tab_bar_button.ts | 67 +++--- styles/src/component/text_button.ts | 5 +- styles/src/style_tree/app.ts | 2 +- styles/src/style_tree/assistant.ts | 69 ++++--- styles/src/style_tree/editor.ts | 2 +- styles/src/style_tree/feedback.ts | 2 +- styles/src/style_tree/picker.ts | 2 +- styles/src/style_tree/project_panel.ts | 16 +- styles/src/style_tree/status_bar.ts | 10 +- styles/src/style_tree/titlebar.ts | 4 +- styles/src/theme/create_theme.ts | 25 ++- styles/src/theme/syntax.ts | 42 ++-- styles/src/theme/theme_config.ts | 4 +- styles/src/theme/tokens/theme.ts | 4 +- styles/src/themes/atelier/common.ts | 6 +- styles/src/types/extract_syntax_types.ts | 41 ++-- styles/src/types/syntax.ts | 253 +++++++++++------------ styles/tsconfig.json | 4 +- 21 files changed, 299 insertions(+), 277 deletions(-) diff --git a/styles/src/build_themes.ts b/styles/src/build_themes.ts index 17575663a1f88b17870b1b146b47e7086bf3e2ba..4d262f8146ed907035e384dbefd28c0b838a467a 100644 --- a/styles/src/build_themes.ts +++ b/styles/src/build_themes.ts @@ -21,9 +21,7 @@ function clear_themes(theme_directory: string) { } } -const all_themes: Theme[] = themes.map((theme) => - create_theme(theme) -) +const all_themes: Theme[] = themes.map((theme) => create_theme(theme)) function write_themes(themes: Theme[], output_directory: string) { clear_themes(output_directory) @@ -34,10 +32,7 @@ function write_themes(themes: Theme[], output_directory: string) { const style_tree = app() const style_tree_json = JSON.stringify(style_tree, null, 2) const temp_path = path.join(temp_directory, `${theme.name}.json`) - const out_path = path.join( - output_directory, - `${theme.name}.json` - ) + const out_path = path.join(output_directory, `${theme.name}.json`) fs.writeFileSync(temp_path, style_tree_json) fs.renameSync(temp_path, out_path) console.log(`- ${out_path} created`) diff --git a/styles/src/build_tokens.ts b/styles/src/build_tokens.ts index fd6aa18ced50af53b6bcf4c3c386d1774c7ab00d..3c52b6d989640a93025ac5eafe5a959b8bc83163 100644 --- a/styles/src/build_tokens.ts +++ b/styles/src/build_tokens.ts @@ -83,8 +83,6 @@ function write_tokens(themes: Theme[], tokens_directory: string) { console.log(`- ${METADATA_FILE} created`) } -const all_themes: Theme[] = themes.map((theme) => - create_theme(theme) -) +const all_themes: Theme[] = themes.map((theme) => create_theme(theme)) write_tokens(all_themes, TOKENS_DIRECTORY) diff --git a/styles/src/component/icon_button.ts b/styles/src/component/icon_button.ts index 6887fc7c30e1f234fd043bb115c2658039b5f806..13dfce6d7762aaf2abc59f298fb6e22583435cf1 100644 --- a/styles/src/component/icon_button.ts +++ b/styles/src/component/icon_button.ts @@ -10,10 +10,7 @@ export type Margin = { } interface IconButtonOptions { - layer?: - | Theme["lowest"] - | Theme["middle"] - | Theme["highest"] + layer?: Theme["lowest"] | Theme["middle"] | Theme["highest"] color?: keyof Theme["lowest"] margin?: Partial } diff --git a/styles/src/component/tab_bar_button.ts b/styles/src/component/tab_bar_button.ts index 0c43e7010e5469c10f959e00f4df8d177963392f..9e7f9acfc314be75850128690d8d066dde520182 100644 --- a/styles/src/component/tab_bar_button.ts +++ b/styles/src/component/tab_bar_button.ts @@ -12,44 +12,47 @@ type TabBarButtonProps = TabBarButtonOptions & { state?: Partial>> } -export function tab_bar_button(theme: Theme, { icon, color = "base" }: TabBarButtonProps) { +export function tab_bar_button( + theme: Theme, + { icon, color = "base" }: TabBarButtonProps +) { const button_spacing = 8 - return ( - interactive({ - base: { - icon: { - color: foreground(theme.middle, color), - asset: icon, - dimensions: { - width: 15, - height: 15, - }, + return interactive({ + base: { + icon: { + color: foreground(theme.middle, color), + asset: icon, + dimensions: { + width: 15, + height: 15, }, - container: { - corner_radius: 4, - padding: { - top: 4, bottom: 4, left: 4, right: 4 - }, - margin: { - left: button_spacing / 2, - right: button_spacing / 2, - }, + }, + container: { + corner_radius: 4, + padding: { + top: 4, + bottom: 4, + left: 4, + right: 4, + }, + margin: { + left: button_spacing / 2, + right: button_spacing / 2, }, }, - state: { - hovered: { - container: { - background: background(theme.middle, color, "hovered"), - - } + }, + state: { + hovered: { + container: { + background: background(theme.middle, color, "hovered"), }, - clicked: { - container: { - background: background(theme.middle, color, "pressed"), - } + }, + clicked: { + container: { + background: background(theme.middle, color, "pressed"), }, }, - }) - ) + }, + }) } diff --git a/styles/src/component/text_button.ts b/styles/src/component/text_button.ts index 58b2a1cbf2ff31a8e4fc50b9e1165bca78ec6b4a..68ec01c92bf1ba12907675dbd4ee87a4f51e4b9c 100644 --- a/styles/src/component/text_button.ts +++ b/styles/src/component/text_button.ts @@ -9,10 +9,7 @@ import { useTheme, Theme } from "../theme" import { Margin } from "./icon_button" interface TextButtonOptions { - layer?: - | Theme["lowest"] - | Theme["middle"] - | Theme["highest"] + layer?: Theme["lowest"] | Theme["middle"] | Theme["highest"] color?: keyof Theme["lowest"] margin?: Partial text_properties?: TextProperties diff --git a/styles/src/style_tree/app.ts b/styles/src/style_tree/app.ts index ccfdd60a981f4d5e763ce35902b0456bf0d703cd..ee0aa133a04bd35202d381835e257ddca2b284cc 100644 --- a/styles/src/style_tree/app.ts +++ b/styles/src/style_tree/app.ts @@ -57,6 +57,6 @@ export default function app(): any { tooltip: tooltip(), terminal: terminal(), assistant: assistant(), - feedback: feedback() + feedback: feedback(), } } diff --git a/styles/src/style_tree/assistant.ts b/styles/src/style_tree/assistant.ts index cfc1f8d813648654a8fee608ea4d00dc30893b75..7df5434f91010f778d47dfc9170ef80b909df0cf 100644 --- a/styles/src/style_tree/assistant.ts +++ b/styles/src/style_tree/assistant.ts @@ -8,50 +8,48 @@ type RoleCycleButton = TextStyle & { } // TODO: Replace these with zed types type RemainingTokens = TextStyle & { - background: string, - margin: { top: number, right: number }, + background: string + margin: { top: number; right: number } padding: { - right: number, - left: number, - top: number, - bottom: number, - }, - corner_radius: number, + right: number + left: number + top: number + bottom: number + } + corner_radius: number } export default function assistant(): any { const theme = useTheme() - const interactive_role = (color: StyleSets): Interactive => { - return ( - interactive({ - base: { + const interactive_role = ( + color: StyleSets + ): Interactive => { + return interactive({ + base: { + ...text(theme.highest, "sans", color, { size: "sm" }), + }, + state: { + hovered: { ...text(theme.highest, "sans", color, { size: "sm" }), + background: background(theme.highest, color, "hovered"), }, - state: { - hovered: { - ...text(theme.highest, "sans", color, { size: "sm" }), - background: background(theme.highest, color, "hovered"), - }, - clicked: { - ...text(theme.highest, "sans", color, { size: "sm" }), - background: background(theme.highest, color, "pressed"), - } + clicked: { + ...text(theme.highest, "sans", color, { size: "sm" }), + background: background(theme.highest, color, "pressed"), }, - }) - ) + }, + }) } const tokens_remaining = (color: StyleSets): RemainingTokens => { - return ( - { - ...text(theme.highest, "mono", color, { size: "xs" }), - background: background(theme.highest, "on", "default"), - margin: { top: 12, right: 20 }, - padding: { right: 4, left: 4, top: 1, bottom: 1 }, - corner_radius: 6, - } - ) + return { + ...text(theme.highest, "mono", color, { size: "xs" }), + background: background(theme.highest, "on", "default"), + margin: { top: 12, right: 20 }, + padding: { right: 4, left: 4, top: 1, bottom: 1 }, + corner_radius: 6, + } } return { @@ -93,7 +91,10 @@ export default function assistant(): any { base: { background: background(theme.middle), padding: { top: 4, bottom: 4 }, - border: border(theme.middle, "default", { top: true, overlay: true }), + border: border(theme.middle, "default", { + top: true, + overlay: true, + }), }, state: { hovered: { @@ -101,7 +102,7 @@ export default function assistant(): any { }, clicked: { background: background(theme.middle, "pressed"), - } + }, }, }), saved_at: { diff --git a/styles/src/style_tree/editor.ts b/styles/src/style_tree/editor.ts index ccbb33e21dd8459f665531b9b4b19af8831946bd..832e77626491ff94f183d5ce1fe195f5a55a3780 100644 --- a/styles/src/style_tree/editor.ts +++ b/styles/src/style_tree/editor.ts @@ -318,7 +318,7 @@ export default function editor(): any { ? with_opacity(theme.ramps.green(0.5).hex(), 0.8) : with_opacity(theme.ramps.green(0.4).hex(), 0.8), }, - selections: foreground(layer, "accent") + selections: foreground(layer, "accent"), }, composition_mark: { underline: { diff --git a/styles/src/style_tree/feedback.ts b/styles/src/style_tree/feedback.ts index b1bd96e165466521804f86d547664c209c7c4671..0349359533041d4425df3d0c72d120ed18499a30 100644 --- a/styles/src/style_tree/feedback.ts +++ b/styles/src/style_tree/feedback.ts @@ -37,7 +37,7 @@ export default function feedback(): any { ...text(theme.highest, "mono", "on", "disabled"), background: background(theme.highest, "on", "disabled"), border: border(theme.highest, "on", "disabled"), - } + }, }, }), button_margin: 8, diff --git a/styles/src/style_tree/picker.ts b/styles/src/style_tree/picker.ts index 28ae85478794a22211dc67cb6ec56cce4bc805f1..317f600b1e2fca3f6b8756c3ba033fa22e6b0220 100644 --- a/styles/src/style_tree/picker.ts +++ b/styles/src/style_tree/picker.ts @@ -152,7 +152,7 @@ export default function picker(): any { 0.5 ), }, - } + }, }), } } diff --git a/styles/src/style_tree/project_panel.ts b/styles/src/style_tree/project_panel.ts index e239f9a84023088d988f74e709c6485ade8a9510..51958af145b50afd25510788ff0a530cc77a5a1d 100644 --- a/styles/src/style_tree/project_panel.ts +++ b/styles/src/style_tree/project_panel.ts @@ -64,17 +64,17 @@ export default function project_panel(): any { const unselected_default_style = merge( base_properties, unselected?.default ?? {}, - {}, + {} ) const unselected_hovered_style = merge( base_properties, { background: background(theme.middle, "hovered") }, - unselected?.hovered ?? {}, + unselected?.hovered ?? {} ) const unselected_clicked_style = merge( base_properties, { background: background(theme.middle, "pressed") }, - unselected?.clicked ?? {}, + unselected?.clicked ?? {} ) const selected_default_style = merge( base_properties, @@ -82,7 +82,7 @@ export default function project_panel(): any { background: background(theme.lowest), text: text(theme.lowest, "sans", { size: "sm" }), }, - selected_style?.default ?? {}, + selected_style?.default ?? {} ) const selected_hovered_style = merge( base_properties, @@ -90,7 +90,7 @@ export default function project_panel(): any { background: background(theme.lowest, "hovered"), text: text(theme.lowest, "sans", { size: "sm" }), }, - selected_style?.hovered ?? {}, + selected_style?.hovered ?? {} ) const selected_clicked_style = merge( base_properties, @@ -98,7 +98,7 @@ export default function project_panel(): any { background: background(theme.lowest, "pressed"), text: text(theme.lowest, "sans", { size: "sm" }), }, - selected_style?.clicked ?? {}, + selected_style?.clicked ?? {} ) return toggleable({ @@ -175,7 +175,7 @@ export default function project_panel(): any { default: { icon_color: foreground(theme.middle, "variant"), }, - }, + } ), cut_entry: entry( { @@ -190,7 +190,7 @@ export default function project_panel(): any { size: "sm", }), }, - }, + } ), filename_editor: { background: background(theme.middle, "on"), diff --git a/styles/src/style_tree/status_bar.ts b/styles/src/style_tree/status_bar.ts index 06afc378235ec843d64a28313a38c05d395f1962..8f50896207ca6853c49ff008d6252d01f44f6911 100644 --- a/styles/src/style_tree/status_bar.ts +++ b/styles/src/style_tree/status_bar.ts @@ -34,10 +34,14 @@ export default function status_bar(): any { ...text(layer, "mono", "variant", { size: "xs" }), }, active_language: text_button({ - color: "variant" + color: "variant", + }), + auto_update_progress_message: text(layer, "sans", "variant", { + size: "xs", + }), + auto_update_done_message: text(layer, "sans", "variant", { + size: "xs", }), - auto_update_progress_message: text(layer, "sans", "variant", { size: "xs" }), - auto_update_done_message: text(layer, "sans", "variant", { size: "xs" }), lsp_status: interactive({ base: { ...diagnostic_status_container, diff --git a/styles/src/style_tree/titlebar.ts b/styles/src/style_tree/titlebar.ts index 177a8c5bd8db0fa2290eda5e25c4160531d81e4b..fe0c53e87dac61bdfc93688eea13e74d583017a9 100644 --- a/styles/src/style_tree/titlebar.ts +++ b/styles/src/style_tree/titlebar.ts @@ -183,10 +183,10 @@ export function titlebar(): any { project_name_divider: text(theme.lowest, "sans", "variant"), project_menu_button: toggleable_text_button(theme, { - color: 'base', + color: "base", }), git_menu_button: toggleable_text_button(theme, { - color: 'variant', + color: "variant", }), // Collaborators diff --git a/styles/src/theme/create_theme.ts b/styles/src/theme/create_theme.ts index e52c4dc95b361572d8cbdc388c04146cecc81e8c..6df36d7077b934f2acc45f21422159872c6f551a 100644 --- a/styles/src/theme/create_theme.ts +++ b/styles/src/theme/create_theme.ts @@ -2,7 +2,7 @@ import { Scale, Color } from "chroma-js" import { ThemeConfig, ThemeAppearance, - ThemeConfigInputColors + ThemeConfigInputColors, } from "./theme_config" import { get_ramps } from "./ramps" import { syntaxStyle } from "./syntax" @@ -13,16 +13,16 @@ export interface Theme { is_light: boolean /** - * App background, other elements that should sit directly on top of the background. - */ + * App background, other elements that should sit directly on top of the background. + */ lowest: Layer /** - * Panels, tabs, other UI surfaces that sit on top of the background. - */ + * Panels, tabs, other UI surfaces that sit on top of the background. + */ middle: Layer /** - * Editors like code buffers, conversation editors, etc. - */ + * Editors like code buffers, conversation editors, etc. + */ highest: Layer ramps: RampSet @@ -115,11 +115,7 @@ export interface Style { } export function create_theme(theme: ThemeConfig): Theme { - const { - name, - appearance, - input_color, - } = theme + const { name, appearance, input_color } = theme const is_light = appearance === ThemeAppearance.Light const color_ramps: ThemeConfigInputColors = input_color @@ -161,7 +157,10 @@ export function create_theme(theme: ThemeConfig): Theme { "7": player(ramps.yellow), } - const syntax = syntaxStyle(ramps, theme.override.syntax ? theme.override.syntax : {}) + const syntax = syntaxStyle( + ramps, + theme.override.syntax ? theme.override.syntax : {} + ) return { name, diff --git a/styles/src/theme/syntax.ts b/styles/src/theme/syntax.ts index d39496a412904647ea2deb8c74048c864ab31550..b1bf5ed9307b87036656d902b892c56b627022a0 100644 --- a/styles/src/theme/syntax.ts +++ b/styles/src/theme/syntax.ts @@ -3,8 +3,13 @@ import { font_weights, ThemeConfigInputSyntax, RampSet } from "../common" import { Syntax, SyntaxHighlightStyle, allSyntaxKeys } from "../types/syntax" // Apply defaults to any missing syntax properties that are not defined manually -function apply_defaults(ramps: RampSet, syntax_highlights: Partial): Syntax { - const restKeys: (keyof Syntax)[] = allSyntaxKeys.filter(key => !syntax_highlights[key]) +function apply_defaults( + ramps: RampSet, + syntax_highlights: Partial +): Syntax { + const restKeys: (keyof Syntax)[] = allSyntaxKeys.filter( + (key) => !syntax_highlights[key] + ) const completeSyntax: Syntax = {} as Syntax @@ -28,23 +33,36 @@ function apply_defaults(ramps: RampSet, syntax_highlights: Partial): Syn // Merge the base syntax with the theme syntax overrides // This is a deep merge, so any nested properties will be merged as well // This allows for a theme to only override a single property of a syntax highlight style -const merge_syntax = (baseSyntax: Syntax, theme_syntax_overrides: ThemeConfigInputSyntax): Syntax => { - return deepmerge(baseSyntax, theme_syntax_overrides, { - arrayMerge: (destinationArray, sourceArray) => [ - ...destinationArray, - ...sourceArray, - ], - }) +const merge_syntax = ( + baseSyntax: Syntax, + theme_syntax_overrides: ThemeConfigInputSyntax +): Syntax => { + return deepmerge( + baseSyntax, + theme_syntax_overrides, + { + arrayMerge: (destinationArray, sourceArray) => [ + ...destinationArray, + ...sourceArray, + ], + } + ) } /** Returns a complete Syntax object of the combined styles of a theme's syntax overrides and the default syntax styles */ -export const syntaxStyle = (ramps: RampSet, theme_syntax_overrides: ThemeConfigInputSyntax): Syntax => { +export const syntaxStyle = ( + ramps: RampSet, + theme_syntax_overrides: ThemeConfigInputSyntax +): Syntax => { const syntax_highlights: Partial = { - "comment": { color: ramps.neutral(0.71).hex() }, + comment: { color: ramps.neutral(0.71).hex() }, "comment.doc": { color: ramps.neutral(0.71).hex() }, primary: { color: ramps.neutral(1).hex() }, emphasis: { color: ramps.blue(0.5).hex() }, - "emphasis.strong": { color: ramps.blue(0.5).hex(), weight: font_weights.bold }, + "emphasis.strong": { + color: ramps.blue(0.5).hex(), + weight: font_weights.bold, + }, link_uri: { color: ramps.green(0.5).hex(), underline: true }, link_text: { color: ramps.orange(0.5).hex(), italic: true }, "text.literal": { color: ramps.orange(0.5).hex() }, diff --git a/styles/src/theme/theme_config.ts b/styles/src/theme/theme_config.ts index 8473bbb600608cac6157f894f3e9ac5d91c31a31..f5f83590743278508ba16b7245c2e7fc8e4d2650 100644 --- a/styles/src/theme/theme_config.ts +++ b/styles/src/theme/theme_config.ts @@ -55,7 +55,9 @@ export type ThemeConfigInputColorsKeys = keyof ThemeConfigInputColors * } * ``` */ -export type ThemeConfigInputSyntax = Partial>> +export type ThemeConfigInputSyntax = Partial< + Record> +> interface ThemeConfigOverrides { syntax: ThemeConfigInputSyntax diff --git a/styles/src/theme/tokens/theme.ts b/styles/src/theme/tokens/theme.ts index f9e83e0512012e0c5d699ac432869a70520a9839..d93079366961a1079df0858ceef980a0b9b59aec 100644 --- a/styles/src/theme/tokens/theme.ts +++ b/styles/src/theme/tokens/theme.ts @@ -4,9 +4,7 @@ import { SingleOtherToken, TokenTypes, } from "@tokens-studio/types" -import { - Shadow, -} from "../create_theme" +import { Shadow } from "../create_theme" import { LayerToken, layer_token } from "./layer" import { PlayersToken, players_token } from "./players" import { color_token } from "./token" diff --git a/styles/src/themes/atelier/common.ts b/styles/src/themes/atelier/common.ts index 09226b336c0aae3d42a4e99130e1c46875d6065b..9a0029581c565b0eb820e7bc8686f62e5e3627b2 100644 --- a/styles/src/themes/atelier/common.ts +++ b/styles/src/themes/atelier/common.ts @@ -1,4 +1,8 @@ -import { ThemeLicenseType, ThemeFamilyMeta, ThemeConfigInputSyntax } from "../../common" +import { + ThemeLicenseType, + ThemeFamilyMeta, + ThemeConfigInputSyntax, +} from "../../common" export interface Variant { colors: { diff --git a/styles/src/types/extract_syntax_types.ts b/styles/src/types/extract_syntax_types.ts index 3bf089518233a8b264e71853ad83e2634f9c1ab3..eb21d2418b9c830099cffc0c03f9ecf4c88ba7ed 100644 --- a/styles/src/types/extract_syntax_types.ts +++ b/styles/src/types/extract_syntax_types.ts @@ -1,9 +1,9 @@ -import fs from 'fs' -import path from 'path' -import readline from 'readline' +import fs from "fs" +import path from "path" +import readline from "readline" function escapeTypeName(name: string): string { - return `'${name.replace('@', '').toLowerCase()}'` + return `'${name.replace("@", "").toLowerCase()}'` } const generatedNote = `// This file is generated by extract_syntax_types.ts @@ -17,8 +17,8 @@ const defaultTextProperty = ` /** Default text color */ | 'primary'` const main = async () => { - const pathFromRoot = 'crates/zed/src/languages' - const directoryPath = path.join(__dirname, '../../../', pathFromRoot) + const pathFromRoot = "crates/zed/src/languages" + const directoryPath = path.join(__dirname, "../../../", pathFromRoot) const stylesMap: Record> = {} const propertyLanguageMap: Record> = {} @@ -47,24 +47,31 @@ const main = async () => { } } - const directories = fs.readdirSync(directoryPath, { withFileTypes: true }) - .filter(dirent => dirent.isDirectory()) - .map(dirent => dirent.name) + const directories = fs + .readdirSync(directoryPath, { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .map((dirent) => dirent.name) for (const dir of directories) { - const highlightsFilePath = path.join(directoryPath, dir, 'highlights.scm') + const highlightsFilePath = path.join( + directoryPath, + dir, + "highlights.scm" + ) if (fs.existsSync(highlightsFilePath)) { await processFile(highlightsFilePath, dir) } } for (const [language, properties] of Object.entries(stylesMap)) { - console.log(`${language}: ${Array.from(properties).join(', ')}`) + console.log(`${language}: ${Array.from(properties).join(", ")}`) } - const sortedProperties = Object.entries(propertyLanguageMap).sort(([propA], [propB]) => propA.localeCompare(propB)) + const sortedProperties = Object.entries(propertyLanguageMap).sort( + ([propA], [propB]) => propA.localeCompare(propB) + ) - const outStream = fs.createWriteStream(path.join(__dirname, 'syntax.ts')) + const outStream = fs.createWriteStream(path.join(__dirname, "syntax.ts")) let allProperties = "" const syntaxKeys = [] for (const [property, languages] of sortedProperties) { @@ -73,9 +80,9 @@ const main = async () => { // Limit to the first 7 languages, append "..." if more than 7 languagesArray = languagesArray.slice(0, 7) if (moreThanSeven) { - languagesArray.push('...') + languagesArray.push("...") } - const languagesString = languagesArray.join(', ') + const languagesString = languagesArray.join(", ") const comment = `/** ${languagesString} */` allProperties += ` ${comment}\n | ${property} \n` syntaxKeys.push(property) @@ -95,7 +102,9 @@ export type SyntaxOverride = Partial export type SyntaxProperty = \n${defaultTextProperty}\n\n${allProperties} -export const allSyntaxKeys: SyntaxProperty[] = [\n ${syntaxKeys.join(',\n ')}\n]`) +export const allSyntaxKeys: SyntaxProperty[] = [\n ${syntaxKeys.join( + ",\n " + )}\n]`) outStream.end() } diff --git a/styles/src/types/syntax.ts b/styles/src/types/syntax.ts index b74edfdf8463e510c40fee84c35e5d22d6586d83..9b23dbde3cc799090e1dd848706f2b96a88e7ba6 100644 --- a/styles/src/types/syntax.ts +++ b/styles/src/types/syntax.ts @@ -6,198 +6,197 @@ // 'npm run extract-syntax-types' from ./styles export type SyntaxHighlightStyle = { - color: string, - fade_out?: number, - italic?: boolean, - underline?: boolean, - weight?: string, + color: string + fade_out?: number + italic?: boolean + underline?: boolean + weight?: string } export type Syntax = Record export type SyntaxOverride = Partial -export type SyntaxProperty = +export type SyntaxProperty = /** Default text color */ - | 'primary' + | "primary" /** elixir */ - | '__attribute__' + | "__attribute__" /** elixir */ - | '__name__' + | "__name__" /** elixir */ - | '_sigil_name' + | "_sigil_name" /** css, heex, lua */ - | 'attribute' + | "attribute" /** javascript, lua, tsx, typescript, yaml */ - | 'boolean' + | "boolean" /** elixir */ - | 'comment.doc' + | "comment.doc" /** elixir */ - | 'comment.unused' + | "comment.unused" /** bash, c, cpp, css, elixir, elm, erb, ... */ - | 'comment' + | "comment" /** elixir, go, javascript, lua, php, python, racket, ... */ - | 'constant.builtin' + | "constant.builtin" /** bash, c, cpp, elixir, elm, glsl, heex, ... */ - | 'constant' + | "constant" /** glsl */ - | 'delimiter' + | "delimiter" /** bash, elixir, javascript, python, ruby, tsx, typescript */ - | 'embedded' + | "embedded" /** markdown */ - | 'emphasis.strong' + | "emphasis.strong" /** markdown */ - | 'emphasis' + | "emphasis" /** go, python, racket, ruby, scheme */ - | 'escape' + | "escape" /** lua */ - | 'field' + | "field" /** lua, php, python */ - | 'function.builtin' + | "function.builtin" /** elm, lua, rust */ - | 'function.definition' + | "function.definition" /** ruby */ - | 'function.method.builtin' + | "function.method.builtin" /** go, javascript, php, python, ruby, rust, tsx, ... */ - | 'function.method' + | "function.method" /** rust */ - | 'function.special.definition' + | "function.special.definition" /** c, cpp, glsl, rust */ - | 'function.special' + | "function.special" /** bash, c, cpp, css, elixir, elm, glsl, ... */ - | 'function' + | "function" /** elm */ - | 'identifier' + | "identifier" /** glsl */ - | 'keyword.function' + | "keyword.function" /** bash, c, cpp, css, elixir, elm, erb, ... */ - | 'keyword' + | "keyword" /** c, cpp, glsl */ - | 'label' + | "label" /** markdown */ - | 'link_text' + | "link_text" /** markdown */ - | 'link_uri' + | "link_uri" /** lua, php, tsx, typescript */ - | 'method.constructor' + | "method.constructor" /** lua */ - | 'method' + | "method" /** heex */ - | 'module' + | "module" /** svelte */ - | 'none' + | "none" /** bash, c, cpp, css, elixir, glsl, go, ... */ - | 'number' + | "number" /** bash, c, cpp, css, elixir, elm, glsl, ... */ - | 'operator' + | "operator" /** lua */ - | 'parameter' + | "parameter" /** lua */ - | 'preproc' + | "preproc" /** bash, c, cpp, css, glsl, go, html, ... */ - | 'property' + | "property" /** c, cpp, elixir, elm, heex, html, javascript, ... */ - | 'punctuation.bracket' + | "punctuation.bracket" /** c, cpp, css, elixir, elm, heex, javascript, ... */ - | 'punctuation.delimiter' + | "punctuation.delimiter" /** markdown */ - | 'punctuation.list_marker' + | "punctuation.list_marker" /** elixir, javascript, python, ruby, tsx, typescript, yaml */ - | 'punctuation.special' + | "punctuation.special" /** elixir */ - | 'punctuation' + | "punctuation" /** glsl */ - | 'storageclass' + | "storageclass" /** elixir, elm, yaml */ - | 'string.escape' + | "string.escape" /** elixir, javascript, racket, ruby, tsx, typescript */ - | 'string.regex' + | "string.regex" /** elixir, ruby */ - | 'string.special.symbol' + | "string.special.symbol" /** css, elixir, toml */ - | 'string.special' + | "string.special" /** bash, c, cpp, css, elixir, elm, glsl, ... */ - | 'string' + | "string" /** svelte */ - | 'tag.delimiter' + | "tag.delimiter" /** css, heex, php, svelte */ - | 'tag' + | "tag" /** markdown */ - | 'text.literal' + | "text.literal" /** markdown */ - | 'title' + | "title" /** javascript, php, rust, tsx, typescript */ - | 'type.builtin' + | "type.builtin" /** glsl */ - | 'type.qualifier' + | "type.qualifier" /** c, cpp, css, elixir, elm, glsl, go, ... */ - | 'type' + | "type" /** glsl, php */ - | 'variable.builtin' + | "variable.builtin" /** cpp, css, javascript, lua, racket, ruby, rust, ... */ - | 'variable.special' + | "variable.special" /** c, cpp, elm, glsl, go, javascript, lua, ... */ - | 'variable' - + | "variable" export const allSyntaxKeys: SyntaxProperty[] = [ - '__attribute__', - '__name__', - '_sigil_name', - 'attribute', - 'boolean', - 'comment.doc', - 'comment.unused', - 'comment', - 'constant.builtin', - 'constant', - 'delimiter', - 'embedded', - 'emphasis.strong', - 'emphasis', - 'escape', - 'field', - 'function.builtin', - 'function.definition', - 'function.method.builtin', - 'function.method', - 'function.special.definition', - 'function.special', - 'function', - 'identifier', - 'keyword.function', - 'keyword', - 'label', - 'link_text', - 'link_uri', - 'method.constructor', - 'method', - 'module', - 'none', - 'number', - 'operator', - 'parameter', - 'preproc', - 'property', - 'punctuation.bracket', - 'punctuation.delimiter', - 'punctuation.list_marker', - 'punctuation.special', - 'punctuation', - 'storageclass', - 'string.escape', - 'string.regex', - 'string.special.symbol', - 'string.special', - 'string', - 'tag.delimiter', - 'tag', - 'text.literal', - 'title', - 'type.builtin', - 'type.qualifier', - 'type', - 'variable.builtin', - 'variable.special', - 'variable' -] \ No newline at end of file + "__attribute__", + "__name__", + "_sigil_name", + "attribute", + "boolean", + "comment.doc", + "comment.unused", + "comment", + "constant.builtin", + "constant", + "delimiter", + "embedded", + "emphasis.strong", + "emphasis", + "escape", + "field", + "function.builtin", + "function.definition", + "function.method.builtin", + "function.method", + "function.special.definition", + "function.special", + "function", + "identifier", + "keyword.function", + "keyword", + "label", + "link_text", + "link_uri", + "method.constructor", + "method", + "module", + "none", + "number", + "operator", + "parameter", + "preproc", + "property", + "punctuation.bracket", + "punctuation.delimiter", + "punctuation.list_marker", + "punctuation.special", + "punctuation", + "storageclass", + "string.escape", + "string.regex", + "string.special.symbol", + "string.special", + "string", + "tag.delimiter", + "tag", + "text.literal", + "title", + "type.builtin", + "type.qualifier", + "type", + "variable.builtin", + "variable.special", + "variable", +] diff --git a/styles/tsconfig.json b/styles/tsconfig.json index 281bd74b215bd16426bb6a8f9d68ddeb5a5bea43..a1913027b705df7d349c78bcc6b74bb96851fe8c 100644 --- a/styles/tsconfig.json +++ b/styles/tsconfig.json @@ -24,7 +24,5 @@ "useUnknownInCatchVariables": false, "baseUrl": "." }, - "exclude": [ - "node_modules" - ] + "exclude": ["node_modules"] } From b08a2770b867951c38a4286ebf96223578f0fc4a Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 27 Jul 2023 13:02:40 -0400 Subject: [PATCH 11/52] Remove redundant `syntax_highlights` --- styles/src/theme/syntax.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/styles/src/theme/syntax.ts b/styles/src/theme/syntax.ts index b1bf5ed9307b87036656d902b892c56b627022a0..db8f98de663bcb3afa8e84ea851363a3f83cbd0c 100644 --- a/styles/src/theme/syntax.ts +++ b/styles/src/theme/syntax.ts @@ -78,7 +78,6 @@ export const syntaxStyle = ( "string.regex": { color: ramps.orange(0.5).hex() }, "method.constructor": { color: ramps.blue(0.5).hex() }, type: { color: ramps.cyan(0.5).hex() }, - variable: { color: ramps.neutral(1).hex() }, label: { color: ramps.blue(0.5).hex() }, attribute: { color: ramps.blue(0.5).hex() }, property: { color: ramps.blue(0.5).hex() }, @@ -88,8 +87,6 @@ export const syntaxStyle = ( number: { color: ramps.green(0.5).hex() }, boolean: { color: ramps.green(0.5).hex() }, function: { color: ramps.yellow(0.5).hex() }, - preproc: { color: ramps.neutral(1).hex() }, - embedded: { color: ramps.neutral(1).hex() }, } const baseSyntax = apply_defaults(ramps, syntax_highlights) From d8352743061ebf73e382b724b80aeec236a67763 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Jul 2023 11:11:24 -0700 Subject: [PATCH 12/52] Downgrade our dependency on treesitter-cpp --- Cargo.lock | 17 +++++++++++++---- Cargo.toml | 2 +- crates/language/src/language.rs | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 05c5faa787cf29f52b9150c4a224e98c653b2f2f..674765f00cbe98c8a4284378b060f89b0b7509ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6513,7 +6513,7 @@ dependencies = [ "theme", "tiktoken-rs 0.5.0", "tree-sitter", - "tree-sitter-cpp", + "tree-sitter-cpp 0.20.2", "tree-sitter-elixir 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tree-sitter-json 0.19.0", "tree-sitter-rust", @@ -8032,9 +8032,18 @@ dependencies = [ [[package]] name = "tree-sitter-cpp" -version = "0.20.1" +version = "0.20.0" +source = "git+https://github.com/tree-sitter/tree-sitter-cpp?rev=f44509141e7e483323d2ec178f2d2e6c0fc041c1#f44509141e7e483323d2ec178f2d2e6c0fc041c1" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-cpp" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dbedbf4066bfab725b3f9e2a21530507419a7d2f98621d3c13213502b734ec0" +checksum = "1c88fd925d0333e63ac64e521f5bd79c53019e569ffbbccfeef346a326f459e9" dependencies = [ "cc", "tree-sitter", @@ -9622,7 +9631,7 @@ dependencies = [ "tree-sitter", "tree-sitter-bash", "tree-sitter-c", - "tree-sitter-cpp", + "tree-sitter-cpp 0.20.0", "tree-sitter-css", "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=4ba9dab6e2602960d95b2b625f3386c27e08084e)", "tree-sitter-elm", diff --git a/Cargo.toml b/Cargo.toml index 7bcbc7e2dcf2a73b639311a00800afcb1275ccb1..fc46286de0c78f286e9d110aed41fe41bf3902d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,7 +109,7 @@ pretty_assertions = "1.3.0" tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "1b0321ee85701d5036c334a6f04761cdc672e64c" } tree-sitter-c = "0.20.1" -tree-sitter-cpp = "0.20.0" +tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev="f44509141e7e483323d2ec178f2d2e6c0fc041c1" } tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" } tree-sitter-elm = { git = "https://github.com/elm-tooling/tree-sitter-elm", rev = "692c50c0b961364c40299e73c1306aecb5d20f40"} diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index e34358c7c5def79e8141e86e54693bcc99188da0..b265bba7b56267c63af402db361be338fbebd27d 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -844,8 +844,8 @@ impl LanguageRegistry { } } } - Err(err) => { - log::error!("failed to load language {name} - {err}"); + Err(e) => { + log::error!("failed to load language {name}:\n{:?}", e); let mut state = this.state.write(); state.mark_language_loaded(id); if let Some(mut txs) = state.loading_languages.remove(&id) { @@ -853,7 +853,7 @@ impl LanguageRegistry { let _ = tx.send(Err(anyhow!( "failed to load language {}: {}", name, - err + e ))); } } @@ -1188,25 +1188,25 @@ impl Language { pub fn with_queries(mut self, queries: LanguageQueries) -> Result { if let Some(query) = queries.highlights { - self = self.with_highlights_query(query.as_ref())?; + self = self.with_highlights_query(query.as_ref()).context("Error loading highlights query")?; } if let Some(query) = queries.brackets { - self = self.with_brackets_query(query.as_ref())?; + self = self.with_brackets_query(query.as_ref()).context("Error loading brackets query")?; } if let Some(query) = queries.indents { - self = self.with_indents_query(query.as_ref())?; + self = self.with_indents_query(query.as_ref()).context("Error loading indents query")?; } if let Some(query) = queries.outline { - self = self.with_outline_query(query.as_ref())?; + self = self.with_outline_query(query.as_ref()).context("Error loading outline query")?; } if let Some(query) = queries.embedding { - self = self.with_embedding_query(query.as_ref())?; + self = self.with_embedding_query(query.as_ref()).context("Error loading embedding query")?; } if let Some(query) = queries.injections { - self = self.with_injection_query(query.as_ref())?; + self = self.with_injection_query(query.as_ref()).context("Error loading injection query")?; } if let Some(query) = queries.overrides { - self = self.with_override_query(query.as_ref())?; + self = self.with_override_query(query.as_ref()).context("Error loading override query")?; } Ok(self) } From a829b5be01659953d133c3b6ee284770fa1f3879 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Jul 2023 11:14:21 -0700 Subject: [PATCH 13/52] fmt --- crates/language/src/language.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index b265bba7b56267c63af402db361be338fbebd27d..125e14d445f3872e9718cb2759016a09b0c28439 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -1188,25 +1188,39 @@ impl Language { pub fn with_queries(mut self, queries: LanguageQueries) -> Result { if let Some(query) = queries.highlights { - self = self.with_highlights_query(query.as_ref()).context("Error loading highlights query")?; + self = self + .with_highlights_query(query.as_ref()) + .context("Error loading highlights query")?; } if let Some(query) = queries.brackets { - self = self.with_brackets_query(query.as_ref()).context("Error loading brackets query")?; + self = self + .with_brackets_query(query.as_ref()) + .context("Error loading brackets query")?; } if let Some(query) = queries.indents { - self = self.with_indents_query(query.as_ref()).context("Error loading indents query")?; + self = self + .with_indents_query(query.as_ref()) + .context("Error loading indents query")?; } if let Some(query) = queries.outline { - self = self.with_outline_query(query.as_ref()).context("Error loading outline query")?; + self = self + .with_outline_query(query.as_ref()) + .context("Error loading outline query")?; } if let Some(query) = queries.embedding { - self = self.with_embedding_query(query.as_ref()).context("Error loading embedding query")?; + self = self + .with_embedding_query(query.as_ref()) + .context("Error loading embedding query")?; } if let Some(query) = queries.injections { - self = self.with_injection_query(query.as_ref()).context("Error loading injection query")?; + self = self + .with_injection_query(query.as_ref()) + .context("Error loading injection query")?; } if let Some(query) = queries.overrides { - self = self.with_override_query(query.as_ref()).context("Error loading override query")?; + self = self + .with_override_query(query.as_ref()) + .context("Error loading override query")?; } Ok(self) } From 7a9af7c663e7669fd1147bca7aecb89f969d1e89 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Thu, 27 Jul 2023 15:17:13 -0400 Subject: [PATCH 14/52] Publish preview releases to discord --- .github/workflows/release_actions.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release_actions.yml b/.github/workflows/release_actions.yml index 71909ae1771637ed099e532266d740dfe3361a2f..6c3b3d57c0b49453c66597b133b2893e898f398e 100644 --- a/.github/workflows/release_actions.yml +++ b/.github/workflows/release_actions.yml @@ -8,7 +8,6 @@ jobs: steps: - name: Discord Webhook Action uses: tsickert/discord-webhook@v5.3.0 - if: ${{ ! github.event.release.prerelease }} with: webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }} content: | From 39794544852192000ec524d6aa94179732ff6fb9 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Thu, 27 Jul 2023 17:13:37 -0400 Subject: [PATCH 15/52] Follow naming convention for menu items --- crates/collab_ui/src/collab_titlebar_item.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index ce8d10d655d76b018aef855a934c95e1d7b1640c..a54c0e9e7950634f64fe123cfb560e1e1f1f28dc 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -374,7 +374,7 @@ impl CollabTitlebarItem { "Share Feedback", feedback::feedback_editor::GiveFeedback, ), - ContextMenuItem::action("Sign out", SignOut), + ContextMenuItem::action("Sign Out", SignOut), ] } else { vec![ From fc9687d16334ac33f482630f9a9330bc24bd8edb Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 27 Jul 2023 18:27:36 -0400 Subject: [PATCH 16/52] Avoid panic by accessing view handle by global in wrong window View handles are window specific but this global will be doing things in all windows, that would cause a panic when it attempted to update a status bar mode indicator in a background window Co-Authored-By: Mikayla Maki --- crates/vim/src/mode_indicator.rs | 61 +++++++++++++++++++++---- crates/vim/src/test.rs | 14 +++--- crates/vim/src/test/vim_test_context.rs | 4 ++ crates/vim/src/vim.rs | 51 +++------------------ crates/zed/src/zed.rs | 2 + 5 files changed, 72 insertions(+), 60 deletions(-) diff --git a/crates/vim/src/mode_indicator.rs b/crates/vim/src/mode_indicator.rs index e0d2b65955489ae72742febd13de1b0c5e1e5e41..84e3e5868a42f8b3f360af2d7b0e17a8f17fc015 100644 --- a/crates/vim/src/mode_indicator.rs +++ b/crates/vim/src/mode_indicator.rs @@ -1,20 +1,60 @@ -use gpui::{elements::Label, AnyElement, Element, Entity, View, ViewContext}; +use gpui::{ + elements::{Empty, Label}, + AnyElement, Element, Entity, Subscription, View, ViewContext, +}; +use settings::SettingsStore; use workspace::{item::ItemHandle, StatusItemView}; -use crate::state::Mode; +use crate::{state::Mode, Vim, VimEvent, VimModeSetting}; pub struct ModeIndicator { - pub mode: Mode, + pub mode: Option, + _subscription: Subscription, } impl ModeIndicator { - pub fn new(mode: Mode) -> Self { - Self { mode } + pub fn new(cx: &mut ViewContext) -> Self { + let handle = cx.handle().downgrade(); + + let _subscription = cx.subscribe_global::(move |&event, cx| { + if let Some(mode_indicator) = handle.upgrade(cx) { + match event { + VimEvent::ModeChanged { mode } => { + cx.update_window(mode_indicator.window_id(), |cx| { + mode_indicator.update(cx, move |mode_indicator, cx| { + mode_indicator.set_mode(mode, cx); + }) + }); + } + } + } + }); + + cx.observe_global::(move |mode_indicator, cx| { + if settings::get::(cx).0 { + mode_indicator.mode = cx + .has_global::() + .then(|| cx.global::().state.mode); + } else { + mode_indicator.mode.take(); + } + }) + .detach(); + + // Vim doesn't exist in some tests + let mode = cx + .has_global::() + .then(|| cx.global::().state.mode); + + Self { + mode, + _subscription, + } } pub fn set_mode(&mut self, mode: Mode, cx: &mut ViewContext) { - if mode != self.mode { - self.mode = mode; + if self.mode != Some(mode) { + self.mode = Some(mode); cx.notify(); } } @@ -30,11 +70,16 @@ impl View for ModeIndicator { } fn render(&mut self, cx: &mut ViewContext) -> AnyElement { + let Some(mode) = self.mode.as_ref() else { + return Empty::new().into_any(); + }; + let theme = &theme::current(cx).workspace.status_bar; + // we always choose text to be 12 monospace characters // so that as the mode indicator changes, the rest of the // UI stays still. - let text = match self.mode { + let text = match mode { Mode::Normal => "-- NORMAL --", Mode::Insert => "-- INSERT --", Mode::Visual { line: false } => "-- VISUAL --", diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 96d6a2b69019d47ef7d131f1ef66d6c218089ec1..98d8cb8749996909757367c36e2591817030bebe 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -215,7 +215,7 @@ async fn test_status_indicator( assert_eq!( cx.workspace(|_, cx| mode_indicator.read(cx).mode), - Mode::Normal + Some(Mode::Normal) ); // shows the correct mode @@ -223,7 +223,7 @@ async fn test_status_indicator( deterministic.run_until_parked(); assert_eq!( cx.workspace(|_, cx| mode_indicator.read(cx).mode), - Mode::Insert + Some(Mode::Insert) ); // shows even in search @@ -231,7 +231,7 @@ async fn test_status_indicator( deterministic.run_until_parked(); assert_eq!( cx.workspace(|_, cx| mode_indicator.read(cx).mode), - Mode::Visual { line: false } + Some(Mode::Visual { line: false }) ); // hides if vim mode is disabled @@ -239,15 +239,15 @@ async fn test_status_indicator( deterministic.run_until_parked(); cx.workspace(|workspace, cx| { let status_bar = workspace.status_bar().read(cx); - let mode_indicator = status_bar.item_of_type::(); - assert!(mode_indicator.is_none()); + let mode_indicator = status_bar.item_of_type::().unwrap(); + assert!(mode_indicator.read(cx).mode.is_none()); }); cx.enable_vim(); deterministic.run_until_parked(); cx.workspace(|workspace, cx| { let status_bar = workspace.status_bar().read(cx); - let mode_indicator = status_bar.item_of_type::(); - assert!(mode_indicator.is_some()); + let mode_indicator = status_bar.item_of_type::().unwrap(); + assert!(mode_indicator.read(cx).mode.is_some()); }); } diff --git a/crates/vim/src/test/vim_test_context.rs b/crates/vim/src/test/vim_test_context.rs index 56ca654644c5277fc8eca5e8fcd769815a6a356c..ea09e550916c4355b10d12b6d3a5a2207112dd16 100644 --- a/crates/vim/src/test/vim_test_context.rs +++ b/crates/vim/src/test/vim_test_context.rs @@ -43,6 +43,10 @@ impl<'a> VimTestContext<'a> { toolbar.add_item(project_search_bar, cx); }) }); + workspace.status_bar().update(cx, |status_bar, cx| { + let vim_mode_indicator = cx.add_view(ModeIndicator::new); + status_bar.add_right_item(vim_mode_indicator, cx); + }); }); Self { cx } diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index d8edf1a667ff06a17e50c4ef69f95e82c1570ba2..22bd196c678d72b40949ffc8171afa3444c4e447 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -43,6 +43,11 @@ struct Number(u8); actions!(vim, [Tab, Enter]); impl_actions!(vim, [Number, SwitchMode, PushOperator]); +#[derive(Copy, Clone, Debug)] +enum VimEvent { + ModeChanged { mode: Mode }, +} + pub fn init(cx: &mut AppContext) { settings::register::(cx); @@ -121,8 +126,6 @@ pub fn observe_keystrokes(cx: &mut WindowContext) { pub struct Vim { active_editor: Option>, editor_subscription: Option, - mode_indicator: Option>, - enabled: bool, state: VimState, } @@ -181,9 +184,7 @@ impl Vim { self.state.mode = mode; self.state.operator_stack.clear(); - if let Some(mode_indicator) = &self.mode_indicator { - mode_indicator.update(cx, |mode_indicator, cx| mode_indicator.set_mode(mode, cx)) - } + cx.emit_global(VimEvent::ModeChanged { mode }); // Sync editor settings like clip mode self.sync_vim_settings(cx); @@ -271,44 +272,6 @@ impl Vim { } } - fn sync_mode_indicator(cx: &mut WindowContext) { - let Some(workspace) = cx.root_view() - .downcast_ref::() - .map(|workspace| workspace.downgrade()) else { - return; - }; - - cx.spawn(|mut cx| async move { - workspace.update(&mut cx, |workspace, cx| { - Vim::update(cx, |vim, cx| { - workspace.status_bar().update(cx, |status_bar, cx| { - let current_position = status_bar.position_of_item::(); - - if vim.enabled && current_position.is_none() { - if vim.mode_indicator.is_none() { - vim.mode_indicator = - Some(cx.add_view(|_| ModeIndicator::new(vim.state.mode))); - }; - let mode_indicator = vim.mode_indicator.as_ref().unwrap(); - let position = status_bar - .position_of_item::(); - if let Some(position) = position { - status_bar.insert_item_after(position, mode_indicator.clone(), cx) - } else { - status_bar.add_left_item(mode_indicator.clone(), cx) - } - } else if !vim.enabled { - if let Some(position) = current_position { - status_bar.remove_item_at(position, cx) - } - } - }) - }) - }) - }) - .detach_and_log_err(cx); - } - fn set_enabled(&mut self, enabled: bool, cx: &mut AppContext) { if self.enabled != enabled { self.enabled = enabled; @@ -359,8 +322,6 @@ impl Vim { self.unhook_vim_settings(editor, cx); } }); - - Vim::sync_mode_indicator(cx); } fn unhook_vim_settings(&self, editor: &mut Editor, cx: &mut ViewContext) { diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 84cef99f81e41d0b43909ab2368e3366a7257d26..a29567ac385633af04b7e7c3f4b2c0de595d892c 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -308,6 +308,7 @@ pub fn initialize_workspace( ); let active_buffer_language = cx.add_view(|_| language_selector::ActiveBufferLanguage::new(workspace)); + let vim_mode_indicator = cx.add_view(|cx| vim::ModeIndicator::new(cx)); let feedback_button = cx.add_view(|_| { feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace) }); @@ -319,6 +320,7 @@ pub fn initialize_workspace( status_bar.add_right_item(feedback_button, cx); status_bar.add_right_item(copilot, cx); status_bar.add_right_item(active_buffer_language, cx); + status_bar.add_right_item(vim_mode_indicator, cx); status_bar.add_right_item(cursor_position, cx); }); From 03bc430bdd82422dc01813f859a8ff8e201212a6 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Jul 2023 16:14:56 -0700 Subject: [PATCH 17/52] Make mode indicator follow vim enabled state --- crates/vim/src/mode_indicator.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/mode_indicator.rs b/crates/vim/src/mode_indicator.rs index 84e3e5868a42f8b3f360af2d7b0e17a8f17fc015..639a7594f113c61bc8c232325ac8d769b2ac89e5 100644 --- a/crates/vim/src/mode_indicator.rs +++ b/crates/vim/src/mode_indicator.rs @@ -44,7 +44,11 @@ impl ModeIndicator { // Vim doesn't exist in some tests let mode = cx .has_global::() - .then(|| cx.global::().state.mode); + .then(|| { + let vim = cx.global::(); + vim.enabled.then(|| vim.state.mode) + }) + .flatten(); Self { mode, From 1935307b4f6b80438df46719ab5202ea7bd26850 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 27 Jul 2023 18:08:15 -0600 Subject: [PATCH 18/52] Fix jumping to definition in a new file This is broken because vim currently sets settings only on the active editor. Fix this by correcting the range on the currently active editor. It would be nice (at some point) to refactor how vim sets settings, but that's for another day. --- crates/editor/src/editor.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index e05837740d4c50fbe7e02e51272bd6340884ec8a..7af3f5460def3d55a9d661e3b29724e0d392e637 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6374,8 +6374,8 @@ impl Editor { .range .to_offset(definition.target.buffer.read(cx)); + let range = self.range_for_match(&range); if Some(&definition.target.buffer) == self.buffer.read(cx).as_singleton().as_ref() { - let range = self.range_for_match(&range); self.change_selections(Some(Autoscroll::fit()), cx, |s| { s.select_ranges([range]); }); @@ -6392,7 +6392,6 @@ impl Editor { // When selecting a definition in a different buffer, disable the nav history // to avoid creating a history entry at the previous cursor location. pane.update(cx, |pane, _| pane.disable_history()); - let range = target_editor.range_for_match(&range); target_editor.change_selections(Some(Autoscroll::fit()), cx, |s| { s.select_ranges([range]); }); From f15a03816f9357522a3793fbba449818dc9ed67e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Jul 2023 17:19:32 -0700 Subject: [PATCH 19/52] underscore arguments --- crates/zed/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index df16ea7db97fbbd2acfb005be15ff45af7ef4ad1..b9fefb89a73555a16a03d9d7e34fa5369d3abde4 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -717,7 +717,7 @@ async fn watch_languages(_: Arc, _: Arc) -> Option<()> } #[cfg(not(debug_assertions))] -fn watch_file_types(fs: Arc, cx: &mut AppContext) {} +fn watch_file_types(_fs: Arc, _cx: &mut AppContext) {} fn connect_to_cli( server_name: &str, From 0dffb728db4287376c1fc9214e2de3b7aee2d06e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Jul 2023 17:36:02 -0700 Subject: [PATCH 20/52] Update elixir depedency co-authored-by: Alex --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c6a213d0d4e36a427fc4352b2e417258f12de8f..9de3e6f4a69fb14351504b66a59f293069978381 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3851,7 +3851,7 @@ dependencies = [ "text", "theme", "tree-sitter", - "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=4ba9dab6e2602960d95b2b625f3386c27e08084e)", + "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=2616034f78ffa83ca6a521ebd7eee1868cb5c14c)", "tree-sitter-embedded-template", "tree-sitter-heex", "tree-sitter-html", @@ -8287,7 +8287,7 @@ dependencies = [ [[package]] name = "tree-sitter-elixir" version = "0.1.0" -source = "git+https://github.com/elixir-lang/tree-sitter-elixir?rev=4ba9dab6e2602960d95b2b625f3386c27e08084e#4ba9dab6e2602960d95b2b625f3386c27e08084e" +source = "git+https://github.com/elixir-lang/tree-sitter-elixir?rev=2616034f78ffa83ca6a521ebd7eee1868cb5c14c#2616034f78ffa83ca6a521ebd7eee1868cb5c14c" dependencies = [ "cc", "tree-sitter", @@ -9923,7 +9923,7 @@ dependencies = [ "tree-sitter-c", "tree-sitter-cpp 0.20.0", "tree-sitter-css", - "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=4ba9dab6e2602960d95b2b625f3386c27e08084e)", + "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=2616034f78ffa83ca6a521ebd7eee1868cb5c14c)", "tree-sitter-elm", "tree-sitter-embedded-template", "tree-sitter-glsl", diff --git a/Cargo.toml b/Cargo.toml index fc46286de0c78f286e9d110aed41fe41bf3902d3..19d43a1b95bc3f7ebf4c482dad8d1a4607faa8c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,7 +111,7 @@ tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", re tree-sitter-c = "0.20.1" tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev="f44509141e7e483323d2ec178f2d2e6c0fc041c1" } tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } -tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" } +tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "2616034f78ffa83ca6a521ebd7eee1868cb5c14c" } tree-sitter-elm = { git = "https://github.com/elm-tooling/tree-sitter-elm", rev = "692c50c0b961364c40299e73c1306aecb5d20f40"} tree-sitter-embedded-template = "0.20.0" tree-sitter-glsl = { git = "https://github.com/theHamsta/tree-sitter-glsl", rev = "2a56fb7bc8bb03a1892b4741279dd0a8758b7fb3" } From 45e5d816649242b058c19979779c0b04c3d9de17 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Jul 2023 17:41:13 -0700 Subject: [PATCH 21/52] update to dependency without symbol conflict --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9de3e6f4a69fb14351504b66a59f293069978381..04ee8c2212f0296c8f1af116823296bb51b49e59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3851,7 +3851,7 @@ dependencies = [ "text", "theme", "tree-sitter", - "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=2616034f78ffa83ca6a521ebd7eee1868cb5c14c)", + "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=a2861e88a730287a60c11ea9299c033c7d076e30)", "tree-sitter-embedded-template", "tree-sitter-heex", "tree-sitter-html", @@ -8287,7 +8287,7 @@ dependencies = [ [[package]] name = "tree-sitter-elixir" version = "0.1.0" -source = "git+https://github.com/elixir-lang/tree-sitter-elixir?rev=2616034f78ffa83ca6a521ebd7eee1868cb5c14c#2616034f78ffa83ca6a521ebd7eee1868cb5c14c" +source = "git+https://github.com/elixir-lang/tree-sitter-elixir?rev=a2861e88a730287a60c11ea9299c033c7d076e30#a2861e88a730287a60c11ea9299c033c7d076e30" dependencies = [ "cc", "tree-sitter", @@ -9923,7 +9923,7 @@ dependencies = [ "tree-sitter-c", "tree-sitter-cpp 0.20.0", "tree-sitter-css", - "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=2616034f78ffa83ca6a521ebd7eee1868cb5c14c)", + "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=a2861e88a730287a60c11ea9299c033c7d076e30)", "tree-sitter-elm", "tree-sitter-embedded-template", "tree-sitter-glsl", diff --git a/Cargo.toml b/Cargo.toml index 19d43a1b95bc3f7ebf4c482dad8d1a4607faa8c8..157db0635f7bcc490ba207c6c0932899cfd6abf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,7 +111,7 @@ tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", re tree-sitter-c = "0.20.1" tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev="f44509141e7e483323d2ec178f2d2e6c0fc041c1" } tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } -tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "2616034f78ffa83ca6a521ebd7eee1868cb5c14c" } +tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "a2861e88a730287a60c11ea9299c033c7d076e30" } tree-sitter-elm = { git = "https://github.com/elm-tooling/tree-sitter-elm", rev = "692c50c0b961364c40299e73c1306aecb5d20f40"} tree-sitter-embedded-template = "0.20.0" tree-sitter-glsl = { git = "https://github.com/theHamsta/tree-sitter-glsl", rev = "2a56fb7bc8bb03a1892b4741279dd0a8758b7fb3" } From a0fc515cfca9677dde32cef8be22321d1304a13e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Jul 2023 17:58:43 -0700 Subject: [PATCH 22/52] Rework close_inactive_items to await all tasks Update action name to be more accurate --- assets/keymaps/default.json | 2 +- crates/workspace/src/pane.rs | 4 +++ crates/workspace/src/workspace.rs | 42 ++++++++++++++++++++----------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 5c841d19b2ca1b5bf54e5ca93c5f7d10341876b5..090385458efd1bb43cce6d83615fbbaf8dbc6166 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -22,7 +22,7 @@ "alt-cmd-right": "pane::ActivateNextItem", "cmd-w": "pane::CloseActiveItem", "alt-cmd-t": "pane::CloseInactiveItems", - "ctrl-alt-cmd-w": "workspace::CloseInactiveEditors", + "ctrl-alt-cmd-w": "workspace::CloseInactiveTabsAndPanes", "cmd-k u": "pane::CloseCleanItems", "cmd-k cmd-w": "pane::CloseAllItems", "cmd-shift-w": "workspace::CloseWindow", diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 2972c307f2624a6bb23bef0f1919aab5a43eb66d..ee658c9cc92b3a4fa24a56f986e895547a190ad1 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -746,6 +746,10 @@ impl Pane { _: &CloseAllItems, cx: &mut ViewContext, ) -> Option>> { + if self.items.is_empty() { + return None; + } + Some(self.close_items(cx, move |_| true)) } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 6694cc06a32ff416323cea047539759a8ee62e39..827b0b8427c0bf4e0f25237d664489f747199592 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -21,6 +21,7 @@ use drag_and_drop::DragAndDrop; use futures::{ channel::{mpsc, oneshot}, future::try_join_all, + stream::FuturesUnordered, FutureExt, StreamExt, }; use gpui::{ @@ -122,7 +123,7 @@ actions!( NewFile, NewWindow, CloseWindow, - CloseInactiveEditors, + CloseInactiveTabsAndPanes, AddFolderToProject, Unfollow, Save, @@ -240,7 +241,7 @@ pub fn init(app_state: Arc, cx: &mut AppContext) { cx.add_async_action(Workspace::follow_next_collaborator); cx.add_async_action(Workspace::close); - cx.add_async_action(Workspace::close_inactive_editors); + cx.add_async_action(Workspace::close_inactive_items_and_panes); cx.add_global_action(Workspace::close_global); cx.add_global_action(restart); cx.add_async_action(Workspace::save_all); @@ -1635,32 +1636,43 @@ impl Workspace { } } - pub fn close_inactive_editors( + pub fn close_inactive_items_and_panes( &mut self, - _: &CloseInactiveEditors, + _: &CloseInactiveTabsAndPanes, cx: &mut ViewContext, ) -> Option>> { let current_pane = self.active_pane(); - // let mut tasks: Vec>> = Vec::new(); - current_pane - .update(cx, |pane, cx| { - pane.close_inactive_items(&CloseInactiveItems, cx).unwrap() - }) - .detach_and_log_err(cx); + let mut tasks = Vec::new(); + + if let Some(current_pane_close) = current_pane.update(cx, |pane, cx| { + pane.close_inactive_items(&CloseInactiveItems, cx) + }) { + tasks.push(current_pane_close); + }; for pane in self.panes() { if pane.id() == current_pane.id() { continue; } - pane.update(cx, |pane: &mut Pane, cx| { - pane.close_all_items(&CloseAllItems, cx).unwrap() - }) - .detach_and_log_err(cx); + if let Some(close_pane_items) = pane.update(cx, |pane: &mut Pane, cx| { + pane.close_all_items(&CloseAllItems, cx) + }) { + tasks.push(close_pane_items) + } } - Some(Task::ready(Ok(()))) + if tasks.is_empty() { + None + } else { + Some(cx.spawn(|_, _| async move { + for task in tasks { + task.await? + } + Ok(()) + })) + } } pub fn toggle_dock(&mut self, dock_side: DockPosition, cx: &mut ViewContext) { From 4735b07088269e5b99e9299dbb9dd620e70f4497 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 27 Jul 2023 18:00:33 -0700 Subject: [PATCH 23/52] Fix warning --- crates/workspace/src/workspace.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 827b0b8427c0bf4e0f25237d664489f747199592..a8ba017655a8a6546ed641e5714f2db1f5663cc5 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -21,7 +21,6 @@ use drag_and_drop::DragAndDrop; use futures::{ channel::{mpsc, oneshot}, future::try_join_all, - stream::FuturesUnordered, FutureExt, StreamExt, }; use gpui::{ From cf6e524c9a5f2fecbfbad9675e37cafd746c002c Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 28 Jul 2023 12:56:44 +0300 Subject: [PATCH 24/52] Make project search includes and excludes more user-friendly Allow search results that start with the include/exclude path part --- crates/project/src/project_tests.rs | 55 ++++---- crates/project/src/search.rs | 117 +++++++++++++++--- crates/search/src/project_search.rs | 84 ++++--------- crates/semantic_index/src/db.rs | 17 +-- crates/semantic_index/src/semantic_index.rs | 14 +-- .../src/semantic_index_tests.rs | 7 +- 6 files changed, 160 insertions(+), 134 deletions(-) diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs index 16e706a77eeb9b4a92a368d7bb653639d24e9814..259c10ca057c8bb29ad5b2d805107eb982239441 100644 --- a/crates/project/src/project_tests.rs +++ b/crates/project/src/project_tests.rs @@ -1,7 +1,6 @@ -use crate::{worktree::WorktreeHandle, Event, *}; +use crate::{search::PathMatcher, worktree::WorktreeHandle, Event, *}; use fs::{FakeFs, LineEnding, RealFs}; use futures::{future, StreamExt}; -use globset::Glob; use gpui::{executor::Deterministic, test::subscribe, AppContext}; use language::{ language_settings::{AllLanguageSettings, LanguageSettingsContent}, @@ -3641,7 +3640,7 @@ async fn test_search_with_inclusions(cx: &mut gpui::TestAppContext) { search_query, false, true, - vec![Glob::new("*.odd").unwrap().compile_matcher()], + vec![PathMatcher::new("*.odd").unwrap()], Vec::new() ), cx @@ -3659,7 +3658,7 @@ async fn test_search_with_inclusions(cx: &mut gpui::TestAppContext) { search_query, false, true, - vec![Glob::new("*.rs").unwrap().compile_matcher()], + vec![PathMatcher::new("*.rs").unwrap()], Vec::new() ), cx @@ -3681,8 +3680,8 @@ async fn test_search_with_inclusions(cx: &mut gpui::TestAppContext) { false, true, vec![ - Glob::new("*.ts").unwrap().compile_matcher(), - Glob::new("*.odd").unwrap().compile_matcher(), + PathMatcher::new("*.ts").unwrap(), + PathMatcher::new("*.odd").unwrap(), ], Vec::new() ), @@ -3705,9 +3704,9 @@ async fn test_search_with_inclusions(cx: &mut gpui::TestAppContext) { false, true, vec![ - Glob::new("*.rs").unwrap().compile_matcher(), - Glob::new("*.ts").unwrap().compile_matcher(), - Glob::new("*.odd").unwrap().compile_matcher(), + PathMatcher::new("*.rs").unwrap(), + PathMatcher::new("*.ts").unwrap(), + PathMatcher::new("*.odd").unwrap(), ], Vec::new() ), @@ -3752,7 +3751,7 @@ async fn test_search_with_exclusions(cx: &mut gpui::TestAppContext) { false, true, Vec::new(), - vec![Glob::new("*.odd").unwrap().compile_matcher()], + vec![PathMatcher::new("*.odd").unwrap()], ), cx ) @@ -3775,7 +3774,7 @@ async fn test_search_with_exclusions(cx: &mut gpui::TestAppContext) { false, true, Vec::new(), - vec![Glob::new("*.rs").unwrap().compile_matcher()], + vec![PathMatcher::new("*.rs").unwrap()], ), cx ) @@ -3797,8 +3796,8 @@ async fn test_search_with_exclusions(cx: &mut gpui::TestAppContext) { true, Vec::new(), vec![ - Glob::new("*.ts").unwrap().compile_matcher(), - Glob::new("*.odd").unwrap().compile_matcher(), + PathMatcher::new("*.ts").unwrap(), + PathMatcher::new("*.odd").unwrap(), ], ), cx @@ -3821,9 +3820,9 @@ async fn test_search_with_exclusions(cx: &mut gpui::TestAppContext) { true, Vec::new(), vec![ - Glob::new("*.rs").unwrap().compile_matcher(), - Glob::new("*.ts").unwrap().compile_matcher(), - Glob::new("*.odd").unwrap().compile_matcher(), + PathMatcher::new("*.rs").unwrap(), + PathMatcher::new("*.ts").unwrap(), + PathMatcher::new("*.odd").unwrap(), ], ), cx @@ -3860,8 +3859,8 @@ async fn test_search_with_exclusions_and_inclusions(cx: &mut gpui::TestAppContex search_query, false, true, - vec![Glob::new("*.odd").unwrap().compile_matcher()], - vec![Glob::new("*.odd").unwrap().compile_matcher()], + vec![PathMatcher::new("*.odd").unwrap()], + vec![PathMatcher::new("*.odd").unwrap()], ), cx ) @@ -3878,8 +3877,8 @@ async fn test_search_with_exclusions_and_inclusions(cx: &mut gpui::TestAppContex search_query, false, true, - vec![Glob::new("*.ts").unwrap().compile_matcher()], - vec![Glob::new("*.ts").unwrap().compile_matcher()], + vec![PathMatcher::new("*.ts").unwrap()], + vec![PathMatcher::new("*.ts").unwrap()], ), cx ) @@ -3897,12 +3896,12 @@ async fn test_search_with_exclusions_and_inclusions(cx: &mut gpui::TestAppContex false, true, vec![ - Glob::new("*.ts").unwrap().compile_matcher(), - Glob::new("*.odd").unwrap().compile_matcher() + PathMatcher::new("*.ts").unwrap(), + PathMatcher::new("*.odd").unwrap() ], vec![ - Glob::new("*.ts").unwrap().compile_matcher(), - Glob::new("*.odd").unwrap().compile_matcher() + PathMatcher::new("*.ts").unwrap(), + PathMatcher::new("*.odd").unwrap() ], ), cx @@ -3921,12 +3920,12 @@ async fn test_search_with_exclusions_and_inclusions(cx: &mut gpui::TestAppContex false, true, vec![ - Glob::new("*.ts").unwrap().compile_matcher(), - Glob::new("*.odd").unwrap().compile_matcher() + PathMatcher::new("*.ts").unwrap(), + PathMatcher::new("*.odd").unwrap() ], vec![ - Glob::new("*.rs").unwrap().compile_matcher(), - Glob::new("*.odd").unwrap().compile_matcher() + PathMatcher::new("*.rs").unwrap(), + PathMatcher::new("*.odd").unwrap() ], ), cx diff --git a/crates/project/src/search.rs b/crates/project/src/search.rs index 4b4126fef2e1f8f4cb403c809ca62a136cff5afb..71a0b70b81b7a6f08a2584064a55a07743096b2c 100644 --- a/crates/project/src/search.rs +++ b/crates/project/src/search.rs @@ -1,5 +1,5 @@ use aho_corasick::{AhoCorasick, AhoCorasickBuilder}; -use anyhow::Result; +use anyhow::{Context, Result}; use client::proto; use globset::{Glob, GlobMatcher}; use itertools::Itertools; @@ -9,7 +9,7 @@ use smol::future::yield_now; use std::{ io::{BufRead, BufReader, Read}, ops::Range, - path::Path, + path::{Path, PathBuf}, sync::Arc, }; @@ -20,8 +20,8 @@ pub enum SearchQuery { query: Arc, whole_word: bool, case_sensitive: bool, - files_to_include: Vec, - files_to_exclude: Vec, + files_to_include: Vec, + files_to_exclude: Vec, }, Regex { regex: Regex, @@ -29,18 +29,43 @@ pub enum SearchQuery { multiline: bool, whole_word: bool, case_sensitive: bool, - files_to_include: Vec, - files_to_exclude: Vec, + files_to_include: Vec, + files_to_exclude: Vec, }, } +#[derive(Clone, Debug)] +pub struct PathMatcher { + maybe_path: PathBuf, + glob: GlobMatcher, +} + +impl std::fmt::Display for PathMatcher { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.maybe_path.to_string_lossy().fmt(f) + } +} + +impl PathMatcher { + pub fn new(maybe_glob: &str) -> Result { + Ok(PathMatcher { + glob: Glob::new(&maybe_glob)?.compile_matcher(), + maybe_path: PathBuf::from(maybe_glob), + }) + } + + pub fn is_match>(&self, other: P) -> bool { + other.as_ref().starts_with(&self.maybe_path) || self.glob.is_match(other) + } +} + impl SearchQuery { pub fn text( query: impl ToString, whole_word: bool, case_sensitive: bool, - files_to_include: Vec, - files_to_exclude: Vec, + files_to_include: Vec, + files_to_exclude: Vec, ) -> Self { let query = query.to_string(); let search = AhoCorasickBuilder::new() @@ -61,8 +86,8 @@ impl SearchQuery { query: impl ToString, whole_word: bool, case_sensitive: bool, - files_to_include: Vec, - files_to_exclude: Vec, + files_to_include: Vec, + files_to_exclude: Vec, ) -> Result { let mut query = query.to_string(); let initial_query = Arc::from(query.as_str()); @@ -96,16 +121,16 @@ impl SearchQuery { message.query, message.whole_word, message.case_sensitive, - deserialize_globs(&message.files_to_include)?, - deserialize_globs(&message.files_to_exclude)?, + deserialize_path_matches(&message.files_to_include)?, + deserialize_path_matches(&message.files_to_exclude)?, ) } else { Ok(Self::text( message.query, message.whole_word, message.case_sensitive, - deserialize_globs(&message.files_to_include)?, - deserialize_globs(&message.files_to_exclude)?, + deserialize_path_matches(&message.files_to_include)?, + deserialize_path_matches(&message.files_to_exclude)?, )) } } @@ -120,12 +145,12 @@ impl SearchQuery { files_to_include: self .files_to_include() .iter() - .map(|g| g.glob().to_string()) + .map(|matcher| matcher.to_string()) .join(","), files_to_exclude: self .files_to_exclude() .iter() - .map(|g| g.glob().to_string()) + .map(|matcher| matcher.to_string()) .join(","), } } @@ -266,7 +291,7 @@ impl SearchQuery { matches!(self, Self::Regex { .. }) } - pub fn files_to_include(&self) -> &[GlobMatcher] { + pub fn files_to_include(&self) -> &[PathMatcher] { match self { Self::Text { files_to_include, .. @@ -277,7 +302,7 @@ impl SearchQuery { } } - pub fn files_to_exclude(&self) -> &[GlobMatcher] { + pub fn files_to_exclude(&self) -> &[PathMatcher] { match self { Self::Text { files_to_exclude, .. @@ -306,11 +331,63 @@ impl SearchQuery { } } -fn deserialize_globs(glob_set: &str) -> Result> { +fn deserialize_path_matches(glob_set: &str) -> anyhow::Result> { glob_set .split(',') .map(str::trim) .filter(|glob_str| !glob_str.is_empty()) - .map(|glob_str| Ok(Glob::new(glob_str)?.compile_matcher())) + .map(|glob_str| { + PathMatcher::new(glob_str) + .with_context(|| format!("deserializing path match glob {glob_str}")) + }) .collect() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn path_matcher_creation_for_valid_paths() { + for valid_path in [ + "file", + "Cargo.toml", + ".DS_Store", + "~/dir/another_dir/", + "./dir/file", + "dir/[a-z].txt", + "../dir/filé", + ] { + let path_matcher = PathMatcher::new(valid_path).unwrap_or_else(|e| { + panic!("Valid path {valid_path} should be accepted, but got: {e}") + }); + assert!( + path_matcher.is_match(valid_path), + "Path matcher for valid path {valid_path} should match itself" + ) + } + } + + #[test] + fn path_matcher_creation_for_globs() { + for invalid_glob in ["dir/[].txt", "dir/[a-z.txt", "dir/{file"] { + match PathMatcher::new(invalid_glob) { + Ok(_) => panic!("Invalid glob {invalid_glob} should not be accepted"), + Err(_expected) => {} + } + } + + for valid_glob in [ + "dir/?ile", + "dir/*.txt", + "dir/**/file", + "dir/[a-z].txt", + "{dir,file}", + ] { + match PathMatcher::new(valid_glob) { + Ok(_expected) => {} + Err(e) => panic!("Valid glob {valid_glob} should be accepted, but got: {e}"), + } + } + } +} diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 52ee12c26de17274d5cd8c5d39a69843cbcb7869..d6d69e575fdfa01a77c92b62efacfa45c31de23d 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -2,14 +2,13 @@ use crate::{ SearchOptions, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, ToggleWholeWord, }; -use anyhow::Result; +use anyhow::Context; use collections::HashMap; use editor::{ items::active_match_index, scroll::autoscroll::Autoscroll, Anchor, Editor, MultiBuffer, SelectAll, MAX_TAB_TITLE_LEN, }; use futures::StreamExt; -use globset::{Glob, GlobMatcher}; use gpui::{ actions, elements::*, @@ -19,7 +18,10 @@ use gpui::{ }; use menu::Confirm; use postage::stream::Stream; -use project::{search::SearchQuery, Entry, Project}; +use project::{ + search::{PathMatcher, SearchQuery}, + Entry, Project, +}; use semantic_index::SemanticIndex; use smallvec::SmallVec; use std::{ @@ -185,21 +187,15 @@ impl ProjectSearch { cx.notify(); } - fn semantic_search( - &mut self, - query: String, - include_files: Vec, - exclude_files: Vec, - cx: &mut ModelContext, - ) { + fn semantic_search(&mut self, query: SearchQuery, cx: &mut ModelContext) { let search = SemanticIndex::global(cx).map(|index| { index.update(cx, |semantic_index, cx| { semantic_index.search_project( self.project.clone(), - query.clone(), + query.as_str().to_owned(), 10, - include_files, - exclude_files, + query.files_to_include().to_vec(), + query.files_to_exclude().to_vec(), cx, ) }) @@ -590,8 +586,7 @@ impl ProjectSearchView { if !dir_entry.is_dir() { return; } - let filter_path = dir_entry.path.join("**"); - let Some(filter_str) = filter_path.to_str() else { return; }; + let Some(filter_str) = dir_entry.path.to_str() else { return; }; let model = cx.add_model(|cx| ProjectSearch::new(workspace.project().clone(), cx)); let search = cx.add_view(|cx| ProjectSearchView::new(model, cx)); @@ -662,16 +657,10 @@ impl ProjectSearchView { if semantic.outstanding_file_count > 0 { return; } - - let query = self.query_editor.read(cx).text(cx); - if let Some((included_files, exclude_files)) = - self.get_included_and_excluded_globsets(cx) - { - self.model.update(cx, |model, cx| { - model.semantic_search(query, included_files, exclude_files, cx) - }); + if let Some(query) = self.build_search_query(cx) { + self.model + .update(cx, |model, cx| model.semantic_search(query, cx)); } - return; } if let Some(query) = self.build_search_query(cx) { @@ -679,42 +668,10 @@ impl ProjectSearchView { } } - fn get_included_and_excluded_globsets( - &mut self, - cx: &mut ViewContext, - ) -> Option<(Vec, Vec)> { - let included_files = - match Self::load_glob_set(&self.included_files_editor.read(cx).text(cx)) { - Ok(included_files) => { - self.panels_with_errors.remove(&InputPanel::Include); - included_files - } - Err(_e) => { - self.panels_with_errors.insert(InputPanel::Include); - cx.notify(); - return None; - } - }; - let excluded_files = - match Self::load_glob_set(&self.excluded_files_editor.read(cx).text(cx)) { - Ok(excluded_files) => { - self.panels_with_errors.remove(&InputPanel::Exclude); - excluded_files - } - Err(_e) => { - self.panels_with_errors.insert(InputPanel::Exclude); - cx.notify(); - return None; - } - }; - - Some((included_files, excluded_files)) - } - fn build_search_query(&mut self, cx: &mut ViewContext) -> Option { let text = self.query_editor.read(cx).text(cx); let included_files = - match Self::load_glob_set(&self.included_files_editor.read(cx).text(cx)) { + match Self::parse_path_matches(&self.included_files_editor.read(cx).text(cx)) { Ok(included_files) => { self.panels_with_errors.remove(&InputPanel::Include); included_files @@ -726,7 +683,7 @@ impl ProjectSearchView { } }; let excluded_files = - match Self::load_glob_set(&self.excluded_files_editor.read(cx).text(cx)) { + match Self::parse_path_matches(&self.excluded_files_editor.read(cx).text(cx)) { Ok(excluded_files) => { self.panels_with_errors.remove(&InputPanel::Exclude); excluded_files @@ -766,11 +723,14 @@ impl ProjectSearchView { } } - fn load_glob_set(text: &str) -> Result> { + fn parse_path_matches(text: &str) -> anyhow::Result> { text.split(',') .map(str::trim) - .filter(|glob_str| !glob_str.is_empty()) - .map(|glob_str| anyhow::Ok(Glob::new(glob_str)?.compile_matcher())) + .filter(|maybe_glob_str| !maybe_glob_str.is_empty()) + .map(|maybe_glob_str| { + PathMatcher::new(maybe_glob_str) + .with_context(|| format!("parsing {maybe_glob_str} as path matcher")) + }) .collect() } @@ -1769,7 +1729,7 @@ pub mod tests { search_view.included_files_editor.update(cx, |editor, cx| { assert_eq!( editor.display_text(cx), - a_dir_entry.path.join("**").display().to_string(), + a_dir_entry.path.to_str().unwrap(), "New search in directory should have included dir entry path" ); }); diff --git a/crates/semantic_index/src/db.rs b/crates/semantic_index/src/db.rs index d180f5e8314291593b1b343cd96527b1aea1d838..e8c929c99500c6a1da445b36d49ec007b4a6d997 100644 --- a/crates/semantic_index/src/db.rs +++ b/crates/semantic_index/src/db.rs @@ -1,7 +1,6 @@ use crate::{parsing::Document, SEMANTIC_INDEX_VERSION}; use anyhow::{anyhow, Context, Result}; -use globset::GlobMatcher; -use project::Fs; +use project::{search::PathMatcher, Fs}; use rpc::proto::Timestamp; use rusqlite::{ params, @@ -290,8 +289,8 @@ impl VectorDatabase { pub fn retrieve_included_file_ids( &self, worktree_ids: &[i64], - include_globs: Vec, - exclude_globs: Vec, + includes: &[PathMatcher], + excludes: &[PathMatcher], ) -> Result> { let mut file_query = self.db.prepare( " @@ -310,13 +309,9 @@ impl VectorDatabase { while let Some(row) = rows.next()? { let file_id = row.get(0)?; let relative_path = row.get_ref(1)?.as_str()?; - let included = include_globs.is_empty() - || include_globs - .iter() - .any(|glob| glob.is_match(relative_path)); - let excluded = exclude_globs - .iter() - .any(|glob| glob.is_match(relative_path)); + let included = + includes.is_empty() || includes.iter().any(|glob| glob.is_match(relative_path)); + let excluded = excludes.iter().any(|glob| glob.is_match(relative_path)); if included && !excluded { file_ids.push(file_id); } diff --git a/crates/semantic_index/src/semantic_index.rs b/crates/semantic_index/src/semantic_index.rs index bd114de216a0a30b3271b56c2b627439a7e70a0e..f1450eb7b0200d2f2dbedca9f46acb7db2a615a3 100644 --- a/crates/semantic_index/src/semantic_index.rs +++ b/crates/semantic_index/src/semantic_index.rs @@ -11,13 +11,12 @@ use anyhow::{anyhow, Result}; use db::VectorDatabase; use embedding::{EmbeddingProvider, OpenAIEmbeddings}; use futures::{channel::oneshot, Future}; -use globset::GlobMatcher; use gpui::{AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, Task, WeakModelHandle}; use language::{Anchor, Buffer, Language, LanguageRegistry}; use parking_lot::Mutex; use parsing::{CodeContextRetriever, Document, PARSEABLE_ENTIRE_FILE_TYPES}; use postage::watch; -use project::{Fs, Project, WorktreeId}; +use project::{search::PathMatcher, Fs, Project, WorktreeId}; use smol::channel; use std::{ cmp::Ordering, @@ -682,8 +681,8 @@ impl SemanticIndex { project: ModelHandle, phrase: String, limit: usize, - include_globs: Vec, - exclude_globs: Vec, + includes: Vec, + excludes: Vec, cx: &mut ModelContext, ) -> Task>> { let project_state = if let Some(state) = self.projects.get(&project.downgrade()) { @@ -714,11 +713,8 @@ impl SemanticIndex { .next() .unwrap(); - let file_ids = database.retrieve_included_file_ids( - &worktree_db_ids, - include_globs, - exclude_globs, - )?; + let file_ids = + database.retrieve_included_file_ids(&worktree_db_ids, &includes, &excludes)?; let batch_n = cx.background().num_cpus(); let ids_len = file_ids.clone().len(); diff --git a/crates/semantic_index/src/semantic_index_tests.rs b/crates/semantic_index/src/semantic_index_tests.rs index acf5a9d72b43a1123102e105da2b4b039fba87c6..6acb25d98a911a061a9b4e8e2f6a387fc73204cc 100644 --- a/crates/semantic_index/src/semantic_index_tests.rs +++ b/crates/semantic_index/src/semantic_index_tests.rs @@ -7,11 +7,10 @@ use crate::{ }; use anyhow::Result; use async_trait::async_trait; -use globset::Glob; use gpui::{Task, TestAppContext}; use language::{Language, LanguageConfig, LanguageRegistry, ToOffset}; use pretty_assertions::assert_eq; -use project::{project_settings::ProjectSettings, FakeFs, Fs, Project}; +use project::{project_settings::ProjectSettings, search::PathMatcher, FakeFs, Fs, Project}; use rand::{rngs::StdRng, Rng}; use serde_json::json; use settings::SettingsStore; @@ -121,8 +120,8 @@ async fn test_semantic_index(cx: &mut TestAppContext) { ); // Test Include Files Functonality - let include_files = vec![Glob::new("*.rs").unwrap().compile_matcher()]; - let exclude_files = vec![Glob::new("*.rs").unwrap().compile_matcher()]; + let include_files = vec![PathMatcher::new("*.rs").unwrap()]; + let exclude_files = vec![PathMatcher::new("*.rs").unwrap()]; let rust_only_search_results = store .update(cx, |store, cx| { store.search_project( From fac0e2dd56bfa44dbeea1baf814d2fad23e08c63 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 28 Jul 2023 12:10:04 -0600 Subject: [PATCH 25/52] Don't highlight project search matches either --- crates/editor/src/editor.rs | 2 +- crates/search/src/project_search.rs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index e05837740d4c50fbe7e02e51272bd6340884ec8a..5404610b1da4213d217c6e5f8f77d4261941ef0e 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1537,7 +1537,7 @@ impl Editor { self.collapse_matches = collapse_matches; } - fn range_for_match(&self, range: &Range) -> Range { + pub fn range_for_match(&self, range: &Range) -> Range { if self.collapse_matches { return range.start..range.start; } diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 9054d9e1213dcc0544af0faeb35eb8bd74a3f117..ade60a6d348d8522517ac601588a04b5ecac5b6b 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -654,6 +654,7 @@ impl ProjectSearchView { let range_to_select = match_ranges[new_index].clone(); self.results_editor.update(cx, |editor, cx| { + let range_to_select = editor.range_for_match(&range_to_select); editor.unfold_ranges([range_to_select.clone()], false, true, cx); editor.change_selections(Some(Autoscroll::fit()), cx, |s| { s.select_ranges([range_to_select]) @@ -695,8 +696,12 @@ impl ProjectSearchView { let is_new_search = self.search_id != prev_search_id; self.results_editor.update(cx, |editor, cx| { if is_new_search { + let range_to_select = match_ranges + .first() + .clone() + .map(|range| editor.range_for_match(range)); editor.change_selections(Some(Autoscroll::fit()), cx, |s| { - s.select_ranges(match_ranges.first().cloned()) + s.select_ranges(range_to_select) }); } editor.highlight_background::( From b8690ec1d1df2e5f3d7a018070be0180dfa3257e Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 28 Jul 2023 15:12:37 -0400 Subject: [PATCH 26/52] Update release action to choose between preview and stable URL in Discord announcements This is what ChatGPT told me, so we'll see. --- .github/workflows/release_actions.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release_actions.yml b/.github/workflows/release_actions.yml index 6c3b3d57c0b49453c66597b133b2893e898f398e..f767324e4f6e2bc2edc825af512bbb5561ac6b62 100644 --- a/.github/workflows/release_actions.yml +++ b/.github/workflows/release_actions.yml @@ -6,6 +6,16 @@ jobs: discord_release: runs-on: ubuntu-latest steps: + - name: Get appropriate URL + id: get-appropriate-url + run: | + if [ "${{ github.event.release.prerelease }}" == "true" ]; then + URL="https://zed.dev/releases/preview/latest" + else + URL="https://zed.dev/releases/stable/latest" + fi + echo "::set-output name=URL::$URL" + - name: Discord Webhook Action uses: tsickert/discord-webhook@v5.3.0 with: @@ -13,6 +23,6 @@ jobs: content: | 📣 Zed ${{ github.event.release.tag_name }} was just released! - Restart your Zed or head to https://zed.dev/releases/stable/latest to grab it. + Restart your Zed or head to ${{ steps.get-appropriate-url.outputs.URL }} to grab it. ${{ github.event.release.body }} From 46101bf1103721088f16da845dae3a79bf30e856 Mon Sep 17 00:00:00 2001 From: Julia Date: Fri, 28 Jul 2023 15:24:40 -0400 Subject: [PATCH 27/52] Reattempt Node installation if the installation itself errors This also makes us a bit more aggressive about reinstalling Node --- crates/copilot/src/copilot.rs | 4 +-- crates/node_runtime/src/node_runtime.rs | 44 ++++++------------------- crates/zed/src/main.rs | 2 +- crates/zed/src/zed.rs | 2 +- 4 files changed, 14 insertions(+), 38 deletions(-) diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index ce4938ed0d9e31c8130625b526095aeb0283e12c..ab2d861190ff98fb7b4da954a7b92bfb43d75a9d 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -338,9 +338,9 @@ impl Copilot { let (server, fake_server) = LanguageServer::fake("copilot".into(), Default::default(), cx.to_async()); let http = util::http::FakeHttpClient::create(|_| async { unreachable!() }); - let this = cx.add_model(|cx| Self { + let this = cx.add_model(|_| Self { http: http.clone(), - node_runtime: NodeRuntime::instance(http, cx.background().clone()), + node_runtime: NodeRuntime::instance(http), server: CopilotServer::Running(RunningCopilotServer { lsp: Arc::new(server), sign_in_status: SignInStatus::Authorized, diff --git a/crates/node_runtime/src/node_runtime.rs b/crates/node_runtime/src/node_runtime.rs index 94858df880e28eeaf44a4899e75395aea47cca6a..d43c14ec7b6e8bcfdc6452df67120efc086f103a 100644 --- a/crates/node_runtime/src/node_runtime.rs +++ b/crates/node_runtime/src/node_runtime.rs @@ -1,9 +1,6 @@ use anyhow::{anyhow, bail, Context, Result}; use async_compression::futures::bufread::GzipDecoder; use async_tar::Archive; -use futures::lock::Mutex; -use futures::{future::Shared, FutureExt}; -use gpui::{executor::Background, Task}; use serde::Deserialize; use smol::{fs, io::BufReader, process::Command}; use std::process::{Output, Stdio}; @@ -33,20 +30,12 @@ pub struct NpmInfoDistTags { pub struct NodeRuntime { http: Arc, - background: Arc, - installation_path: Mutex>>>>>, } impl NodeRuntime { - pub fn instance(http: Arc, background: Arc) -> Arc { + pub fn instance(http: Arc) -> Arc { RUNTIME_INSTANCE - .get_or_init(|| { - Arc::new(NodeRuntime { - http, - background, - installation_path: Mutex::new(None), - }) - }) + .get_or_init(|| Arc::new(NodeRuntime { http })) .clone() } @@ -61,7 +50,9 @@ impl NodeRuntime { subcommand: &str, args: &[&str], ) -> Result { - let attempt = |installation_path: PathBuf| async move { + let attempt = || async move { + let installation_path = self.install_if_needed().await?; + let mut env_path = installation_path.join("bin").into_os_string(); if let Some(existing_path) = std::env::var_os("PATH") { if !existing_path.is_empty() { @@ -92,10 +83,9 @@ impl NodeRuntime { command.output().await.map_err(|e| anyhow!("{e}")) }; - let installation_path = self.install_if_needed().await?; - let mut output = attempt(installation_path.clone()).await; + let mut output = attempt().await; if output.is_err() { - output = attempt(installation_path).await; + output = attempt().await; if output.is_err() { return Err(anyhow!( "failed to launch npm subcommand {subcommand} subcommand" @@ -167,23 +157,8 @@ impl NodeRuntime { } async fn install_if_needed(&self) -> Result { - let task = self - .installation_path - .lock() - .await - .get_or_insert_with(|| { - let http = self.http.clone(); - self.background - .spawn(async move { Self::install(http).await.map_err(Arc::new) }) - .shared() - }) - .clone(); - - task.await.map_err(|e| anyhow!("{}", e)) - } + log::info!("Node runtime install_if_needed"); - async fn install(http: Arc) -> Result { - log::info!("installing Node runtime"); let arch = match consts::ARCH { "x86_64" => "x64", "aarch64" => "arm64", @@ -214,7 +189,8 @@ impl NodeRuntime { let file_name = format!("node-{VERSION}-darwin-{arch}.tar.gz"); let url = format!("https://nodejs.org/dist/{VERSION}/{file_name}"); - let mut response = http + let mut response = self + .http .get(&url, Default::default(), true) .await .context("error downloading Node binary tarball")?; diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index b9fefb89a73555a16a03d9d7e34fa5369d3abde4..e44ab3e33acbb213f69b230a80075aea07890c85 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -136,7 +136,7 @@ fn main() { languages.set_executor(cx.background().clone()); languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone()); let languages = Arc::new(languages); - let node_runtime = NodeRuntime::instance(http.clone(), cx.background().to_owned()); + let node_runtime = NodeRuntime::instance(http.clone()); languages::init(languages.clone(), node_runtime.clone()); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx)); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index a29567ac385633af04b7e7c3f4b2c0de595d892c..4b0bf1cd4c6aec42aa2d636b474828ef452cbe03 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -2364,7 +2364,7 @@ mod tests { languages.set_executor(cx.background().clone()); let languages = Arc::new(languages); let http = FakeHttpClient::with_404_response(); - let node_runtime = NodeRuntime::instance(http, cx.background().to_owned()); + let node_runtime = NodeRuntime::instance(http); languages::init(languages.clone(), node_runtime); for name in languages.language_names() { languages.language_for_name(&name); From d3b89e16f26d24965267637000e642382cb4b675 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 28 Jul 2023 14:56:13 -0700 Subject: [PATCH 28/52] Make wrap guides respect scroll position --- crates/editor/src/element.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index b9bf74ee85f8bbc3c338a75b4cd1bf39bc0a53cb..cb46e74af0b1e8d1480dedba1ae51db417fbf5b6 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -546,8 +546,18 @@ impl EditorElement { }); } + let scroll_left = + layout.position_map.snapshot.scroll_position().x() * layout.position_map.em_width; + for (wrap_position, active) in layout.wrap_guides.iter() { - let x = text_bounds.origin_x() + wrap_position + layout.position_map.em_width / 2.; + let x = + (text_bounds.origin_x() + wrap_position + layout.position_map.em_width / 2.) + - scroll_left; + + if x < text_bounds.origin_x() { + continue; + } + let color = if *active { self.style.active_wrap_guide } else { From fe43bacb6fa9a22d57d174df92a05a8cb6739e9d Mon Sep 17 00:00:00 2001 From: Julia Date: Fri, 28 Jul 2023 18:53:24 -0400 Subject: [PATCH 29/52] Put LiveKitBridge Swift build directory in `target` Helps it get caught in a cargo clean --- crates/live_kit_client/build.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/live_kit_client/build.rs b/crates/live_kit_client/build.rs index bcd3f76dca99d5cf22ee01ebe1e1d51cc13e103f..3fa0e003e744b656139958acea89a7b107c68579 100644 --- a/crates/live_kit_client/build.rs +++ b/crates/live_kit_client/build.rs @@ -58,11 +58,14 @@ fn build_bridge(swift_target: &SwiftTarget) { "cargo:rerun-if-changed={}/Package.resolved", SWIFT_PACKAGE_NAME ); + let swift_package_root = swift_package_root(); + let swift_target_folder = swift_target_folder(); if !Command::new("swift") .arg("build") .args(["--configuration", &env::var("PROFILE").unwrap()]) .args(["--triple", &swift_target.target.triple]) + .args(["--build-path".into(), swift_target_folder]) .current_dir(&swift_package_root) .status() .unwrap() @@ -128,6 +131,12 @@ fn swift_package_root() -> PathBuf { env::current_dir().unwrap().join(SWIFT_PACKAGE_NAME) } +fn swift_target_folder() -> PathBuf { + env::current_dir() + .unwrap() + .join(format!("../../target/{SWIFT_PACKAGE_NAME}")) +} + fn copy_dir(source: &Path, destination: &Path) { assert!( Command::new("rm") @@ -155,8 +164,7 @@ fn copy_dir(source: &Path, destination: &Path) { impl SwiftTarget { fn out_dir_path(&self) -> PathBuf { - swift_package_root() - .join(".build") + swift_target_folder() .join(&self.target.unversioned_triple) .join(env::var("PROFILE").unwrap()) } From 2c47efcce91328ee8d567f2871fae1e3cd107b63 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 28 Jul 2023 22:36:15 -0400 Subject: [PATCH 30/52] Add a command to collapse all entires --- crates/project_panel/src/project_panel.rs | 76 +++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index e6e1cff5981cf7450c154cd7173ab195c5190751..b650d272fbdb7cbb05b477e5033e1f127be8d07b 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -115,6 +115,7 @@ actions!( [ ExpandSelectedEntry, CollapseSelectedEntry, + CollapseAllEntries, NewDirectory, NewFile, Copy, @@ -140,6 +141,7 @@ pub fn init(assets: impl AssetSource, cx: &mut AppContext) { file_associations::init(assets, cx); cx.add_action(ProjectPanel::expand_selected_entry); cx.add_action(ProjectPanel::collapse_selected_entry); + cx.add_action(ProjectPanel::collapse_all_entries); cx.add_action(ProjectPanel::select_prev); cx.add_action(ProjectPanel::select_next); cx.add_action(ProjectPanel::new_file); @@ -514,6 +516,12 @@ impl ProjectPanel { } } + pub fn collapse_all_entries(&mut self, _: &CollapseAllEntries, cx: &mut ViewContext) { + self.expanded_dir_ids.clear(); + self.update_visible_entries(None, cx); + cx.notify(); + } + fn toggle_expanded(&mut self, entry_id: ProjectEntryId, cx: &mut ViewContext) { if let Some(worktree_id) = self.project.read(cx).worktree_id_for_entry(entry_id, cx) { if let Some(expanded_dir_ids) = self.expanded_dir_ids.get_mut(&worktree_id) { @@ -2678,6 +2686,73 @@ mod tests { ); } + #[gpui::test] + async fn test_collapse_all_entries(cx: &mut gpui::TestAppContext) { + init_test_with_editor(cx); + + let fs = FakeFs::new(cx.background()); + fs.insert_tree( + "/project_root", + json!({ + "dir_1": { + "nested_dir": { + "file_a.py": "# File contents", + "file_b.py": "# File contents", + "file_c.py": "# File contents", + }, + "file_1.py": "# File contents", + "file_2.py": "# File contents", + "file_3.py": "# File contents", + }, + "dir_2": { + "file_1.py": "# File contents", + "file_2.py": "# File contents", + "file_3.py": "# File contents", + } + }), + ) + .await; + + let project = Project::test(fs.clone(), ["/project_root".as_ref()], cx).await; + let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); + let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx)); + + let new_search_events_count = Arc::new(AtomicUsize::new(0)); + let _subscription = panel.update(cx, |_, cx| { + let subcription_count = Arc::clone(&new_search_events_count); + cx.subscribe(&cx.handle(), move |_, _, event, _| { + if matches!(event, Event::NewSearchInDirectory { .. }) { + subcription_count.fetch_add(1, atomic::Ordering::SeqCst); + } + }) + }); + + panel.update(cx, |panel, cx| { + panel.collapse_all_entries(&CollapseAllEntries, cx) + }); + cx.foreground().run_until_parked(); + assert_eq!( + visible_entries_as_strings(&panel, 0..10, cx), + &["v project_root", " > dir_1", " > dir_2",] + ); + + // Open dir_1 and make sure nested_dir was collapsed during + toggle_expand_dir(&panel, "project_root/dir_1", cx); + cx.foreground().run_until_parked(); + assert_eq!( + visible_entries_as_strings(&panel, 0..10, cx), + &[ + "v project_root", + " v dir_1 <== selected", + " > nested_dir", + " file_1.py", + " file_2.py", + " file_3.py", + " > dir_2", + ] + ); + } + fn toggle_expand_dir( panel: &ViewHandle, path: impl AsRef, @@ -2878,3 +2953,4 @@ mod tests { }); } } +// TODO - a workspace command? From b0e81c58dc9d85a93153563b1c71753c425c4247 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 28 Jul 2023 23:06:40 -0400 Subject: [PATCH 31/52] Remove unused code in test --- crates/project_panel/src/project_panel.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index b650d272fbdb7cbb05b477e5033e1f127be8d07b..b2b8b2e4bd721fa225db6b8d6f902cb0e0b560d6 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -2717,16 +2717,6 @@ mod tests { let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); let panel = workspace.update(cx, |workspace, cx| ProjectPanel::new(workspace, cx)); - let new_search_events_count = Arc::new(AtomicUsize::new(0)); - let _subscription = panel.update(cx, |_, cx| { - let subcription_count = Arc::clone(&new_search_events_count); - cx.subscribe(&cx.handle(), move |_, _, event, _| { - if matches!(event, Event::NewSearchInDirectory { .. }) { - subcription_count.fetch_add(1, atomic::Ordering::SeqCst); - } - }) - }); - panel.update(cx, |panel, cx| { panel.collapse_all_entries(&CollapseAllEntries, cx) }); From 0bd6e7bac3179b49f69125b573c78dce438f286a Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 28 Jul 2023 23:13:36 -0400 Subject: [PATCH 32/52] Fix comment --- crates/project_panel/src/project_panel.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index b2b8b2e4bd721fa225db6b8d6f902cb0e0b560d6..0be52646e631ef1446f168dc3ecf1ce7b9ef0075 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -2726,7 +2726,7 @@ mod tests { &["v project_root", " > dir_1", " > dir_2",] ); - // Open dir_1 and make sure nested_dir was collapsed during + // Open dir_1 and make sure nested_dir was collapsed when running collapse_all_entries toggle_expand_dir(&panel, "project_root/dir_1", cx); cx.foreground().run_until_parked(); assert_eq!( From d58f031696ce039c0068344803551558c391d85c Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 28 Jul 2023 22:27:36 -0700 Subject: [PATCH 33/52] disable wrap guides in the assitant panel --- crates/ai/src/assistant.rs | 1 + crates/editor/src/editor.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/crates/ai/src/assistant.rs b/crates/ai/src/assistant.rs index 8a4c04d3387784e0e2b5e4e7d745c690f72c02aa..957c5e1c063aad3de12657448267d0f813f38887 100644 --- a/crates/ai/src/assistant.rs +++ b/crates/ai/src/assistant.rs @@ -1637,6 +1637,7 @@ impl ConversationEditor { let mut editor = Editor::for_buffer(conversation.read(cx).buffer.clone(), None, cx); editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); editor.set_show_gutter(false, cx); + editor.set_show_wrap_guides(false, cx); editor }); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b4145edb6483dd0d8c25d0f645cdcef1927ed374..5270d6f951870fa952e9a0a33f2f229a1d71ff98 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -543,6 +543,7 @@ pub struct Editor { show_local_selections: bool, mode: EditorMode, show_gutter: bool, + show_wrap_guides: Option, placeholder_text: Option>, highlighted_rows: Option>, #[allow(clippy::type_complexity)] @@ -1375,6 +1376,7 @@ impl Editor { show_local_selections: true, mode, show_gutter: mode == EditorMode::Full, + show_wrap_guides: None, placeholder_text: None, highlighted_rows: None, background_highlights: Default::default(), @@ -7187,6 +7189,10 @@ impl Editor { pub fn wrap_guides(&self, cx: &AppContext) -> SmallVec<[(usize, bool); 2]> { let mut wrap_guides = smallvec::smallvec![]; + if self.show_wrap_guides == Some(false) { + return wrap_guides; + } + let settings = self.buffer.read(cx).settings_at(0, cx); if settings.show_wrap_guides { if let SoftWrap::Column(soft_wrap) = self.soft_wrap_mode(cx) { @@ -7244,6 +7250,11 @@ impl Editor { cx.notify(); } + pub fn set_show_wrap_guides(&mut self, show_gutter: bool, cx: &mut ViewContext) { + self.show_wrap_guides = Some(show_gutter); + cx.notify(); + } + pub fn reveal_in_finder(&mut self, _: &RevealInFinder, cx: &mut ViewContext) { if let Some(buffer) = self.buffer().read(cx).as_singleton() { if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) { From 8926266952948063a666a248f2e4b7bf8edcfde6 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Sat, 29 Jul 2023 23:53:16 -0700 Subject: [PATCH 34/52] Halve opacity on wrap guides --- styles/src/style_tree/editor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/styles/src/style_tree/editor.ts b/styles/src/style_tree/editor.ts index 832e77626491ff94f183d5ce1fe195f5a55a3780..deab45d4b21df8b7d130479c277ed317ba78d8d4 100644 --- a/styles/src/style_tree/editor.ts +++ b/styles/src/style_tree/editor.ts @@ -182,8 +182,8 @@ export default function editor(): any { line_number: with_opacity(foreground(layer), 0.35), line_number_active: foreground(layer), rename_fade: 0.6, - wrap_guide: with_opacity(foreground(layer), 0.1), - active_wrap_guide: with_opacity(foreground(layer), 0.2), + wrap_guide: with_opacity(foreground(layer), 0.05), + active_wrap_guide: with_opacity(foreground(layer), 0.1), unnecessary_code_fade: 0.5, selection: theme.players[0], whitespace: theme.ramps.neutral(0.5).hex(), From a5dd8dd0a9c14e85bc95a8b84989366f5ff590fa Mon Sep 17 00:00:00 2001 From: KCaverly Date: Mon, 31 Jul 2023 10:02:28 -0400 Subject: [PATCH 35/52] add lua embedding query for semantic search --- Cargo.lock | 39 +++---- crates/semantic_index/Cargo.toml | 1 + .../src/semantic_index_tests.rs | 102 ++++++++++++++++++ crates/zed/src/languages/lua/config.toml | 1 + crates/zed/src/languages/lua/embedding.scm | 10 ++ 5 files changed, 134 insertions(+), 19 deletions(-) create mode 100644 crates/zed/src/languages/lua/embedding.scm diff --git a/Cargo.lock b/Cargo.lock index 7c6a213d0d4e36a427fc4352b2e417258f12de8f..6c558cbb090a557814cbcd662683e1a40561a463 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2042,9 +2042,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.64+curl-8.2.0" +version = "0.4.65+curl-8.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f96069f0b1cb1241c838740659a771ef143363f52772a9ce1bd9c04c75eee0dc" +checksum = "961ba061c9ef2fe34bbd12b807152d96f0badd2bebe7b90ce6c8c8b7572a0986" dependencies = [ "cc", "libc", @@ -3033,9 +3033,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1391ab1f92ffcc08911957149833e682aa3fe252b9f45f966d2ef972274c97df" +checksum = "aca8bbd8e0707c1887a8bbb7e6b40e228f251ff5d62c8220a4a7a53c73aff006" dependencies = [ "aho-corasick 1.0.2", "bstr", @@ -6688,6 +6688,7 @@ dependencies = [ "tree-sitter-cpp 0.20.2", "tree-sitter-elixir 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tree-sitter-json 0.19.0", + "tree-sitter-lua", "tree-sitter-rust", "tree-sitter-toml 0.20.0", "tree-sitter-typescript 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6722,18 +6723,18 @@ checksum = "5a9f47faea3cad316faa914d013d24f471cd90bfca1a0c70f05a3f42c6441e99" [[package]] name = "serde" -version = "1.0.175" +version = "1.0.177" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d25439cd7397d044e2748a6fe2432b5e85db703d6d097bd014b3c0ad1ebff0b" +checksum = "63ba2516aa6bf82e0b19ca8b50019d52df58455d3cf9bdaf6315225fdd0c560a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.175" +version = "1.0.177" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b23f7ade6f110613c0d63858ddb8b94c1041f550eab58a16b371bdf2c9c80ab4" +checksum = "401797fe7833d72109fedec6bfcbe67c0eed9b99772f26eb8afd261f0abc6fd3" dependencies = [ "proc-macro2", "quote", @@ -6762,9 +6763,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.103" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" +checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" dependencies = [ "indexmap 2.0.0", "itoa 1.0.9", @@ -6786,9 +6787,9 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e168eaaf71e8f9bd6037feb05190485708e019f4fd87d161b3c0a0d37daf85e5" +checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", @@ -9031,9 +9032,9 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasm-encoder" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06a3d1b4a575ffb873679402b2aedb3117555eb65c27b1b86c8a91e574bc2a2a" +checksum = "41763f20eafed1399fff1afb466496d3a959f58241436cfdc17e3f5ca954de16" dependencies = [ "leb128", ] @@ -9255,9 +9256,9 @@ dependencies = [ [[package]] name = "wast" -version = "62.0.0" +version = "62.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7f7ee878019d69436895f019b65f62c33da63595d8e857cbdc87c13ecb29a32" +checksum = "b8ae06f09dbe377b889fbd620ff8fa21e1d49d1d9d364983c0cdbf9870cb9f1f" dependencies = [ "leb128", "memchr", @@ -9267,11 +9268,11 @@ dependencies = [ [[package]] name = "wat" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "295572bf24aa5b685a971a83ad3e8b6e684aaad8a9be24bc7bf59bed84cc1c08" +checksum = "842e15861d203fb4a96d314b0751cdeaf0f6f8b35e8d81d2953af2af5e44e637" dependencies = [ - "wast 62.0.0", + "wast 62.0.1", ] [[package]] diff --git a/crates/semantic_index/Cargo.toml b/crates/semantic_index/Cargo.toml index a1f126bfb841ecb8334aeca391ac4959ef9f57b0..942f61d29883134895cf257bdbbeaded8a3677a4 100644 --- a/crates/semantic_index/Cargo.toml +++ b/crates/semantic_index/Cargo.toml @@ -60,3 +60,4 @@ tree-sitter-rust = "*" tree-sitter-toml = "*" tree-sitter-cpp = "*" tree-sitter-elixir = "*" +tree-sitter-lua = "*" diff --git a/crates/semantic_index/src/semantic_index_tests.rs b/crates/semantic_index/src/semantic_index_tests.rs index acf5a9d72b43a1123102e105da2b4b039fba87c6..4eedade69d9ed15c85a4e84a1e647b8510b71fd4 100644 --- a/crates/semantic_index/src/semantic_index_tests.rs +++ b/crates/semantic_index/src/semantic_index_tests.rs @@ -486,6 +486,79 @@ async fn test_code_context_retrieval_javascript() { ) } +#[gpui::test] +async fn test_code_context_retrieval_lua() { + let language = lua_lang(); + let mut retriever = CodeContextRetriever::new(); + + let text = r#" + -- Creates a new class + -- @param baseclass The Baseclass of this class, or nil. + -- @return A new class reference. + function classes.class(baseclass) + -- Create the class definition and metatable. + local classdef = {} + -- Find the super class, either Object or user-defined. + baseclass = baseclass or classes.Object + -- If this class definition does not know of a function, it will 'look up' to the Baseclass via the __index of the metatable. + setmetatable(classdef, { __index = baseclass }) + -- All class instances have a reference to the class object. + classdef.class = classdef + --- Recursivly allocates the inheritance tree of the instance. + -- @param mastertable The 'root' of the inheritance tree. + -- @return Returns the instance with the allocated inheritance tree. + function classdef.alloc(mastertable) + -- All class instances have a reference to a superclass object. + local instance = { super = baseclass.alloc(mastertable) } + -- Any functions this instance does not know of will 'look up' to the superclass definition. + setmetatable(instance, { __index = classdef, __newindex = mastertable }) + return instance + end + end + "#.unindent(); + + let documents = retriever.parse_file(&text, language.clone()).unwrap(); + + assert_documents_eq( + &documents, + &[ + (r#" + -- Creates a new class + -- @param baseclass The Baseclass of this class, or nil. + -- @return A new class reference. + function classes.class(baseclass) + -- Create the class definition and metatable. + local classdef = {} + -- Find the super class, either Object or user-defined. + baseclass = baseclass or classes.Object + -- If this class definition does not know of a function, it will 'look up' to the Baseclass via the __index of the metatable. + setmetatable(classdef, { __index = baseclass }) + -- All class instances have a reference to the class object. + classdef.class = classdef + --- Recursivly allocates the inheritance tree of the instance. + -- @param mastertable The 'root' of the inheritance tree. + -- @return Returns the instance with the allocated inheritance tree. + function classdef.alloc(mastertable) + --[ ... ]-- + --[ ... ]-- + end + end"#.unindent(), + 114), + (r#" + --- Recursivly allocates the inheritance tree of the instance. + -- @param mastertable The 'root' of the inheritance tree. + -- @return Returns the instance with the allocated inheritance tree. + function classdef.alloc(mastertable) + -- All class instances have a reference to a superclass object. + local instance = { super = baseclass.alloc(mastertable) } + -- Any functions this instance does not know of will 'look up' to the superclass definition. + setmetatable(instance, { __index = classdef, __newindex = mastertable }) + return instance + end"#.unindent(), 809), + ] + ); +} + #[gpui::test] async fn test_code_context_retrieval_elixir() { let language = elixir_lang(); @@ -1084,6 +1157,35 @@ fn cpp_lang() -> Arc { ) } +fn lua_lang() -> Arc { + Arc::new( + Language::new( + LanguageConfig { + name: "Lua".into(), + path_suffixes: vec!["lua".into()], + collapsed_placeholder: "--[ ... ]--".to_string(), + ..Default::default() + }, + Some(tree_sitter_lua::language()), + ) + .with_embedding_query( + r#" + ( + (comment)* @context + . + (function_declaration + "function" @name + name: (_) @name + (comment)* @collapse + body: (block) @collapse + ) @item + ) + "#, + ) + .unwrap(), + ) +} + fn elixir_lang() -> Arc { Arc::new( Language::new( diff --git a/crates/zed/src/languages/lua/config.toml b/crates/zed/src/languages/lua/config.toml index fe44a3d2aaa5b0c57d13f41d925193d478d714a9..d3e44edfe97b6aa07481d0bf0f0fffae072950b7 100644 --- a/crates/zed/src/languages/lua/config.toml +++ b/crates/zed/src/languages/lua/config.toml @@ -7,3 +7,4 @@ brackets = [ { start = "[", end = "]", close = true, newline = true }, { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, ] +collapsed_placeholder = "--[ ... ]--" diff --git a/crates/zed/src/languages/lua/embedding.scm b/crates/zed/src/languages/lua/embedding.scm new file mode 100644 index 0000000000000000000000000000000000000000..0d1065089fc0853c1e6fa874f4e511e1ef2c1422 --- /dev/null +++ b/crates/zed/src/languages/lua/embedding.scm @@ -0,0 +1,10 @@ +( + (comment)* @context + . + (function_declaration + "function" @name + name: (_) @name + (comment)* @collapse + body: (block) @collapse + ) @item +) From ca4e21881efc5d0293e545a1059971cab356bc54 Mon Sep 17 00:00:00 2001 From: KCaverly Date: Mon, 31 Jul 2023 10:54:30 -0400 Subject: [PATCH 36/52] add ruby support for semantic search --- Cargo.lock | 1 + crates/semantic_index/Cargo.toml | 1 + .../src/semantic_index_tests.rs | 231 ++++++++++++++++++ crates/zed/src/languages/ruby/config.toml | 1 + crates/zed/src/languages/ruby/embedding.scm | 22 ++ 5 files changed, 256 insertions(+) create mode 100644 crates/zed/src/languages/ruby/embedding.scm diff --git a/Cargo.lock b/Cargo.lock index 6c558cbb090a557814cbcd662683e1a40561a463..b4a8f13bea56d64f4d10084e726c22c312cdec92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6689,6 +6689,7 @@ dependencies = [ "tree-sitter-elixir 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tree-sitter-json 0.19.0", "tree-sitter-lua", + "tree-sitter-ruby", "tree-sitter-rust", "tree-sitter-toml 0.20.0", "tree-sitter-typescript 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/crates/semantic_index/Cargo.toml b/crates/semantic_index/Cargo.toml index 942f61d29883134895cf257bdbbeaded8a3677a4..637f3f4487443825ace9b98dbe73690ce02ec250 100644 --- a/crates/semantic_index/Cargo.toml +++ b/crates/semantic_index/Cargo.toml @@ -61,3 +61,4 @@ tree-sitter-toml = "*" tree-sitter-cpp = "*" tree-sitter-elixir = "*" tree-sitter-lua = "*" +tree-sitter-ruby = "*" diff --git a/crates/semantic_index/src/semantic_index_tests.rs b/crates/semantic_index/src/semantic_index_tests.rs index 4eedade69d9ed15c85a4e84a1e647b8510b71fd4..58d34649c7e953faf2ebf3bac5829e5474330f85 100644 --- a/crates/semantic_index/src/semantic_index_tests.rs +++ b/crates/semantic_index/src/semantic_index_tests.rs @@ -827,6 +827,196 @@ async fn test_code_context_retrieval_cpp() { ); } +#[gpui::test] +async fn test_code_context_retrieval_ruby() { + let language = ruby_lang(); + let mut retriever = CodeContextRetriever::new(); + + let text = r#" + # This concern is inspired by "sudo mode" on GitHub. It + # is a way to re-authenticate a user before allowing them + # to see or perform an action. + # + # Add `before_action :require_challenge!` to actions you + # want to protect. + # + # The user will be shown a page to enter the challenge (which + # is either the password, or just the username when no + # password exists). Upon passing, there is a grace period + # during which no challenge will be asked from the user. + # + # Accessing challenge-protected resources during the grace + # period will refresh the grace period. + module ChallengableConcern + extend ActiveSupport::Concern + + CHALLENGE_TIMEOUT = 1.hour.freeze + + def require_challenge! + return if skip_challenge? + + if challenge_passed_recently? + session[:challenge_passed_at] = Time.now.utc + return + end + + @challenge = Form::Challenge.new(return_to: request.url) + + if params.key?(:form_challenge) + if challenge_passed? + session[:challenge_passed_at] = Time.now.utc + else + flash.now[:alert] = I18n.t('challenge.invalid_password') + render_challenge + end + else + render_challenge + end + end + + def challenge_passed? + current_user.valid_password?(challenge_params[:current_password]) + end + end + + class Animal + include Comparable + + attr_reader :legs + + def initialize(name, legs) + @name, @legs = name, legs + end + + def <=>(other) + legs <=> other.legs + end + end + + # Singleton method for car object + def car.wheels + puts "There are four wheels" + end"# + .unindent(); + + let documents = retriever.parse_file(&text, language.clone()).unwrap(); + + assert_documents_eq( + &documents, + &[ + ( + r#" + # This concern is inspired by "sudo mode" on GitHub. It + # is a way to re-authenticate a user before allowing them + # to see or perform an action. + # + # Add `before_action :require_challenge!` to actions you + # want to protect. + # + # The user will be shown a page to enter the challenge (which + # is either the password, or just the username when no + # password exists). Upon passing, there is a grace period + # during which no challenge will be asked from the user. + # + # Accessing challenge-protected resources during the grace + # period will refresh the grace period. + module ChallengableConcern + extend ActiveSupport::Concern + + CHALLENGE_TIMEOUT = 1.hour.freeze + + def require_challenge! + # ... + end + + def challenge_passed? + # ... + end + end"# + .unindent(), + 558, + ), + ( + r#" + def require_challenge! + return if skip_challenge? + + if challenge_passed_recently? + session[:challenge_passed_at] = Time.now.utc + return + end + + @challenge = Form::Challenge.new(return_to: request.url) + + if params.key?(:form_challenge) + if challenge_passed? + session[:challenge_passed_at] = Time.now.utc + else + flash.now[:alert] = I18n.t('challenge.invalid_password') + render_challenge + end + else + render_challenge + end + end"# + .unindent(), + 663, + ), + ( + r#" + def challenge_passed? + current_user.valid_password?(challenge_params[:current_password]) + end"# + .unindent(), + 1254, + ), + ( + r#" + class Animal + include Comparable + + attr_reader :legs + + def initialize(name, legs) + # ... + end + + def <=>(other) + # ... + end + end"# + .unindent(), + 1363, + ), + ( + r#" + def initialize(name, legs) + @name, @legs = name, legs + end"# + .unindent(), + 1427, + ), + ( + r#" + def <=>(other) + legs <=> other.legs + end"# + .unindent(), + 1501, + ), + ( + r#" + # Singleton method for car object + def car.wheels + puts "There are four wheels" + end"# + .unindent(), + 1591, + ), + ], + ); +} + #[gpui::test] fn test_dot_product(mut rng: StdRng) { assert_eq!(dot(&[1., 0., 0., 0., 0.], &[0., 1., 0., 0., 0.]), 0.); @@ -1186,6 +1376,47 @@ fn lua_lang() -> Arc { ) } +fn ruby_lang() -> Arc { + Arc::new( + Language::new( + LanguageConfig { + name: "Ruby".into(), + path_suffixes: vec!["rb".into()], + collapsed_placeholder: "# ...".to_string(), + ..Default::default() + }, + Some(tree_sitter_ruby::language()), + ) + .with_embedding_query( + r#" + ( + (comment)* @context + . + [ + (module + "module" @name + name: (_) @name) + (method + "def" @name + name: (_) @name + body: (body_statement) @collapse) + (class + "class" @name + name: (_) @name) + (singleton_method + "def" @name + object: (_) @name + "." @name + name: (_) @name + body: (body_statement) @collapse) + ] @item + ) + "#, + ) + .unwrap(), + ) +} + fn elixir_lang() -> Arc { Arc::new( Language::new( diff --git a/crates/zed/src/languages/ruby/config.toml b/crates/zed/src/languages/ruby/config.toml index a0b26bff92048d0b0327f1bcbe4301f9964737c6..6c8c61501556c88dac13d890bd1ddcc758134cc8 100644 --- a/crates/zed/src/languages/ruby/config.toml +++ b/crates/zed/src/languages/ruby/config.toml @@ -10,3 +10,4 @@ brackets = [ { start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] }, { start = "'", end = "'", close = true, newline = false, not_in = ["comment", "string"] }, ] +collapsed_placeholder = "# ..." diff --git a/crates/zed/src/languages/ruby/embedding.scm b/crates/zed/src/languages/ruby/embedding.scm new file mode 100644 index 0000000000000000000000000000000000000000..7a101e6b0925383f09fcdd24a7d5c26bfaf85628 --- /dev/null +++ b/crates/zed/src/languages/ruby/embedding.scm @@ -0,0 +1,22 @@ +( + (comment)* @context + . + [ + (module + "module" @name + name: (_) @name) + (method + "def" @name + name: (_) @name + body: (body_statement) @collapse) + (class + "class" @name + name: (_) @name) + (singleton_method + "def" @name + object: (_) @name + "." @name + name: (_) @name + body: (body_statement) @collapse) + ] @item + ) From 89edb3d1b534b962f3e4e81c6055b6fd92fef868 Mon Sep 17 00:00:00 2001 From: KCaverly Date: Mon, 31 Jul 2023 11:41:18 -0400 Subject: [PATCH 37/52] fix templating bug for parseable entire files --- crates/semantic_index/src/parsing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/semantic_index/src/parsing.rs b/crates/semantic_index/src/parsing.rs index c952ef3a4edf939ddc8ad17c9bab6e17ec5e0cce..677406931e0cc36cd32fd497a5f53337052421e8 100644 --- a/crates/semantic_index/src/parsing.rs +++ b/crates/semantic_index/src/parsing.rs @@ -59,7 +59,7 @@ impl CodeContextRetriever { let document_span = ENTIRE_FILE_TEMPLATE .replace("", relative_path.to_string_lossy().as_ref()) .replace("", language_name.as_ref()) - .replace("item", &content); + .replace("", &content); Ok(vec![Document { range: 0..content.len(), From e07a81b22590257bb7bc8c4362d6afe3a01d401c Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Mon, 31 Jul 2023 12:49:55 -0400 Subject: [PATCH 38/52] Add additional storage filetypes --- assets/icons/file_icons/file_types.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/assets/icons/file_icons/file_types.json b/assets/icons/file_icons/file_types.json index 0ccf9c2bb7c7b4eb12f6ca83646ab9a38c661490..67791aaecb42f20a6a57035266a9bedaa4d7b415 100644 --- a/assets/icons/file_icons/file_types.json +++ b/assets/icons/file_icons/file_types.json @@ -1,5 +1,16 @@ { "suffixes": { + "db": "storage", + "sqlite": "storage", + "myi": "storage", + "myd": "storage", + "mdf": "storage", + "csv": "storage", + "bak": "backup", + "dat": "storage", + "dll": "storage", + "sav": "storage", + "tsv": "storage", "aac": "audio", "bash": "terminal", "bmp": "image", From c4709418d142888b5d94ae61c5aad98f28c6b21a Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Mon, 31 Jul 2023 12:50:30 -0400 Subject: [PATCH 39/52] Format --- assets/icons/file_icons/file_types.json | 343 ++++++++++++------------ 1 file changed, 176 insertions(+), 167 deletions(-) diff --git a/assets/icons/file_icons/file_types.json b/assets/icons/file_icons/file_types.json index 67791aaecb42f20a6a57035266a9bedaa4d7b415..9ea75d07309d853f37fed0192ca83bfd7d1099d8 100644 --- a/assets/icons/file_icons/file_types.json +++ b/assets/icons/file_icons/file_types.json @@ -1,170 +1,179 @@ { - "suffixes": { - "db": "storage", - "sqlite": "storage", - "myi": "storage", - "myd": "storage", - "mdf": "storage", - "csv": "storage", - "bak": "backup", - "dat": "storage", - "dll": "storage", - "sav": "storage", - "tsv": "storage", - "aac": "audio", - "bash": "terminal", - "bmp": "image", - "c": "code", - "conf": "settings", - "cpp": "code", - "cc": "code", - "css": "code", - "doc": "document", - "docx": "document", - "eslintrc": "eslint", - "eslintrc.js": "eslint", - "eslintrc.json": "eslint", - "flac": "audio", - "fish": "terminal", - "gitattributes": "vcs", - "gitignore": "vcs", - "gitmodules": "vcs", - "gif": "image", - "go": "code", - "h": "code", - "handlebars": "code", - "hbs": "template", - "htm": "template", - "html": "template", - "svelte": "template", - "hpp": "code", - "ico": "image", - "ini": "settings", - "java": "code", - "jpeg": "image", - "jpg": "image", - "js": "code", - "json": "storage", - "lock": "lock", - "log": "log", - "md": "document", - "mdx": "document", - "mp3": "audio", - "mp4": "video", - "ods": "document", - "odp": "document", - "odt": "document", - "ogg": "video", - "pdf": "document", - "php": "code", - "png": "image", - "ppt": "document", - "pptx": "document", - "prettierrc": "prettier", - "prettierignore": "prettier", - "ps1": "terminal", - "psd": "image", - "py": "code", - "rb": "code", - "rkt": "code", - "rs": "rust", - "rtf": "document", - "scm": "code", - "sh": "terminal", - "bashrc": "terminal", - "bash_profile": "terminal", - "bash_aliases": "terminal", - "bash_logout": "terminal", - "profile": "terminal", - "zshrc": "terminal", - "zshenv": "terminal", - "zsh_profile": "terminal", - "zsh_aliases": "terminal", - "zsh_histfile": "terminal", - "zlogin": "terminal", - "sql": "code", - "svg": "image", - "swift": "code", - "tiff": "image", - "toml": "toml", - "ts": "typescript", - "tsx": "code", - "txt": "document", - "wav": "audio", - "webm": "video", - "xls": "document", - "xlsx": "document", - "xml": "template", - "yaml": "settings", - "yml": "settings", - "zsh": "terminal" - }, - "types": { - "audio": { - "icon": "icons/file_icons/audio.svg" - }, - "code": { - "icon": "icons/file_icons/code.svg" - }, - "collapsed_chevron": { - "icon": "icons/file_icons/chevron_right.svg" - }, - "collapsed_folder": { - "icon": "icons/file_icons/folder.svg" - }, - "default": { - "icon": "icons/file_icons/file.svg" - }, - "document": { - "icon": "icons/file_icons/book.svg" - }, - "eslint": { - "icon": "icons/file_icons/eslint.svg" - }, - "expanded_chevron": { - "icon": "icons/file_icons/chevron_down.svg" - }, - "expanded_folder": { - "icon": "icons/file_icons/folder_open.svg" - }, - "image": { - "icon": "icons/file_icons/image.svg" - }, - "lock": { - "icon": "icons/file_icons/lock.svg" - }, - "log": { - "icon": "icons/file_icons/info.svg" - }, - "prettier": { - "icon": "icons/file_icons/prettier.svg" - }, - "rust": { - "icon": "icons/file_icons/rust.svg" - }, - "settings": { - "icon": "icons/file_icons/settings.svg" - }, - "storage": { - "icon": "icons/file_icons/database.svg" - }, - "template": { - "icon": "icons/file_icons/html.svg" - }, - "terminal": { - "icon": "icons/file_icons/terminal.svg" - }, - "toml": { - "icon": "icons/file_icons/toml.svg" - }, - "typescript": { - "icon": "icons/file_icons/typescript.svg" - }, - "vcs": { - "icon": "icons/file_icons/git.svg" - }, - "video": { - "icon": "icons/file_icons/video.svg" + "suffixes": { + "aac": "audio", + "accdb": "storage", + "bak": "backup", + "bash": "terminal", + "bash_aliases": "terminal", + "bash_logout": "terminal", + "bash_profile": "terminal", + "bashrc": "terminal", + "bmp": "image", + "c": "code", + "cc": "code", + "conf": "settings", + "cpp": "code", + "css": "code", + "csv": "storage", + "dat": "storage", + "db": "storage", + "dbf": "storage", + "dll": "storage", + "doc": "document", + "docx": "document", + "eslintrc": "eslint", + "eslintrc.js": "eslint", + "eslintrc.json": "eslint", + "fmp": "storage", + "fp7": "storage", + "flac": "audio", + "fish": "terminal", + "frm": "storage", + "gdb": "storage", + "gitattributes": "vcs", + "gitignore": "vcs", + "gitmodules": "vcs", + "gif": "image", + "go": "code", + "h": "code", + "handlebars": "code", + "hbs": "template", + "htm": "template", + "html": "template", + "ib": "storage", + "ico": "image", + "ini": "settings", + "java": "code", + "jpeg": "image", + "jpg": "image", + "js": "code", + "json": "storage", + "ldf": "storage", + "lock": "lock", + "log": "log", + "mdb": "storage", + "md": "document", + "mdf": "storage", + "mdx": "document", + "mp3": "audio", + "mp4": "video", + "myd": "storage", + "myi": "storage", + "ods": "document", + "odp": "document", + "odt": "document", + "ogg": "video", + "pdb": "storage", + "pdf": "document", + "php": "code", + "png": "image", + "ppt": "document", + "pptx": "document", + "prettierignore": "prettier", + "prettierrc": "prettier", + "profile": "terminal", + "ps1": "terminal", + "psd": "image", + "py": "code", + "rb": "code", + "rkt": "code", + "rs": "rust", + "rtf": "document", + "sav": "storage", + "scm": "code", + "sh": "terminal", + "sqlite": "storage", + "sdf": "storage", + "svelte": "template", + "svg": "image", + "swift": "code", + "ts": "typescript", + "tsx": "code", + "tiff": "image", + "toml": "toml", + "tsv": "storage", + "txt": "document", + "wav": "audio", + "webm": "video", + "xls": "document", + "xlsx": "document", + "xml": "template", + "yaml": "settings", + "yml": "settings", + "zlogin": "terminal", + "zsh": "terminal", + "zsh_aliases": "terminal", + "zshenv": "terminal", + "zsh_histfile": "terminal", + "zsh_profile": "terminal", + "zshrc": "terminal" + }, + "types": { + "audio": { + "icon": "icons/file_icons/audio.svg" + }, + "code": { + "icon": "icons/file_icons/code.svg" + }, + "collapsed_chevron": { + "icon": "icons/file_icons/chevron_right.svg" + }, + "collapsed_folder": { + "icon": "icons/file_icons/folder.svg" + }, + "default": { + "icon": "icons/file_icons/file.svg" + }, + "document": { + "icon": "icons/file_icons/book.svg" + }, + "eslint": { + "icon": "icons/file_icons/eslint.svg" + }, + "expanded_chevron": { + "icon": "icons/file_icons/chevron_down.svg" + }, + "expanded_folder": { + "icon": "icons/file_icons/folder_open.svg" + }, + "image": { + "icon": "icons/file_icons/image.svg" + }, + "lock": { + "icon": "icons/file_icons/lock.svg" + }, + "log": { + "icon": "icons/file_icons/info.svg" + }, + "prettier": { + "icon": "icons/file_icons/prettier.svg" + }, + "rust": { + "icon": "icons/file_icons/rust.svg" + }, + "settings": { + "icon": "icons/file_icons/settings.svg" + }, + "storage": { + "icon": "icons/file_icons/database.svg" + }, + "template": { + "icon": "icons/file_icons/html.svg" + }, + "terminal": { + "icon": "icons/file_icons/terminal.svg" + }, + "toml": { + "icon": "icons/file_icons/toml.svg" + }, + "typescript": { + "icon": "icons/file_icons/typescript.svg" + }, + "vcs": { + "icon": "icons/file_icons/git.svg" + }, + "video": { + "icon": "icons/file_icons/video.svg" + } } - } } From bb288eb941fba31ba98a89f9b2b32940ed493ac5 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Mon, 31 Jul 2023 13:08:40 -0400 Subject: [PATCH 40/52] Ensure json uses a tab size of 4 --- .zed/settings.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .zed/settings.json diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..d4b3375b0d21f95128c6bffb2c7a92f8bf97916c --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,5 @@ +{ + "JSON": { + "tab_size": 4 + } +} From 88474a60485257814313b4a6ff799642feeafe6a Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 31 Jul 2023 10:54:29 -0700 Subject: [PATCH 41/52] Clip wrap guides from under the scrollbar --- crates/editor/src/element.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index cb46e74af0b1e8d1480dedba1ae51db417fbf5b6..750beaea1380ee676c15a3d895c633a91bbe6c12 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -554,7 +554,9 @@ impl EditorElement { (text_bounds.origin_x() + wrap_position + layout.position_map.em_width / 2.) - scroll_left; - if x < text_bounds.origin_x() { + if x < text_bounds.origin_x() + || (layout.show_scrollbars && x > self.scrollbar_left(&bounds)) + { continue; } @@ -1046,6 +1048,10 @@ impl EditorElement { scene.pop_layer(); } + fn scrollbar_left(&self, bounds: &RectF) -> f32 { + bounds.max_x() - self.style.theme.scrollbar.width + } + fn paint_scrollbar( &mut self, scene: &mut SceneBuilder, @@ -1064,7 +1070,7 @@ impl EditorElement { let top = bounds.min_y(); let bottom = bounds.max_y(); let right = bounds.max_x(); - let left = right - style.width; + let left = self.scrollbar_left(&bounds); let row_range = &layout.scrollbar_row_range; let max_row = layout.max_row as f32 + (row_range.end - row_range.start); From 599f6748274ca40e91e593d5d049982b2fbded45 Mon Sep 17 00:00:00 2001 From: KCaverly Date: Mon, 31 Jul 2023 16:36:09 -0400 Subject: [PATCH 42/52] add php support for semantic search --- Cargo.lock | 65 ++---- crates/semantic_index/Cargo.toml | 17 +- crates/semantic_index/src/parsing.rs | 7 +- .../src/semantic_index_tests.rs | 205 ++++++++++++++++++ crates/zed/src/languages/php/config.toml | 1 + crates/zed/src/languages/php/embedding.scm | 36 +++ crates/zed/src/languages/php/outline.scm | 7 +- 7 files changed, 275 insertions(+), 63 deletions(-) create mode 100644 crates/zed/src/languages/php/embedding.scm diff --git a/Cargo.lock b/Cargo.lock index b4a8f13bea56d64f4d10084e726c22c312cdec92..f6a85aa70c38181110739d30310cf59603d2af8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2341,7 +2341,7 @@ dependencies = [ "tree-sitter", "tree-sitter-html", "tree-sitter-rust", - "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", + "tree-sitter-typescript", "unindent", "util", "workspace", @@ -3851,7 +3851,7 @@ dependencies = [ "text", "theme", "tree-sitter", - "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=4ba9dab6e2602960d95b2b625f3386c27e08084e)", + "tree-sitter-elixir", "tree-sitter-embedded-template", "tree-sitter-heex", "tree-sitter-html", @@ -3860,7 +3860,7 @@ dependencies = [ "tree-sitter-python", "tree-sitter-ruby", "tree-sitter-rust", - "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", + "tree-sitter-typescript", "unicase", "unindent", "util", @@ -6685,14 +6685,15 @@ dependencies = [ "theme", "tiktoken-rs 0.5.0", "tree-sitter", - "tree-sitter-cpp 0.20.2", - "tree-sitter-elixir 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tree-sitter-json 0.19.0", + "tree-sitter-cpp", + "tree-sitter-elixir", + "tree-sitter-json 0.20.0", "tree-sitter-lua", + "tree-sitter-php", "tree-sitter-ruby", "tree-sitter-rust", - "tree-sitter-toml 0.20.0", - "tree-sitter-typescript 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tree-sitter-toml", + "tree-sitter-typescript", "unindent", "util", "workspace", @@ -8257,16 +8258,6 @@ dependencies = [ "tree-sitter", ] -[[package]] -name = "tree-sitter-cpp" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c88fd925d0333e63ac64e521f5bd79c53019e569ffbbccfeef346a326f459e9" -dependencies = [ - "cc", - "tree-sitter", -] - [[package]] name = "tree-sitter-css" version = "0.19.0" @@ -8276,16 +8267,6 @@ dependencies = [ "tree-sitter", ] -[[package]] -name = "tree-sitter-elixir" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a9916f3e1c80b3c8aab8582604e97e8720cb9b893489b347cf999f80f9d469e" -dependencies = [ - "cc", - "tree-sitter", -] - [[package]] name = "tree-sitter-elixir" version = "0.1.0" @@ -8464,26 +8445,6 @@ dependencies = [ "tree-sitter", ] -[[package]] -name = "tree-sitter-toml" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca517f578a98b23d20780247cc2688407fa81effad5b627a5a364ec3339b53e8" -dependencies = [ - "cc", - "tree-sitter", -] - -[[package]] -name = "tree-sitter-typescript" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "079c695c32d39ad089101c66393aeaca30e967fba3486a91f573d2f0e12d290a" -dependencies = [ - "cc", - "tree-sitter", -] - [[package]] name = "tree-sitter-typescript" version = "0.20.2" @@ -9923,9 +9884,9 @@ dependencies = [ "tree-sitter", "tree-sitter-bash", "tree-sitter-c", - "tree-sitter-cpp 0.20.0", + "tree-sitter-cpp", "tree-sitter-css", - "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=4ba9dab6e2602960d95b2b625f3386c27e08084e)", + "tree-sitter-elixir", "tree-sitter-elm", "tree-sitter-embedded-template", "tree-sitter-glsl", @@ -9942,8 +9903,8 @@ dependencies = [ "tree-sitter-rust", "tree-sitter-scheme", "tree-sitter-svelte", - "tree-sitter-toml 0.5.1", - "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", + "tree-sitter-toml", + "tree-sitter-typescript", "tree-sitter-yaml", "unindent", "url", diff --git a/crates/semantic_index/Cargo.toml b/crates/semantic_index/Cargo.toml index 637f3f4487443825ace9b98dbe73690ce02ec250..3c7a6ff5df6df4b0ae7de9e0e7754a0e0d5850cc 100644 --- a/crates/semantic_index/Cargo.toml +++ b/crates/semantic_index/Cargo.toml @@ -54,11 +54,12 @@ tempdir.workspace = true ctor.workspace = true env_logger.workspace = true -tree-sitter-typescript = "*" -tree-sitter-json = "*" -tree-sitter-rust = "*" -tree-sitter-toml = "*" -tree-sitter-cpp = "*" -tree-sitter-elixir = "*" -tree-sitter-lua = "*" -tree-sitter-ruby = "*" +tree-sitter-typescript.workspace = true +tree-sitter-json.workspace = true +tree-sitter-rust.workspace = true +tree-sitter-toml.workspace = true +tree-sitter-cpp.workspace = true +tree-sitter-elixir.workspace = true +tree-sitter-lua.workspace = true +tree-sitter-ruby.workspace = true +tree-sitter-php.workspace = true diff --git a/crates/semantic_index/src/parsing.rs b/crates/semantic_index/src/parsing.rs index 677406931e0cc36cd32fd497a5f53337052421e8..3f7a850a5743a737ccb23aa5c91ee93317f3ae3d 100644 --- a/crates/semantic_index/src/parsing.rs +++ b/crates/semantic_index/src/parsing.rs @@ -200,7 +200,12 @@ impl CodeContextRetriever { let mut document_content = String::new(); for context_range in &context_match.context_ranges { - document_content.push_str(&content[context_range.clone()]); + add_content_from_range( + &mut document_content, + content, + context_range.clone(), + context_match.start_col, + ); document_content.push_str("\n"); } diff --git a/crates/semantic_index/src/semantic_index_tests.rs b/crates/semantic_index/src/semantic_index_tests.rs index 58d34649c7e953faf2ebf3bac5829e5474330f85..0411a8e5ecd70d503dd8dfcdfd5f19426e2e81c5 100644 --- a/crates/semantic_index/src/semantic_index_tests.rs +++ b/crates/semantic_index/src/semantic_index_tests.rs @@ -1017,6 +1017,156 @@ async fn test_code_context_retrieval_ruby() { ); } +#[gpui::test] +async fn test_code_context_retrieval_php() { + let language = php_lang(); + let mut retriever = CodeContextRetriever::new(); + + let text = r#" + 100) { + throw new Exception(message: 'Progress cannot be greater than 100'); + } + + if ($this->achievements()->find($achievement->id)) { + throw new Exception(message: 'User already has this Achievement'); + } + + $this->achievements()->attach($achievement, [ + 'progress' => $progress ?? null, + ]); + + $this->when(value: ($progress === null) || ($progress === 100), callback: fn (): ?array => event(new AchievementAwarded(achievement: $achievement, user: $this))); + } + + public function achievements(): BelongsToMany + { + return $this->belongsToMany(related: Achievement::class) + ->withPivot(columns: 'progress') + ->where('is_secret', false) + ->using(AchievementUser::class); + } + } + + interface Multiplier + { + public function qualifies(array $data): bool; + + public function setMultiplier(): int; + } + + enum AuditType: string + { + case Add = 'add'; + case Remove = 'remove'; + case Reset = 'reset'; + case LevelUp = 'level_up'; + } + + ?>"# + .unindent(); + + let documents = retriever.parse_file(&text, language.clone()).unwrap(); + + assert_documents_eq( + &documents, + &[ + ( + r#" + /* + This is a multiple-lines comment block + that spans over multiple + lines + */ + function functionName() { + echo "Hello world!"; + }"# + .unindent(), + 123, + ), + ( + r#" + trait HasAchievements + { + /** + * @throws \Exception + */ + public function grantAchievement(Achievement $achievement, $progress = null): void + {/* ... */} + + public function achievements(): BelongsToMany + {/* ... */} + }"# + .unindent(), + 177, + ), + (r#" + /** + * @throws \Exception + */ + public function grantAchievement(Achievement $achievement, $progress = null): void + { + if ($progress > 100) { + throw new Exception(message: 'Progress cannot be greater than 100'); + } + + if ($this->achievements()->find($achievement->id)) { + throw new Exception(message: 'User already has this Achievement'); + } + + $this->achievements()->attach($achievement, [ + 'progress' => $progress ?? null, + ]); + + $this->when(value: ($progress === null) || ($progress === 100), callback: fn (): ?array => event(new AchievementAwarded(achievement: $achievement, user: $this))); + }"#.unindent(), 245), + (r#" + public function achievements(): BelongsToMany + { + return $this->belongsToMany(related: Achievement::class) + ->withPivot(columns: 'progress') + ->where('is_secret', false) + ->using(AchievementUser::class); + }"#.unindent(), 902), + (r#" + interface Multiplier + { + public function qualifies(array $data): bool; + + public function setMultiplier(): int; + }"#.unindent(), + 1146), + (r#" + enum AuditType: string + { + case Add = 'add'; + case Remove = 'remove'; + case Reset = 'reset'; + case LevelUp = 'level_up'; + }"#.unindent(), 1265) + ], + ); +} + #[gpui::test] fn test_dot_product(mut rng: StdRng) { assert_eq!(dot(&[1., 0., 0., 0., 0.], &[0., 1., 0., 0., 0.]), 0.); @@ -1376,6 +1526,61 @@ fn lua_lang() -> Arc { ) } +fn php_lang() -> Arc { + Arc::new( + Language::new( + LanguageConfig { + name: "PHP".into(), + path_suffixes: vec!["php".into()], + collapsed_placeholder: "/* ... */".into(), + ..Default::default() + }, + Some(tree_sitter_php::language()), + ) + .with_embedding_query( + r#" + ( + (comment)* @context + . + [ + (function_definition + "function" @name + name: (_) @name + body: (_ + "{" @keep + "}" @keep) @collapse + ) + + (trait_declaration + "trait" @name + name: (_) @name) + + (method_declaration + "function" @name + name: (_) @name + body: (_ + "{" @keep + "}" @keep) @collapse + ) + + (interface_declaration + "interface" @name + name: (_) @name + ) + + (enum_declaration + "enum" @name + name: (_) @name + ) + + ] @item + ) + "#, + ) + .unwrap(), + ) +} + fn ruby_lang() -> Arc { Arc::new( Language::new( diff --git a/crates/zed/src/languages/php/config.toml b/crates/zed/src/languages/php/config.toml index e9de52745a153b63df0ed99c260d64b9aea65aab..19acb949e25c66be9890f9931f49a8e82f8bb972 100644 --- a/crates/zed/src/languages/php/config.toml +++ b/crates/zed/src/languages/php/config.toml @@ -9,3 +9,4 @@ brackets = [ { start = "(", end = ")", close = true, newline = true }, { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, ] +collapsed_placeholder = "/* ... */" diff --git a/crates/zed/src/languages/php/embedding.scm b/crates/zed/src/languages/php/embedding.scm new file mode 100644 index 0000000000000000000000000000000000000000..db277775b38fe43f5bc3dc981cf468048202dc17 --- /dev/null +++ b/crates/zed/src/languages/php/embedding.scm @@ -0,0 +1,36 @@ +( + (comment)* @context + . + [ + (function_definition + "function" @name + name: (_) @name + body: (_ + "{" @keep + "}" @keep) @collapse + ) + + (trait_declaration + "trait" @name + name: (_) @name) + + (method_declaration + "function" @name + name: (_) @name + body: (_ + "{" @keep + "}" @keep) @collapse + ) + + (interface_declaration + "interface" @name + name: (_) @name + ) + + (enum_declaration + "enum" @name + name: (_) @name + ) + + ] @item + ) diff --git a/crates/zed/src/languages/php/outline.scm b/crates/zed/src/languages/php/outline.scm index 4934bc494d0ae709ec52ea3fb46db518b8dc35d8..87986f1032e7189070add8d18f163b00432c6475 100644 --- a/crates/zed/src/languages/php/outline.scm +++ b/crates/zed/src/languages/php/outline.scm @@ -8,8 +8,6 @@ name: (_) @name ) @item - - (method_declaration "function" @context name: (_) @name @@ -24,3 +22,8 @@ "enum" @context name: (_) @name ) @item + +(trait_declaration + "trait" @context + name: (_) @name + ) @item From 646dabe1133b32c852bf9b41b22234723f442602 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 31 Jul 2023 16:40:03 +0300 Subject: [PATCH 43/52] Add buffer search history --- assets/keymaps/default.json | 7 + crates/gpui/src/app.rs | 6 + crates/search/src/buffer_search.rs | 230 ++++++++++++++++++++++++++++- crates/search/src/search.rs | 187 +++++++++++++++++++++++ crates/vim/src/normal/search.rs | 2 +- crates/vim/src/test.rs | 4 +- 6 files changed, 428 insertions(+), 8 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index adc55f8c91e8cd39ec72745975c988aaaac9fb7c..57fde112bfc5a9ab4d15f5a17f91afd6a89cbf82 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -227,6 +227,13 @@ "alt-enter": "search::SelectAllMatches" } }, + { + "context": "BufferSearchBar > Editor", + "bindings": { + "up": "search::PreviousHistoryQuery", + "down": "search::NextHistoryQuery" + } + }, { "context": "ProjectSearchBar", "bindings": { diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 7af363d596b63abe06f78717d8945dcba820d7fd..da601ba3510e3624b7acd0954f922082b2197755 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1128,6 +1128,12 @@ impl AppContext { self.keystroke_matcher.clear_bindings(); } + pub fn binding_for_action(&self, action: &dyn Action) -> Option<&Binding> { + self.keystroke_matcher + .bindings_for_action(action.id()) + .find(|binding| binding.action().eq(action)) + } + pub fn default_global(&mut self) -> &T { let type_id = TypeId::of::(); self.update(|this| { diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 54293050989c146e5bb39363c12281c46eea1a53..45842aa5617b4f87cf306aebdead2d9ae96d455f 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -1,6 +1,6 @@ use crate::{ - SearchOptions, SelectAllMatches, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, - ToggleRegex, ToggleWholeWord, + NextHistoryQuery, PreviousHistoryQuery, SearchHistory, SearchOptions, SelectAllMatches, + SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, ToggleWholeWord, }; use collections::HashMap; use editor::Editor; @@ -46,6 +46,8 @@ pub fn init(cx: &mut AppContext) { cx.add_action(BufferSearchBar::select_prev_match_on_pane); cx.add_action(BufferSearchBar::select_all_matches_on_pane); cx.add_action(BufferSearchBar::handle_editor_cancel); + cx.add_action(BufferSearchBar::next_history_query); + cx.add_action(BufferSearchBar::previous_history_query); add_toggle_option_action::(SearchOptions::CASE_SENSITIVE, cx); add_toggle_option_action::(SearchOptions::WHOLE_WORD, cx); add_toggle_option_action::(SearchOptions::REGEX, cx); @@ -65,7 +67,7 @@ fn add_toggle_option_action(option: SearchOptions, cx: &mut AppContex } pub struct BufferSearchBar { - pub query_editor: ViewHandle, + query_editor: ViewHandle, active_searchable_item: Option>, active_match_index: Option, active_searchable_item_subscription: Option, @@ -76,6 +78,7 @@ pub struct BufferSearchBar { default_options: SearchOptions, query_contains_error: bool, dismissed: bool, + search_history: SearchHistory, } impl Entity for BufferSearchBar { @@ -106,6 +109,48 @@ impl View for BufferSearchBar { .map(|active_searchable_item| active_searchable_item.supported_options()) .unwrap_or_default(); + let previous_query_keystrokes = + cx.binding_for_action(&PreviousHistoryQuery {}) + .map(|binding| { + binding + .keystrokes() + .iter() + .map(|k| k.to_string()) + .collect::>() + }); + let next_query_keystrokes = cx.binding_for_action(&NextHistoryQuery {}).map(|binding| { + binding + .keystrokes() + .iter() + .map(|k| k.to_string()) + .collect::>() + }); + let new_placeholder_text = match (previous_query_keystrokes, next_query_keystrokes) { + (Some(previous_query_keystrokes), Some(next_query_keystrokes)) => { + format!( + "Search ({}/{} for previous/next query)", + previous_query_keystrokes.join(" "), + next_query_keystrokes.join(" ") + ) + } + (None, Some(next_query_keystrokes)) => { + format!( + "Search ({} for next query)", + next_query_keystrokes.join(" ") + ) + } + (Some(previous_query_keystrokes), None) => { + format!( + "Search ({} for previous query)", + previous_query_keystrokes.join(" ") + ) + } + (None, None) => String::new(), + }; + self.query_editor.update(cx, |editor, cx| { + editor.set_placeholder_text(new_placeholder_text, cx); + }); + Flex::row() .with_child( Flex::row() @@ -258,6 +303,7 @@ impl BufferSearchBar { pending_search: None, query_contains_error: false, dismissed: true, + search_history: SearchHistory::default(), } } @@ -341,7 +387,7 @@ impl BufferSearchBar { cx: &mut ViewContext, ) -> oneshot::Receiver<()> { let options = options.unwrap_or(self.default_options); - if query != self.query_editor.read(cx).text(cx) || self.search_options != options { + if query != self.query(cx) || self.search_options != options { self.query_editor.update(cx, |query_editor, cx| { query_editor.buffer().update(cx, |query_buffer, cx| { let len = query_buffer.len(cx); @@ -674,7 +720,7 @@ impl BufferSearchBar { fn update_matches(&mut self, cx: &mut ViewContext) -> oneshot::Receiver<()> { let (done_tx, done_rx) = oneshot::channel(); - let query = self.query_editor.read(cx).text(cx); + let query = self.query(cx); self.pending_search.take(); if let Some(active_searchable_item) = self.active_searchable_item.as_ref() { if query.is_empty() { @@ -707,6 +753,7 @@ impl BufferSearchBar { ) }; + let query_text = query.as_str().to_string(); let matches = active_searchable_item.find_matches(query, cx); let active_searchable_item = active_searchable_item.downgrade(); @@ -720,6 +767,7 @@ impl BufferSearchBar { .insert(active_searchable_item.downgrade(), matches); this.update_match_index(cx); + this.search_history.add(query_text); if !this.dismissed { let matches = this .searchable_items_with_matches @@ -753,6 +801,28 @@ impl BufferSearchBar { cx.notify(); } } + + fn next_history_query(&mut self, _: &NextHistoryQuery, cx: &mut ViewContext) { + if let Some(new_query) = self.search_history.next().map(str::to_string) { + let _ = self.search(&new_query, Some(self.search_options), cx); + } else { + self.search_history.reset_selection(); + let _ = self.search("", Some(self.search_options), cx); + } + } + + fn previous_history_query(&mut self, _: &PreviousHistoryQuery, cx: &mut ViewContext) { + if self.query(cx).is_empty() { + if let Some(new_query) = self.search_history.current().map(str::to_string) { + let _ = self.search(&new_query, Some(self.search_options), cx); + return; + } + } + + if let Some(new_query) = self.search_history.previous().map(str::to_string) { + let _ = self.search(&new_query, Some(self.search_options), cx); + } + } } #[cfg(test)] @@ -1333,4 +1403,154 @@ mod tests { ); }); } + + #[gpui::test] + async fn test_search_query_history(cx: &mut TestAppContext) { + crate::project_search::tests::init_test(cx); + + let buffer_text = r#" + A regular expression (shortened as regex or regexp;[1] also referred to as + rational expression[2][3]) is a sequence of characters that specifies a search + pattern in text. Usually such patterns are used by string-searching algorithms + for "find" or "find and replace" operations on strings, or for input validation. + "# + .unindent(); + let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx)); + let (window_id, _root_view) = cx.add_window(|_| EmptyView); + + let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx)); + + let search_bar = cx.add_view(window_id, |cx| { + let mut search_bar = BufferSearchBar::new(cx); + search_bar.set_active_pane_item(Some(&editor), cx); + search_bar.show(cx); + search_bar + }); + + // Add 3 search items into the history. + search_bar + .update(cx, |search_bar, cx| search_bar.search("a", None, cx)) + .await + .unwrap(); + search_bar + .update(cx, |search_bar, cx| search_bar.search("b", None, cx)) + .await + .unwrap(); + search_bar + .update(cx, |search_bar, cx| { + search_bar.search("c", Some(SearchOptions::CASE_SENSITIVE), cx) + }) + .await + .unwrap(); + // Ensure that the latest search is active. + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "c"); + assert_eq!(search_bar.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // Next history query after the latest should set the query to the empty string. + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), ""); + assert_eq!(search_bar.search_options, SearchOptions::CASE_SENSITIVE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), ""); + assert_eq!(search_bar.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // First previous query for empty current query should set the query to the latest. + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "c"); + assert_eq!(search_bar.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // Further previous items should go over the history in reverse order. + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "b"); + assert_eq!(search_bar.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // Previous items should never go behind the first history item. + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "a"); + assert_eq!(search_bar.search_options, SearchOptions::CASE_SENSITIVE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "a"); + assert_eq!(search_bar.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // Next items should go over the history in the original order. + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "b"); + assert_eq!(search_bar.search_options, SearchOptions::CASE_SENSITIVE); + }); + + search_bar + .update(cx, |search_bar, cx| search_bar.search("ba", None, cx)) + .await + .unwrap(); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "ba"); + assert_eq!(search_bar.search_options, SearchOptions::NONE); + }); + + // New search input should add another entry to history and move the selection to the end of the history. + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "c"); + assert_eq!(search_bar.search_options, SearchOptions::NONE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "b"); + assert_eq!(search_bar.search_options, SearchOptions::NONE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "c"); + assert_eq!(search_bar.search_options, SearchOptions::NONE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "ba"); + assert_eq!(search_bar.search_options, SearchOptions::NONE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), ""); + assert_eq!(search_bar.search_options, SearchOptions::NONE); + }); + } } diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index 58cda0c7dc5f819ec1b34cd97ff577331cc030b0..18e39155274c650d4f2dde860a4998e398a8bbbe 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -3,6 +3,7 @@ pub use buffer_search::BufferSearchBar; use gpui::{actions, Action, AppContext}; use project::search::SearchQuery; pub use project_search::{ProjectSearchBar, ProjectSearchView}; +use smallvec::SmallVec; pub mod buffer_search; pub mod project_search; @@ -21,6 +22,8 @@ actions!( SelectNextMatch, SelectPrevMatch, SelectAllMatches, + NextHistoryQuery, + PreviousHistoryQuery, ] ); @@ -65,3 +68,187 @@ impl SearchOptions { options } } + +const SEARCH_HISTORY_LIMIT: usize = 20; + +#[derive(Default, Debug)] +pub struct SearchHistory { + history: SmallVec<[String; SEARCH_HISTORY_LIMIT]>, + selected: Option, +} + +impl SearchHistory { + pub fn add(&mut self, search_string: String) { + if let Some(i) = self.selected { + if search_string == self.history[i] { + return; + } + } + + if let Some(previously_searched) = self.history.last_mut() { + if search_string.find(previously_searched.as_str()).is_some() { + *previously_searched = search_string; + self.selected = Some(self.history.len() - 1); + return; + } + } + + self.history.push(search_string); + if self.history.len() > SEARCH_HISTORY_LIMIT { + self.history.remove(0); + } + self.selected = Some(self.history.len() - 1); + } + + pub fn next(&mut self) -> Option<&str> { + let history_size = self.history.len(); + if history_size == 0 { + return None; + } + + let selected = self.selected?; + if selected == history_size - 1 { + return None; + } + let next_index = selected + 1; + self.selected = Some(next_index); + Some(&self.history[next_index]) + } + + pub fn current(&self) -> Option<&str> { + Some(&self.history[self.selected?]) + } + + pub fn previous(&mut self) -> Option<&str> { + let history_size = self.history.len(); + if history_size == 0 { + return None; + } + + let prev_index = match self.selected { + Some(selected_index) => { + if selected_index == 0 { + return None; + } else { + selected_index - 1 + } + } + None => history_size - 1, + }; + + self.selected = Some(prev_index); + Some(&self.history[prev_index]) + } + + pub fn reset_selection(&mut self) { + self.selected = None; + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_add() { + let mut search_history = SearchHistory::default(); + assert_eq!( + search_history.current(), + None, + "No current selection should be set fo the default search history" + ); + + search_history.add("rust".to_string()); + assert_eq!( + search_history.current(), + Some("rust"), + "Newly added item should be selected" + ); + + // check if duplicates are not added + search_history.add("rust".to_string()); + assert_eq!( + search_history.history.len(), + 1, + "Should not add a duplicate" + ); + assert_eq!(search_history.current(), Some("rust")); + + // check if new string containing the previous string replaces it + search_history.add("rustlang".to_string()); + assert_eq!( + search_history.history.len(), + 1, + "Should replace previous item if it's a substring" + ); + assert_eq!(search_history.current(), Some("rustlang")); + + // push enough items to test SEARCH_HISTORY_LIMIT + for i in 0..SEARCH_HISTORY_LIMIT * 2 { + search_history.add(format!("item{i}")); + } + assert!(search_history.history.len() <= SEARCH_HISTORY_LIMIT); + } + + #[test] + fn test_next_and_previous() { + let mut search_history = SearchHistory::default(); + assert_eq!( + search_history.next(), + None, + "Default search history should not have a next item" + ); + + search_history.add("Rust".to_string()); + assert_eq!(search_history.next(), None); + search_history.add("JavaScript".to_string()); + assert_eq!(search_history.next(), None); + search_history.add("TypeScript".to_string()); + assert_eq!(search_history.next(), None); + + assert_eq!(search_history.current(), Some("TypeScript")); + + assert_eq!(search_history.previous(), Some("JavaScript")); + assert_eq!(search_history.current(), Some("JavaScript")); + + assert_eq!(search_history.previous(), Some("Rust")); + assert_eq!(search_history.current(), Some("Rust")); + + assert_eq!(search_history.previous(), None); + assert_eq!(search_history.current(), Some("Rust")); + + assert_eq!(search_history.next(), Some("JavaScript")); + assert_eq!(search_history.current(), Some("JavaScript")); + + assert_eq!(search_history.next(), Some("TypeScript")); + assert_eq!(search_history.current(), Some("TypeScript")); + + assert_eq!(search_history.next(), None); + assert_eq!(search_history.current(), Some("TypeScript")); + } + + #[test] + fn test_reset_selection() { + let mut search_history = SearchHistory::default(); + search_history.add("Rust".to_string()); + search_history.add("JavaScript".to_string()); + search_history.add("TypeScript".to_string()); + + assert_eq!(search_history.current(), Some("TypeScript")); + search_history.reset_selection(); + assert_eq!(search_history.current(), None); + assert_eq!( + search_history.previous(), + Some("TypeScript"), + "Should start from the end after reset on previous item query" + ); + + search_history.previous(); + assert_eq!(search_history.current(), Some("JavaScript")); + search_history.previous(); + assert_eq!(search_history.current(), Some("Rust")); + + search_history.reset_selection(); + assert_eq!(search_history.current(), None); + } +} diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index d584c575d2970e3fa1131acb08b1adfac7ca38a9..614866d9c9c4ce7b3aca398dcc978f79298dfc81 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -222,7 +222,7 @@ mod test { }); search_bar.read_with(cx.cx, |bar, cx| { - assert_eq!(bar.query_editor.read(cx).text(cx), "cc"); + assert_eq!(bar.query(cx), "cc"); }); deterministic.run_until_parked(); diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 98d8cb8749996909757367c36e2591817030bebe..474f2128fc5194857e2c5436a802c5ce99791cc8 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -99,7 +99,7 @@ async fn test_buffer_search(cx: &mut gpui::TestAppContext) { }); search_bar.read_with(cx.cx, |bar, cx| { - assert_eq!(bar.query_editor.read(cx).text(cx), ""); + assert_eq!(bar.query(cx), ""); }) } @@ -175,7 +175,7 @@ async fn test_selection_on_search(cx: &mut gpui::TestAppContext) { }); search_bar.read_with(cx.cx, |bar, cx| { - assert_eq!(bar.query_editor.read(cx).text(cx), "cc"); + assert_eq!(bar.query(cx), "cc"); }); // wait for the query editor change event to fire. From 634baeedb4a0a59b303182519ef1279b72319c8f Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 1 Aug 2023 01:23:51 +0300 Subject: [PATCH 44/52] Add project search history --- assets/keymaps/default.json | 7 + crates/search/src/project_search.rs | 283 +++++++++++++++++++++++++++- crates/search/src/search.rs | 2 +- 3 files changed, 289 insertions(+), 3 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 57fde112bfc5a9ab4d15f5a17f91afd6a89cbf82..38ec8ffb4057d2404c5e38e1150b27bb3acd155d 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -240,6 +240,13 @@ "escape": "project_search::ToggleFocus" } }, + { + "context": "ProjectSearchBar > Editor", + "bindings": { + "up": "search::PreviousHistoryQuery", + "down": "search::NextHistoryQuery" + } + }, { "context": "ProjectSearchView", "bindings": { diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 87307264f507070ced1303c072c8b9a59cee5cc9..1b4e32f4b832483c160293a5d792b39d62a1a628 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -1,6 +1,6 @@ use crate::{ - SearchOptions, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, - ToggleWholeWord, + NextHistoryQuery, PreviousHistoryQuery, SearchHistory, SearchOptions, SelectNextMatch, + SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, ToggleWholeWord, }; use anyhow::Context; use collections::HashMap; @@ -56,6 +56,8 @@ pub fn init(cx: &mut AppContext) { cx.add_action(ProjectSearchBar::search_in_new); cx.add_action(ProjectSearchBar::select_next_match); cx.add_action(ProjectSearchBar::select_prev_match); + cx.add_action(ProjectSearchBar::next_history_query); + cx.add_action(ProjectSearchBar::previous_history_query); cx.capture_action(ProjectSearchBar::tab); cx.capture_action(ProjectSearchBar::tab_previous); add_toggle_option_action::(SearchOptions::CASE_SENSITIVE, cx); @@ -83,6 +85,7 @@ struct ProjectSearch { match_ranges: Vec>, active_query: Option, search_id: usize, + search_history: SearchHistory, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -131,6 +134,7 @@ impl ProjectSearch { match_ranges: Default::default(), active_query: None, search_id: 0, + search_history: SearchHistory::default(), } } @@ -144,6 +148,7 @@ impl ProjectSearch { match_ranges: self.match_ranges.clone(), active_query: self.active_query.clone(), search_id: self.search_id, + search_history: self.search_history.clone(), }) } @@ -152,6 +157,7 @@ impl ProjectSearch { .project .update(cx, |project, cx| project.search(query.clone(), cx)); self.search_id += 1; + self.search_history.add(query.as_str().to_string()); self.active_query = Some(query); self.match_ranges.clear(); self.pending_search = Some(cx.spawn_weak(|this, mut cx| async move { @@ -202,6 +208,7 @@ impl ProjectSearch { }); self.search_id += 1; self.match_ranges.clear(); + self.search_history.add(query.as_str().to_string()); self.pending_search = Some(cx.spawn(|this, mut cx| async move { let results = search?.await.log_err()?; @@ -278,6 +285,49 @@ impl View for ProjectSearchView { Cow::Borrowed("No results") }; + let previous_query_keystrokes = + cx.binding_for_action(&PreviousHistoryQuery {}) + .map(|binding| { + binding + .keystrokes() + .iter() + .map(|k| k.to_string()) + .collect::>() + }); + let next_query_keystrokes = + cx.binding_for_action(&NextHistoryQuery {}).map(|binding| { + binding + .keystrokes() + .iter() + .map(|k| k.to_string()) + .collect::>() + }); + let new_placeholder_text = match (previous_query_keystrokes, next_query_keystrokes) { + (Some(previous_query_keystrokes), Some(next_query_keystrokes)) => { + format!( + "Search ({}/{} for previous/next query)", + previous_query_keystrokes.join(" "), + next_query_keystrokes.join(" ") + ) + } + (None, Some(next_query_keystrokes)) => { + format!( + "Search ({} for next query)", + next_query_keystrokes.join(" ") + ) + } + (Some(previous_query_keystrokes), None) => { + format!( + "Search ({} for previous query)", + previous_query_keystrokes.join(" ") + ) + } + (None, None) => String::new(), + }; + self.query_editor.update(cx, |editor, cx| { + editor.set_placeholder_text(new_placeholder_text, cx); + }); + MouseEventHandler::::new(0, cx, |_, _| { Label::new(text, theme.search.results_status.clone()) .aligned() @@ -1152,6 +1202,47 @@ impl ProjectSearchBar { false } } + + fn next_history_query(&mut self, _: &NextHistoryQuery, cx: &mut ViewContext) { + if let Some(search_view) = self.active_project_search.as_ref() { + search_view.update(cx, |search_view, cx| { + let new_query = search_view.model.update(cx, |model, _| { + if let Some(new_query) = model.search_history.next().map(str::to_string) { + new_query + } else { + model.search_history.reset_selection(); + String::new() + } + }); + search_view.set_query(&new_query, cx); + }); + } + } + + fn previous_history_query(&mut self, _: &PreviousHistoryQuery, cx: &mut ViewContext) { + if let Some(search_view) = self.active_project_search.as_ref() { + search_view.update(cx, |search_view, cx| { + if search_view.query_editor.read(cx).text(cx).is_empty() { + if let Some(new_query) = search_view + .model + .read(cx) + .search_history + .current() + .map(str::to_string) + { + search_view.set_query(&new_query, cx); + return; + } + } + + if let Some(new_query) = search_view.model.update(cx, |model, _| { + model.search_history.previous().map(str::to_string) + }) { + search_view.set_query(&new_query, cx); + } + }); + } + } } impl Entity for ProjectSearchBar { @@ -1333,6 +1424,7 @@ pub mod tests { use editor::DisplayPoint; use gpui::{color::Color, executor::Deterministic, TestAppContext}; use project::FakeFs; + use semantic_index::semantic_index_settings::SemanticIndexSettings; use serde_json::json; use settings::SettingsStore; use std::sync::Arc; @@ -1758,6 +1850,192 @@ pub mod tests { }); } + #[gpui::test] + async fn test_search_query_history(cx: &mut TestAppContext) { + init_test(cx); + + let fs = FakeFs::new(cx.background()); + fs.insert_tree( + "/dir", + json!({ + "one.rs": "const ONE: usize = 1;", + "two.rs": "const TWO: usize = one::ONE + one::ONE;", + "three.rs": "const THREE: usize = one::ONE + two::TWO;", + "four.rs": "const FOUR: usize = one::ONE + three::THREE;", + }), + ) + .await; + let project = Project::test(fs.clone(), ["/dir".as_ref()], cx).await; + let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx)); + workspace.update(cx, |workspace, cx| { + ProjectSearchView::deploy(workspace, &workspace::NewSearch, cx) + }); + + let search_view = cx.read(|cx| { + workspace + .read(cx) + .active_pane() + .read(cx) + .active_item() + .and_then(|item| item.downcast::()) + .expect("Search view expected to appear after new search event trigger") + }); + + let search_bar = cx.add_view(window_id, |cx| { + let mut search_bar = ProjectSearchBar::new(); + search_bar.set_active_pane_item(Some(&search_view), cx); + // search_bar.show(cx); + search_bar + }); + + // Add 3 search items into the history + another unsubmitted one. + search_view.update(cx, |search_view, cx| { + search_view.search_options = SearchOptions::CASE_SENSITIVE; + search_view + .query_editor + .update(cx, |query_editor, cx| query_editor.set_text("ONE", cx)); + search_view.search(cx); + }); + cx.foreground().run_until_parked(); + search_view.update(cx, |search_view, cx| { + search_view + .query_editor + .update(cx, |query_editor, cx| query_editor.set_text("TWO", cx)); + search_view.search(cx); + }); + cx.foreground().run_until_parked(); + search_view.update(cx, |search_view, cx| { + search_view + .query_editor + .update(cx, |query_editor, cx| query_editor.set_text("THREE", cx)); + search_view.search(cx); + }); + cx.foreground().run_until_parked(); + search_view.update(cx, |search_view, cx| { + search_view.query_editor.update(cx, |query_editor, cx| { + query_editor.set_text("JUST_TEXT_INPUT", cx) + }); + }); + cx.foreground().run_until_parked(); + + // Ensure that the latest input with search settings is active. + search_view.update(cx, |search_view, cx| { + assert_eq!( + search_view.query_editor.read(cx).text(cx), + "JUST_TEXT_INPUT" + ); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // Next history query after the latest should set the query to the empty string. + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), ""); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), ""); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // First previous query for empty current query should set the query to the latest submitted one. + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "THREE"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // Further previous items should go over the history in reverse order. + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "TWO"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // Previous items should never go behind the first history item. + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "ONE"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "ONE"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // Next items should go over the history in the original order. + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "TWO"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + + search_view.update(cx, |search_view, cx| { + search_view + .query_editor + .update(cx, |query_editor, cx| query_editor.set_text("TWO_NEW", cx)); + search_view.search(cx); + }); + cx.foreground().run_until_parked(); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "TWO_NEW"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + + // New search input should add another entry to history and move the selection to the end of the history. + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "THREE"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.previous_history_query(&PreviousHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "TWO"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "THREE"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), "TWO_NEW"); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + search_bar.update(cx, |search_bar, cx| { + search_bar.next_history_query(&NextHistoryQuery, cx); + }); + search_view.update(cx, |search_view, cx| { + assert_eq!(search_view.query_editor.read(cx).text(cx), ""); + assert_eq!(search_view.search_options, SearchOptions::CASE_SENSITIVE); + }); + } + pub fn init_test(cx: &mut TestAppContext) { cx.foreground().forbid_parking(); let fonts = cx.font_cache(); @@ -1767,6 +2045,7 @@ pub mod tests { cx.update(|cx| { cx.set_global(SettingsStore::test(cx)); cx.set_global(ActiveSearches::default()); + settings::register::(cx); theme::init((), cx); cx.update_global::(|store, _| { diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index 18e39155274c650d4f2dde860a4998e398a8bbbe..f1711afec20c73bd9965bd77140994aa1c1145b8 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -71,7 +71,7 @@ impl SearchOptions { const SEARCH_HISTORY_LIMIT: usize = 20; -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone)] pub struct SearchHistory { history: SmallVec<[String; SEARCH_HISTORY_LIMIT]>, selected: Option, From 9a50b43eaa0f52a0a223e198141b8091ec618548 Mon Sep 17 00:00:00 2001 From: KCaverly Date: Mon, 31 Jul 2023 21:03:02 -0400 Subject: [PATCH 45/52] add templating languages html, erb, heex, svelte as entire parseable file types --- crates/semantic_index/src/parsing.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/semantic_index/src/parsing.rs b/crates/semantic_index/src/parsing.rs index 3f7a850a5743a737ccb23aa5c91ee93317f3ae3d..643db8c79827819a2e274aa2eb82d37cfb6bc4a2 100644 --- a/crates/semantic_index/src/parsing.rs +++ b/crates/semantic_index/src/parsing.rs @@ -21,7 +21,8 @@ const CODE_CONTEXT_TEMPLATE: &str = "The below code snippet is from file ''\n\n```\n\n```"; const ENTIRE_FILE_TEMPLATE: &str = "The below snippet is from file ''\n\n```\n\n```"; -pub const PARSEABLE_ENTIRE_FILE_TYPES: &[&str] = &["TOML", "YAML", "CSS"]; +pub const PARSEABLE_ENTIRE_FILE_TYPES: &[&str] = + &["TOML", "YAML", "CSS", "HEEX", "ERB", "SVELTE", "HTML"]; pub struct CodeContextRetriever { pub parser: Parser, From e221f23018d9b9883327712874b1237725922a0a Mon Sep 17 00:00:00 2001 From: KCaverly Date: Tue, 1 Aug 2023 10:30:34 -0400 Subject: [PATCH 46/52] add support for markdown files to semantic search --- crates/semantic_index/src/parsing.rs | 16 ++++++++++++++++ crates/semantic_index/src/semantic_index.rs | 1 + 2 files changed, 17 insertions(+) diff --git a/crates/semantic_index/src/parsing.rs b/crates/semantic_index/src/parsing.rs index 643db8c79827819a2e274aa2eb82d37cfb6bc4a2..cef23862c563f470000306fde5ac32f95a50a458 100644 --- a/crates/semantic_index/src/parsing.rs +++ b/crates/semantic_index/src/parsing.rs @@ -21,6 +21,7 @@ const CODE_CONTEXT_TEMPLATE: &str = "The below code snippet is from file ''\n\n```\n\n```"; const ENTIRE_FILE_TEMPLATE: &str = "The below snippet is from file ''\n\n```\n\n```"; +const MARKDOWN_CONTEXT_TEMPLATE: &str = "The below file contents is from file ''\n\n"; pub const PARSEABLE_ENTIRE_FILE_TYPES: &[&str] = &["TOML", "YAML", "CSS", "HEEX", "ERB", "SVELTE", "HTML"]; @@ -70,6 +71,19 @@ impl CodeContextRetriever { }]) } + fn parse_markdown_file(&self, relative_path: &Path, content: &str) -> Result> { + let document_span = MARKDOWN_CONTEXT_TEMPLATE + .replace("", relative_path.to_string_lossy().as_ref()) + .replace("", &content); + + Ok(vec![Document { + range: 0..content.len(), + content: document_span, + embedding: Vec::new(), + name: "Markdown".to_string(), + }]) + } + fn get_matches_in_file( &mut self, content: &str, @@ -136,6 +150,8 @@ impl CodeContextRetriever { if PARSEABLE_ENTIRE_FILE_TYPES.contains(&language_name.as_ref()) { return self.parse_entire_file(relative_path, language_name, &content); + } else if &language_name.to_string() == &"Markdown".to_string() { + return self.parse_markdown_file(relative_path, &content); } let mut documents = self.parse_file(content, language)?; diff --git a/crates/semantic_index/src/semantic_index.rs b/crates/semantic_index/src/semantic_index.rs index bd114de216a0a30b3271b56c2b627439a7e70a0e..23c75f40149cc4af2fb981844a6330dec3a638bb 100644 --- a/crates/semantic_index/src/semantic_index.rs +++ b/crates/semantic_index/src/semantic_index.rs @@ -613,6 +613,7 @@ impl SemanticIndex { .await { if !PARSEABLE_ENTIRE_FILE_TYPES.contains(&language.name().as_ref()) + && &language.name().as_ref() != &"Markdown" && language .grammar() .and_then(|grammar| grammar.embedding_config.as_ref()) From eb26fb2d45357e35d7d39edb8e2b3c6e0c1e9dbb Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 1 Aug 2023 11:52:53 -0400 Subject: [PATCH 47/52] Fix variable names --- crates/editor/src/editor.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 5270d6f951870fa952e9a0a33f2f229a1d71ff98..a4d9259a6d7e7a63dc1606450ecef9d2aa4c53f4 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4221,7 +4221,7 @@ impl Editor { _: &SortLinesCaseSensitive, cx: &mut ViewContext, ) { - self.manipulate_lines(cx, |text| text.sort()) + self.manipulate_lines(cx, |lines| lines.sort()) } pub fn sort_lines_case_insensitive( @@ -4229,7 +4229,7 @@ impl Editor { _: &SortLinesCaseInsensitive, cx: &mut ViewContext, ) { - self.manipulate_lines(cx, |text| text.sort_by_key(|line| line.to_lowercase())) + self.manipulate_lines(cx, |lines| lines.sort_by_key(|line| line.to_lowercase())) } pub fn reverse_lines(&mut self, _: &ReverseLines, cx: &mut ViewContext) { @@ -4267,19 +4267,19 @@ impl Editor { let text = buffer .text_for_range(start_point..end_point) .collect::(); - let mut text = text.split("\n").collect_vec(); + let mut lines = text.split("\n").collect_vec(); - let text_len = text.len(); - callback(&mut text); + let lines_len = lines.len(); + callback(&mut lines); // This is a current limitation with selections. // If we wanted to support removing or adding lines, we'd need to fix the logic associated with selections. debug_assert!( - text.len() == text_len, + lines.len() == lines_len, "callback should not change the number of lines" ); - edits.push((start_point..end_point, text.join("\n"))); + edits.push((start_point..end_point, lines.join("\n"))); let start_anchor = buffer.anchor_after(start_point); let end_anchor = buffer.anchor_before(end_point); From 3cee181f99c6de5ae264a119124d0ca94c0ffe3d Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 1 Aug 2023 14:04:29 -0400 Subject: [PATCH 48/52] Improve panic message usefulness on local dev builds --- crates/zed/src/main.rs | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index e44ab3e33acbb213f69b230a80075aea07890c85..2a1fef6a56efc5bf1c5496c935c134a752767066 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -45,6 +45,7 @@ use std::{ use sum_tree::Bias; use terminal_view::{get_working_directory, TerminalSettings, TerminalView}; use util::{ + channel::ReleaseChannel, http::{self, HttpClient}, paths::PathLikeWithPosition, }; @@ -415,22 +416,41 @@ fn init_panic_hook(app: &App, installation_id: Option) { panic::set_hook(Box::new(move |info| { let prior_panic_count = PANIC_COUNT.fetch_add(1, Ordering::SeqCst); if prior_panic_count > 0 { - std::panic::resume_unwind(Box::new(())); + // Give the panic-ing thread time to write the panic file + loop { + std::thread::yield_now(); + } } - let app_version = ZED_APP_VERSION - .or_else(|| platform.app_version().ok()) - .map_or("dev".to_string(), |v| v.to_string()); - let thread = thread::current(); - let thread = thread.name().unwrap_or(""); + let thread_name = thread.name().unwrap_or(""); - let payload = info.payload(); - let payload = None - .or_else(|| payload.downcast_ref::<&str>().map(|s| s.to_string())) - .or_else(|| payload.downcast_ref::().map(|s| s.clone())) + let payload = info + .payload() + .downcast_ref::<&str>() + .map(|s| s.to_string()) + .or_else(|| info.payload().downcast_ref::().map(|s| s.clone())) .unwrap_or_else(|| "Box".to_string()); + if *util::channel::RELEASE_CHANNEL == ReleaseChannel::Dev { + let location = info.location().unwrap(); + let backtrace = Backtrace::new(); + eprintln!( + "Thread {:?} panicked with {:?} at {}:{}:{}\n{:?}", + thread_name, + payload, + location.file(), + location.line(), + location.column(), + backtrace, + ); + std::process::exit(-1); + } + + let app_version = ZED_APP_VERSION + .or_else(|| platform.app_version().ok()) + .map_or("dev".to_string(), |v| v.to_string()); + let backtrace = Backtrace::new(); let mut backtrace = backtrace .frames() @@ -447,7 +467,7 @@ fn init_panic_hook(app: &App, installation_id: Option) { } let panic_data = Panic { - thread: thread.into(), + thread: thread_name.into(), payload: payload.into(), location_data: info.location().map(|location| LocationData { file: location.file().into(), From 4c7d60ed131f563edc5c937e5bf3cf654f1c9178 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 2 Aug 2023 09:07:35 -0700 Subject: [PATCH 49/52] Upgrade to rust 1.71 --- Dockerfile | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2a78d37cbbcadd1bd7afaf612be5767a09abb581..77d011490e5821f282240af7d387b19f67a0edbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax = docker/dockerfile:1.2 -FROM rust:1.70-bullseye as builder +FROM rust:1.71-bullseye as builder WORKDIR app COPY . . diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f78a67ddb344b48057437e80661698500a1cb302..50003020e9baf17e3e9e0b50babb19c354356e15 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.70" +channel = "1.71" components = [ "rustfmt" ] targets = [ "x86_64-apple-darwin", "aarch64-apple-darwin", "wasm32-wasi" ] From a127b0d3e6168de644267541b5bd29b6adfec55c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 2 Aug 2023 09:19:23 -0700 Subject: [PATCH 50/52] Fix warnings surfaced in Rust 1.71 --- crates/collab/src/tests/randomized_integration_tests.rs | 2 +- crates/editor/src/display_map/inlay_map.rs | 4 +--- crates/editor/src/inlay_hint_cache.rs | 1 - crates/project/src/worktree.rs | 2 +- crates/sum_tree/src/cursor.rs | 2 +- crates/vim/src/normal/search.rs | 2 +- crates/zed/src/zed.rs | 1 - 7 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/collab/src/tests/randomized_integration_tests.rs b/crates/collab/src/tests/randomized_integration_tests.rs index 8062a12b83264f8ac4521f9071318d45fb5b0265..ae3e609b9397e77c0ee7d3fe3c6a1bcc4347a8fd 100644 --- a/crates/collab/src/tests/randomized_integration_tests.rs +++ b/crates/collab/src/tests/randomized_integration_tests.rs @@ -183,7 +183,7 @@ async fn apply_server_operation( let username; { let mut plan = plan.lock(); - let mut user = plan.user(user_id); + let user = plan.user(user_id); if user.online { return false; } diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index 6a59cecae8e2ecb172cd3e72b447b29cb33d42c4..9794ac45c1190ec88ccb471ee61630ec50d320ca 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -397,7 +397,7 @@ impl InlayMap { buffer_snapshot: MultiBufferSnapshot, mut buffer_edits: Vec>, ) -> (InlaySnapshot, Vec) { - let mut snapshot = &mut self.snapshot; + let snapshot = &mut self.snapshot; if buffer_edits.is_empty() { if snapshot.buffer.trailing_excerpt_update_count() @@ -572,7 +572,6 @@ impl InlayMap { }) .collect(); let buffer_snapshot = snapshot.buffer.clone(); - drop(snapshot); let (snapshot, edits) = self.sync(buffer_snapshot, buffer_edits); (snapshot, edits) } @@ -635,7 +634,6 @@ impl InlayMap { } log::info!("removing inlays: {:?}", to_remove); - drop(snapshot); let (snapshot, edits) = self.splice(to_remove, to_insert); (snapshot, edits) } diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs index 63076ba234d52c53556bb9fc9a8a43acbf314a96..3d4ea3d6f28279273ce683a7a88997905d1feef0 100644 --- a/crates/editor/src/inlay_hint_cache.rs +++ b/crates/editor/src/inlay_hint_cache.rs @@ -571,7 +571,6 @@ fn new_update_task( if let Some(buffer) = refresh_multi_buffer.buffer(pending_refresh_query.buffer_id) { - drop(refresh_multi_buffer); editor.inlay_hint_cache.update_tasks.insert( pending_refresh_query.excerpt_id, UpdateTask { diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index b0795818b8d62557b688313fcfe8d017c2b55795..9e30796bbc58e3176ef73e8acb95358565fc6b34 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -2369,7 +2369,7 @@ impl BackgroundScannerState { } // Remove any git repositories whose .git entry no longer exists. - let mut snapshot = &mut self.snapshot; + let snapshot = &mut self.snapshot; let mut repositories = mem::take(&mut snapshot.git_repositories); let mut repository_entries = mem::take(&mut snapshot.repository_entries); repositories.retain(|work_directory_id, _| { diff --git a/crates/sum_tree/src/cursor.rs b/crates/sum_tree/src/cursor.rs index efd6ac145e0978ffc65cb5261bcd616b51aa71a6..12ab12dc27b9a2611983806665aa840e0ac32caa 100644 --- a/crates/sum_tree/src/cursor.rs +++ b/crates/sum_tree/src/cursor.rs @@ -202,7 +202,7 @@ where self.position = D::default(); } - let mut entry = self.stack.last_mut().unwrap(); + let entry = self.stack.last_mut().unwrap(); if !descending { if entry.index == 0 { self.stack.pop(); diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index 614866d9c9c4ce7b3aca398dcc978f79298dfc81..9375c4e78da53d58df29b636c768db56f9ac4fb9 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -93,7 +93,7 @@ fn search_submit(workspace: &mut Workspace, _: &SearchSubmit, cx: &mut ViewConte pane.update(cx, |pane, cx| { if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { search_bar.update(cx, |search_bar, cx| { - let mut state = &mut vim.state.search; + let state = &mut vim.state.search; let mut count = state.count; // in the case that the query has changed, the search bar diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 4b0bf1cd4c6aec42aa2d636b474828ef452cbe03..b67bf0bab48b76052b5ee10668b627f81e7f0042 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -545,7 +545,6 @@ pub fn handle_keymap_file_changes( reload_keymaps(cx, &keymap_content); } }) - .detach(); })); } } From b0ec05a73242bc131d1e788fa278a057e4dfb569 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Wed, 2 Aug 2023 13:50:30 -0400 Subject: [PATCH 51/52] v0.99.x dev --- Cargo.lock | 2 +- crates/zed/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a00b0735866ddd7bd4957e45f50fab0413f6c01f..fbf4e750c62c920a7158c712d48c4f6cd380bf6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9815,7 +9815,7 @@ dependencies = [ [[package]] name = "zed" -version = "0.98.0" +version = "0.99.0" dependencies = [ "activity_indicator", "ai", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index a5877aaccb41a390776a16d8627653d2c0afa40c..95d6445d1762e3eedbd3c57141ba2c61595dd70b 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Nathan Sobo "] description = "The fast, collaborative code editor." edition = "2021" name = "zed" -version = "0.98.0" +version = "0.99.0" publish = false [lib] From 9e755bb85582f2cbe953492e9a14ce0a166f24c1 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 2 Aug 2023 12:15:39 -0700 Subject: [PATCH 52/52] Revert "Extract syntax highlighting properties from tree-sitter highlight queries (#2797)" This reverts commit 45c635872b5ef7bb8994e16d593aa25edf8e94bf, reversing changes made to f2b82369f27b79fdcaa6a4276bb047abddf7171c. --- crates/zed/src/languages/bash/highlights.scm | 2 +- crates/zed/src/languages/c/highlights.scm | 3 +- crates/zed/src/languages/c/injections.scm | 4 +- crates/zed/src/languages/cpp/highlights.scm | 4 +- crates/zed/src/languages/cpp/injections.scm | 4 +- crates/zed/src/languages/css/highlights.scm | 2 +- crates/zed/src/languages/elixir/embedding.scm | 6 +- .../zed/src/languages/elixir/highlights.scm | 18 +- .../zed/src/languages/elixir/injections.scm | 4 +- crates/zed/src/languages/elixir/outline.scm | 4 +- crates/zed/src/languages/elm/injections.scm | 2 +- crates/zed/src/languages/erb/injections.scm | 8 +- crates/zed/src/languages/glsl/highlights.scm | 4 +- crates/zed/src/languages/heex/injections.scm | 6 +- crates/zed/src/languages/html/injections.scm | 4 +- .../src/languages/javascript/highlights.scm | 6 +- crates/zed/src/languages/lua/highlights.scm | 10 +- crates/zed/src/languages/php/highlights.scm | 10 +- crates/zed/src/languages/php/injections.scm | 4 +- .../zed/src/languages/python/highlights.scm | 8 +- .../zed/src/languages/racket/highlights.scm | 7 +- crates/zed/src/languages/racket/outline.scm | 4 +- crates/zed/src/languages/ruby/brackets.scm | 2 +- crates/zed/src/languages/ruby/highlights.scm | 8 +- crates/zed/src/languages/rust/highlights.scm | 4 +- crates/zed/src/languages/rust/injections.scm | 4 +- .../zed/src/languages/scheme/highlights.scm | 4 +- crates/zed/src/languages/scheme/outline.scm | 4 +- .../zed/src/languages/svelte/injections.scm | 14 +- .../src/languages/typescript/highlights.scm | 10 +- styles/package.json | 1 - styles/src/build_themes.ts | 9 +- styles/src/build_tokens.ts | 4 +- styles/src/component/icon_button.ts | 5 +- styles/src/component/tab_bar_button.ts | 67 ++- styles/src/component/text_button.ts | 5 +- styles/src/style_tree/app.ts | 2 +- styles/src/style_tree/assistant.ts | 69 ++-- styles/src/style_tree/editor.ts | 32 +- styles/src/style_tree/feedback.ts | 2 +- styles/src/style_tree/picker.ts | 2 +- styles/src/style_tree/project_panel.ts | 16 +- styles/src/style_tree/status_bar.ts | 10 +- styles/src/style_tree/titlebar.ts | 4 +- styles/src/theme/create_theme.ts | 30 +- styles/src/theme/syntax.ts | 389 ++++++++++++++---- styles/src/theme/theme_config.ts | 6 +- styles/src/theme/tokens/theme.ts | 10 +- styles/src/themes/atelier/common.ts | 9 +- styles/src/themes/ayu/common.ts | 6 +- styles/src/themes/gruvbox/gruvbox-common.ts | 6 +- styles/src/themes/one/one-dark.ts | 4 +- styles/src/themes/one/one-light.ts | 2 + styles/src/themes/rose-pine/common.ts | 4 +- styles/src/types/extract_syntax_types.ts | 111 ----- styles/src/types/syntax.ts | 202 --------- styles/tsconfig.json | 4 +- 57 files changed, 554 insertions(+), 631 deletions(-) delete mode 100644 styles/src/types/extract_syntax_types.ts delete mode 100644 styles/src/types/syntax.ts diff --git a/crates/zed/src/languages/bash/highlights.scm b/crates/zed/src/languages/bash/highlights.scm index f3e0c9529a1d7c19777e40c28f934c0b57e10941..a72c5468edd911b60b31c8ae07041c3f733f3497 100644 --- a/crates/zed/src/languages/bash/highlights.scm +++ b/crates/zed/src/languages/bash/highlights.scm @@ -54,5 +54,5 @@ ( (command (_) @constant) - (.match? @constant "^-") + (#match? @constant "^-") ) diff --git a/crates/zed/src/languages/c/highlights.scm b/crates/zed/src/languages/c/highlights.scm index 5245e53a052578a62f8d4cddab8141bb0d80d288..064ec61a378beb00417e6b6716a6f1358daa5cbf 100644 --- a/crates/zed/src/languages/c/highlights.scm +++ b/crates/zed/src/languages/c/highlights.scm @@ -86,7 +86,7 @@ (identifier) @variable ((identifier) @constant - (.match? @constant "^_*[A-Z][A-Z\\d_]*$")) + (#match? @constant "^_*[A-Z][A-Z\\d_]*$")) (call_expression function: (identifier) @function) @@ -106,3 +106,4 @@ (primitive_type) (sized_type_specifier) ] @type + diff --git a/crates/zed/src/languages/c/injections.scm b/crates/zed/src/languages/c/injections.scm index fbc7d83f8211836067a08cf05fae1b7b66170d12..845a63bd1bd4e700df0fd1eb3c5d10d31e2ab0e4 100644 --- a/crates/zed/src/languages/c/injections.scm +++ b/crates/zed/src/languages/c/injections.scm @@ -1,7 +1,7 @@ (preproc_def value: (preproc_arg) @content - (.set! "language" "c")) + (#set! "language" "c")) (preproc_function_def value: (preproc_arg) @content - (.set! "language" "c")) + (#set! "language" "c")) \ No newline at end of file diff --git a/crates/zed/src/languages/cpp/highlights.scm b/crates/zed/src/languages/cpp/highlights.scm index a040b1d053cd714a5576c8a6d9f13304c6c1392c..bcfa01ca5c6aca231d444026af94c7f6c6b32f51 100644 --- a/crates/zed/src/languages/cpp/highlights.scm +++ b/crates/zed/src/languages/cpp/highlights.scm @@ -31,13 +31,13 @@ declarator: (field_identifier) @function) ((namespace_identifier) @type - (.match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) (auto) @type (type_identifier) @type ((identifier) @constant - (.match? @constant "^_*[A-Z][A-Z\\d_]*$")) + (#match? @constant "^_*[A-Z][A-Z\\d_]*$")) (field_identifier) @property (statement_identifier) @label diff --git a/crates/zed/src/languages/cpp/injections.scm b/crates/zed/src/languages/cpp/injections.scm index 3c94ba4061f6942fd88c7b09279b4f40a1709d14..eca372d577be30c352a2b7f7d93505a3b869e293 100644 --- a/crates/zed/src/languages/cpp/injections.scm +++ b/crates/zed/src/languages/cpp/injections.scm @@ -1,7 +1,7 @@ (preproc_def value: (preproc_arg) @content - (.set! "language" "c++")) + (#set! "language" "c++")) (preproc_function_def value: (preproc_arg) @content - (.set! "language" "c++")) + (#set! "language" "c++")) \ No newline at end of file diff --git a/crates/zed/src/languages/css/highlights.scm b/crates/zed/src/languages/css/highlights.scm index 83f99861c59e19b9e60335f2f4cc10231d00e31b..e271d8583c661b62f1a0bf5f4c848ca34cdbdc9d 100644 --- a/crates/zed/src/languages/css/highlights.scm +++ b/crates/zed/src/languages/css/highlights.scm @@ -46,7 +46,7 @@ (property_name) (plain_value) ] @variable.special - (.match? @variable.special "^--") + (#match? @variable.special "^--") ) [ diff --git a/crates/zed/src/languages/elixir/embedding.scm b/crates/zed/src/languages/elixir/embedding.scm index 3c523c248767dff3b855f9c623e66e5b3e03a4ae..16ad20746d4b0c8697ff126fcc5150636cb8b794 100644 --- a/crates/zed/src/languages/elixir/embedding.scm +++ b/crates/zed/src/languages/elixir/embedding.scm @@ -3,7 +3,7 @@ operator: "@" operand: (call target: (identifier) @unary - (.match? @unary "^(doc)$")) + (#match? @unary "^(doc)$")) ) @context . (call @@ -18,10 +18,10 @@ target: (identifier) @name) operator: "when") ]) - (.match? @name "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item + (#match? @name "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item ) (call target: (identifier) @name (arguments (alias) @name) - (.match? @name "^(defmodule|defprotocol)$")) @item + (#match? @name "^(defmodule|defprotocol)$")) @item diff --git a/crates/zed/src/languages/elixir/highlights.scm b/crates/zed/src/languages/elixir/highlights.scm index a8fd7eb45a6c04de64f1c7aa00fbeeecb535a316..0e779d195c5e6e03404c783d9675fc223232c84d 100644 --- a/crates/zed/src/languages/elixir/highlights.scm +++ b/crates/zed/src/languages/elixir/highlights.scm @@ -54,13 +54,13 @@ (sigil_name) @__name__ quoted_start: _ @string quoted_end: _ @string - (.match? @__name__ "^[sS]$")) @string + (#match? @__name__ "^[sS]$")) @string (sigil (sigil_name) @__name__ quoted_start: _ @string.regex quoted_end: _ @string.regex - (.match? @__name__ "^[rR]$")) @string.regex + (#match? @__name__ "^[rR]$")) @string.regex (sigil (sigil_name) @__name__ @@ -69,7 +69,7 @@ ( (identifier) @comment.unused - (.match? @comment.unused "^_") + (#match? @comment.unused "^_") ) (call @@ -91,7 +91,7 @@ operator: "|>" right: (identifier)) ]) - (.match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$")) + (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$")) (binary_operator operator: "|>" @@ -99,15 +99,15 @@ (call target: (identifier) @keyword - (.match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$")) + (#match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$")) (call target: (identifier) @keyword - (.match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$")) + (#match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$")) ( (identifier) @constant.builtin - (.match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$") + (#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$") ) (unary_operator @@ -121,7 +121,7 @@ (sigil) (boolean) ] @comment.doc)) - (.match? @__attribute__ "^(moduledoc|typedoc|doc)$")) + (#match? @__attribute__ "^(moduledoc|typedoc|doc)$")) (comment) @comment @@ -150,4 +150,4 @@ ((sigil (sigil_name) @_sigil_name (quoted_content) @embedded) - (.eq? @_sigil_name "H")) + (#eq? @_sigil_name "H")) diff --git a/crates/zed/src/languages/elixir/injections.scm b/crates/zed/src/languages/elixir/injections.scm index 5d445a7b820ed480a9545c638ba6e685be7c244a..4de229f1046ca39264ffb23dc98e565bfd74185b 100644 --- a/crates/zed/src/languages/elixir/injections.scm +++ b/crates/zed/src/languages/elixir/injections.scm @@ -3,5 +3,5 @@ ((sigil (sigil_name) @_sigil_name (quoted_content) @content) - (.eq? @_sigil_name "H") - (.set! language "heex")) + (#eq? @_sigil_name "H") + (#set! language "heex")) diff --git a/crates/zed/src/languages/elixir/outline.scm b/crates/zed/src/languages/elixir/outline.scm index 756d39651039c002ef79ec818ba63aee20523c20..a3311fb6d4640aa4ff5469c638022c1fde02e912 100644 --- a/crates/zed/src/languages/elixir/outline.scm +++ b/crates/zed/src/languages/elixir/outline.scm @@ -1,7 +1,7 @@ (call target: (identifier) @context (arguments (alias) @name) - (.match? @context "^(defmodule|defprotocol)$")) @item + (#match? @context "^(defmodule|defprotocol)$")) @item (call target: (identifier) @context @@ -23,4 +23,4 @@ ")" @context.extra)) operator: "when") ]) - (.match? @context "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item + (#match? @context "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @item diff --git a/crates/zed/src/languages/elm/injections.scm b/crates/zed/src/languages/elm/injections.scm index 3456f59a04af62c95fc26c7cec085123eb8b567d..0567320675a89c6649a191fdef950c6670d65707 100644 --- a/crates/zed/src/languages/elm/injections.scm +++ b/crates/zed/src/languages/elm/injections.scm @@ -1,2 +1,2 @@ ((glsl_content) @content - (.set! "language" "glsl")) + (#set! "language" "glsl")) diff --git a/crates/zed/src/languages/erb/injections.scm b/crates/zed/src/languages/erb/injections.scm index d9801015b7ca1f41f94b8be516f79b4c3c9365f6..7a69a818ef31d7fa3822466209b08c15280c6f5b 100644 --- a/crates/zed/src/languages/erb/injections.scm +++ b/crates/zed/src/languages/erb/injections.scm @@ -1,7 +1,7 @@ ((code) @content - (.set! "language" "ruby") - (.set! "combined")) + (#set! "language" "ruby") + (#set! "combined")) ((content) @content - (.set! "language" "html") - (.set! "combined")) + (#set! "language" "html") + (#set! "combined")) diff --git a/crates/zed/src/languages/glsl/highlights.scm b/crates/zed/src/languages/glsl/highlights.scm index 2378b8449b594d883ba19a0e5515369f5725522f..e4503c6fbba298afb1f2eddb82ce960af74b03c0 100644 --- a/crates/zed/src/languages/glsl/highlights.scm +++ b/crates/zed/src/languages/glsl/highlights.scm @@ -74,7 +74,7 @@ (sized_type_specifier) @type ((identifier) @constant - (.match? @constant "^[A-Z][A-Z\\d_]*$")) + (#match? @constant "^[A-Z][A-Z\\d_]*$")) (identifier) @variable @@ -114,5 +114,5 @@ ( (identifier) @variable.builtin - (.match? @variable.builtin "^gl_") + (#match? @variable.builtin "^gl_") ) diff --git a/crates/zed/src/languages/heex/injections.scm b/crates/zed/src/languages/heex/injections.scm index 1b63005cbfa02189e19a6a202c5beea0112c0946..b503bcb28dc10911b9e57e74f7217a21ece549fb 100644 --- a/crates/zed/src/languages/heex/injections.scm +++ b/crates/zed/src/languages/heex/injections.scm @@ -5,9 +5,9 @@ (expression_value) (ending_expression_value) ] @content) - (.set! language "elixir") - (.set! combined) + (#set! language "elixir") + (#set! combined) ) ((expression (expression_value) @content) - (.set! language "elixir")) + (#set! language "elixir")) diff --git a/crates/zed/src/languages/html/injections.scm b/crates/zed/src/languages/html/injections.scm index 7d2ed0a225e7555c6f12a9b902863a2e9e2e0939..9084e373f217b95cf70bad9cc907d5d9cd127391 100644 --- a/crates/zed/src/languages/html/injections.scm +++ b/crates/zed/src/languages/html/injections.scm @@ -1,7 +1,7 @@ (script_element (raw_text) @content - (.set! "language" "javascript")) + (#set! "language" "javascript")) (style_element (raw_text) @content - (.set! "language" "css")) + (#set! "language" "css")) diff --git a/crates/zed/src/languages/javascript/highlights.scm b/crates/zed/src/languages/javascript/highlights.scm index 7761bbb3a2dbdf0a66536f233be1df85c0724a11..36ab21ca1ec854566ad716a13f5ab5725fa1acc9 100644 --- a/crates/zed/src/languages/javascript/highlights.scm +++ b/crates/zed/src/languages/javascript/highlights.scm @@ -44,7 +44,7 @@ ; Special identifiers ((identifier) @type - (.match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) (type_identifier) @type (predefined_type) @type.builtin @@ -53,7 +53,7 @@ (shorthand_property_identifier) (shorthand_property_identifier_pattern) ] @constant -(.match? @constant "^_*[A-Z_][A-Z\\d_]*$")) + (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) ; Literals @@ -214,4 +214,4 @@ "type" "readonly" "override" -] @keyword +] @keyword \ No newline at end of file diff --git a/crates/zed/src/languages/lua/highlights.scm b/crates/zed/src/languages/lua/highlights.scm index e00d0b9557c86bb6a6d395a727dae2a1f2593210..f061bbf8f91651605a7bcf946dcb576a82045aa6 100644 --- a/crates/zed/src/languages/lua/highlights.scm +++ b/crates/zed/src/languages/lua/highlights.scm @@ -127,7 +127,7 @@ (identifier) @variable ((identifier) @variable.special - (.eq? @variable.special "self")) + (#eq? @variable.special "self")) (variable_list attribute: (attribute @@ -137,7 +137,7 @@ ;; Constants ((identifier) @constant - (.match? @constant "^[A-Z][A-Z_0-9]*$")) + (#match? @constant "^[A-Z][A-Z_0-9]*$")) (vararg_expression) @constant @@ -158,7 +158,7 @@ [ "{" "}" -] @method.constructor) +] @constructor) ;; Functions @@ -180,7 +180,7 @@ (function_call (identifier) @function.builtin - (.any-of? @function.builtin + (#any-of? @function.builtin ;; built-in functions in Lua 5.1 "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print" @@ -195,4 +195,4 @@ (number) @number -(string) @string +(string) @string \ No newline at end of file diff --git a/crates/zed/src/languages/php/highlights.scm b/crates/zed/src/languages/php/highlights.scm index fb85d997fad6585066ac621253fe9694467e8517..fcb087c47d14dbc036ed79a50be7ff1b57ebc4e8 100644 --- a/crates/zed/src/languages/php/highlights.scm +++ b/crates/zed/src/languages/php/highlights.scm @@ -43,15 +43,15 @@ (relative_scope) @variable.builtin ((name) @constant - (.match? @constant "^_?[A-Z][A-Z\\d_]+$")) + (#match? @constant "^_?[A-Z][A-Z\\d_]+$")) ((name) @constant.builtin - (.match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) + (#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) -((name) @method.constructor -(.match? @method.constructor "^[A-Z]")) +((name) @constructor + (#match? @constructor "^[A-Z]")) ((name) @variable.builtin - (.eq? @variable.builtin "this")) + (#eq? @variable.builtin "this")) (variable_name) @variable diff --git a/crates/zed/src/languages/php/injections.scm b/crates/zed/src/languages/php/injections.scm index 725729337b240a9e58b1e392ab645809d235314e..57abd8ea2b0576e7b936788b4a9880bc57fea798 100644 --- a/crates/zed/src/languages/php/injections.scm +++ b/crates/zed/src/languages/php/injections.scm @@ -1,3 +1,3 @@ ((text) @content - (.set! "language" "html") - (.set! "combined")) + (#set! "language" "html") + (#set! "combined")) diff --git a/crates/zed/src/languages/python/highlights.scm b/crates/zed/src/languages/python/highlights.scm index b31bddaeb501158c8bf6370ca0de37a1d73b7a6a..71ab963d82664db4dd9a66b9e9ac0e85449caf57 100644 --- a/crates/zed/src/languages/python/highlights.scm +++ b/crates/zed/src/languages/python/highlights.scm @@ -18,16 +18,16 @@ ; Identifier naming conventions ((identifier) @type - (.match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) ((identifier) @constant - (.match? @constant "^_*[A-Z][A-Z\\d_]*$")) + (#match? @constant "^_*[A-Z][A-Z\\d_]*$")) ; Builtin functions ((call function: (identifier) @function.builtin) - (.match? + (#match? @function.builtin "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$")) @@ -122,4 +122,4 @@ "yield" "match" "case" -] @keyword +] @keyword \ No newline at end of file diff --git a/crates/zed/src/languages/racket/highlights.scm b/crates/zed/src/languages/racket/highlights.scm index 304b10a018b23eebcea9248d33e0f43edd50ea29..2c0caf89357cfbe8f966bffbbc712272b3c1e59d 100644 --- a/crates/zed/src/languages/racket/highlights.scm +++ b/crates/zed/src/languages/racket/highlights.scm @@ -22,7 +22,7 @@ (lang_name) @variable.special ((symbol) @operator - (.match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) + (#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) (list . @@ -31,9 +31,10 @@ (list . (symbol) @keyword - (.match? @keyword + (#match? @keyword "^(unit-from-context|for/last|syntax-case|match-let\\*-values|define-for-syntax|define/subexpression-pos-prop|set-field!|class-field-accessor|invoke-unit|#%stratified-body|for\\*/and|for\\*/weak-set|flat-rec-contract|for\\*/stream|planet|for/mutable-seteqv|log-error|delay|#%declare|prop:dict/contract|->d|lib|override\\*|define-local-member-name|send-generic|for\\*/hasheq|define-syntax|submod|except|include-at/relative-to/reader|public\\*|define-member-name|define/public|let\\*|for/and|for\\*/first|for|delay/strict|define-values-for-export|==|match-define-values|for/weak-seteq|for\\*/async|for/stream|for/weak-seteqv|set!-values|lambda|for\\*/product|augment-final\\*|pubment\\*|command-line|contract|case|struct-field-index|contract-struct|unless|for/hasheq|for/seteqv|with-method|define-values-for-syntax|for-template|pubment|for\\*/list|syntax-case\\*|init-field|define-serializable-class|=>|for/foldr/derived|letrec-syntaxes|overment\\*|unquote-splicing|_|inherit-field|for\\*|stream-lazy|match-lambda\\*|contract-pos/neg-doubling|unit/c|match-define|for\\*/set|unit/s|nor|#%expression|class/c|this%|place/context|super-make-object|when|set!|parametric->/c|syntax-id-rules|include/reader|compound-unit|override-final|get-field|gen:dict|for\\*/seteqv|for\\*/hash|#%provide|combine-out|link|with-contract-continuation-mark|define-struct/derived|stream\\*|λ|rename-out|define-serializable-class\\*|augment|define/augment|let|define-signature-form|letrec-syntax|abstract|define-namespace-anchor|#%module-begin|#%top-interaction|for\\*/weak-seteqv|do|define/subexpression-pos-prop/name|absent|send/apply|with-handlers\\*|all-from-out|provide-signature-elements|gen:stream|define/override-final|for\\*/mutable-seteqv|rename|quasisyntax/loc|instantiate|for/list|extends|include-at/relative-to|mixin|define/pubment|#%plain-lambda|except-out|#%plain-module-begin|init|for\\*/last|relative-in|define-unit/new-import-export|->dm|member-name-key|nand|interface\\*|struct|define/override|else|define/augment-final|failure-cont|open|log-info|define/final-prop|all-defined-out|for/sum|for\\*/sum|recursive-contract|define|define-logger|match\\*|log-debug|rename-inner|->|struct/derived|unit|class\\*|prefix-out|any|define/overment|define-signature|match-letrec-values|let-syntaxes|for/mutable-set|define/match|cond|super-instantiate|define-contract-struct|import|hash/dc|define-custom-set-types|public-final|for/vector|for-label|prefix-in|for\\*/foldr/derived|define-unit-binding|object-contract|syntax-rules|augride|for\\*/mutable-seteq|quasisyntax|inner|for-syntax|overment|send/keyword-apply|generic|let\\*-values|->m|define-values|struct-copy|init-depend|struct/ctc|match-lambda|#%printing-module-begin|match\\*/derived|case->m|this|file|stream-cons|inspect|field|for/weak-set|struct\\*|gen:custom-write|thunk\\*|combine-in|unquote|for/lists|define/private|for\\*/foldr|define-unit/s|with-continuation-mark|begin|prefix|quote-syntax/prune|object/c|interface|match/derived|for/hasheqv|current-contract-region|define-compound-unit|override|define/public-final|recontract-out|let/cc|augride\\*|inherit|send|define-values/invoke-unit|for/mutable-seteq|#%datum|for/first|match-let\\*|invoke-unit/infer|define/contract|syntax/loc|for\\*/hasheqv|define-sequence-syntax|let/ec|for/product|for\\*/fold/derived|define-syntax-rule|lazy|unconstrained-domain->|augment-final|private|class|define-splicing-for-clause-syntax|for\\*/fold|prompt-tag/c|contract-out|match/values|public-final\\*|case-lambda|for/fold|unsyntax|for/set|begin0|#%require|time|public|define-struct|include|define-values/invoke-unit/infer|only-space-in|struct/c|only-meta-in|unit/new-import-export|place|begin-for-syntax|shared|inherit/super|quote|for/or|struct/contract|export|inherit/inner|struct-out|let-syntax|augment\\*|for\\*/vector|rename-in|match-let|define-unit|:do-in|~@|for\\*/weak-seteq|private\\*|and|except-in|log-fatal|gen:equal\\+hash|provide|require|thunk|invariant-assertion|define-match-expander|init-rest|->\\*|class/derived|super-new|for/fold/derived|for\\*/mutable-set|match-lambda\\*\\*|only|with-contract|~\\?|opt/c|let-values|delay/thread|->i|for/foldr|for-meta|only-in|send\\+|\\.\\.\\.|struct-guard/c|->\\*m|gen:set|struct/dc|define-syntaxes|if|parameterize|module\\*|module|send\\*|#%variable-reference|compound-unit/infer|#%plain-app|for/hash|contracted|case->|match|for\\*/lists|#%app|letrec-values|log-warning|super|define/augride|local-require|provide/contract|define-struct/contract|match-let-values|quote-syntax|for\\*/seteq|define-compound-unit/infer|parameterize\\*|values/drop|for/seteq|tag|stream|delay/idle|module\\+|define-custom-hash-types|cons/dc|define-module-boundary-contract|or|protect-out|define-opt/c|implies|letrec-syntaxes\\+values|for\\*/or|unsyntax-splicing|override-final\\*|for/async|parameterize-break|syntax|place\\*|for-space|quasiquote|with-handlers|delay/sync|define-unit-from-context|match-letrec|#%top|define-unit/contract|delay/name|new|field-bound\\?|letrec|class-field-mutator|with-syntax|flat-murec-contract|rename-super|local)$" )) ((symbol) @comment - (.match? @comment "^#[cC][iIsS]$")) + (#match? @comment "^#[cC][iIsS]$")) + diff --git a/crates/zed/src/languages/racket/outline.scm b/crates/zed/src/languages/racket/outline.scm index 188067078de2676ebaeaba90fe98d508dc7d19e0..604e052a63f71badbe98ec1debc96a519dc49256 100644 --- a/crates/zed/src/languages/racket/outline.scm +++ b/crates/zed/src/languages/racket/outline.scm @@ -6,5 +6,5 @@ (symbol) @name (list . (symbol) @name) ] - (.match? @start-symbol "^define") -) @item + (#match? @start-symbol "^define") +) @item \ No newline at end of file diff --git a/crates/zed/src/languages/ruby/brackets.scm b/crates/zed/src/languages/ruby/brackets.scm index f5129f8f310ce4b533c29c5e3fdb465844e5e68e..957b20ecdb4524920ba30b9d202d94d101215ed5 100644 --- a/crates/zed/src/languages/ruby/brackets.scm +++ b/crates/zed/src/languages/ruby/brackets.scm @@ -11,4 +11,4 @@ (begin "begin" @open "end" @close) (module "module" @open "end" @close) (_ . "def" @open "end" @close) -(_ . "class" @open "end" @close) +(_ . "class" @open "end" @close) \ No newline at end of file diff --git a/crates/zed/src/languages/ruby/highlights.scm b/crates/zed/src/languages/ruby/highlights.scm index 93cf2608f4ee7829c55718c42075b6cb986805a1..2610cfa1ccf07254c68c87d2e8013741d7d6969f 100644 --- a/crates/zed/src/languages/ruby/highlights.scm +++ b/crates/zed/src/languages/ruby/highlights.scm @@ -33,12 +33,12 @@ (identifier) @variable ((identifier) @keyword - (.match? @keyword "^(private|protected|public)$")) + (#match? @keyword "^(private|protected|public)$")) ; Function calls ((identifier) @function.method.builtin - (.eq? @function.method.builtin "require")) + (#eq? @function.method.builtin "require")) "defined?" @function.method.builtin @@ -60,7 +60,7 @@ ] @property ((identifier) @constant.builtin - (.match? @constant.builtin "^__(FILE|LINE|ENCODING)__$")) + (#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$")) (file) @constant.builtin (line) @constant.builtin @@ -71,7 +71,7 @@ ) @constant.builtin ((constant) @constant - (.match? @constant "^[A-Z\\d_]+$")) + (#match? @constant "^[A-Z\\d_]+$")) (constant) @type diff --git a/crates/zed/src/languages/rust/highlights.scm b/crates/zed/src/languages/rust/highlights.scm index 54dbfa00bd3195efadc965d3dca490d8c00b74bd..7240173a89260b22a9508a9984e40dc8b1ab7410 100644 --- a/crates/zed/src/languages/rust/highlights.scm +++ b/crates/zed/src/languages/rust/highlights.scm @@ -38,11 +38,11 @@ ; Assume uppercase names are types/enum-constructors ((identifier) @type - (.match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) ; Assume all-caps names are constants ((identifier) @constant - (.match? @constant "^_*[A-Z][A-Z\\d_]*$")) + (#match? @constant "^_*[A-Z][A-Z\\d_]*$")) [ "(" diff --git a/crates/zed/src/languages/rust/injections.scm b/crates/zed/src/languages/rust/injections.scm index 78fde3752fd9722e33daf4ad747b4e557044d353..57ebea8539345c72145eaa44cffb09845f913406 100644 --- a/crates/zed/src/languages/rust/injections.scm +++ b/crates/zed/src/languages/rust/injections.scm @@ -1,7 +1,7 @@ (macro_invocation (token_tree) @content - (.set! "language" "rust")) + (#set! "language" "rust")) (macro_rule (token_tree) @content - (.set! "language" "rust")) + (#set! "language" "rust")) \ No newline at end of file diff --git a/crates/zed/src/languages/scheme/highlights.scm b/crates/zed/src/languages/scheme/highlights.scm index 201b0e9276870afeb4f3ed7eb68de302af929b33..40ba61cd055948195023e2aa25db6f032acd674e 100644 --- a/crates/zed/src/languages/scheme/highlights.scm +++ b/crates/zed/src/languages/scheme/highlights.scm @@ -14,7 +14,7 @@ (directive)] @comment ((symbol) @operator - (.match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) + (#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=)$")) (list . @@ -23,6 +23,6 @@ (list . (symbol) @keyword - (.match? @keyword + (#match? @keyword "^(define-syntax|let\\*|lambda|λ|case|=>|quote-splicing|unquote-splicing|set!|let|letrec|letrec-syntax|let-values|let\\*-values|do|else|define|cond|syntax-rules|unquote|begin|quote|let-syntax|and|if|quasiquote|letrec|delay|or|when|unless|identifier-syntax|assert|library|export|import|rename|only|except|prefix)$" )) diff --git a/crates/zed/src/languages/scheme/outline.scm b/crates/zed/src/languages/scheme/outline.scm index 188067078de2676ebaeaba90fe98d508dc7d19e0..604e052a63f71badbe98ec1debc96a519dc49256 100644 --- a/crates/zed/src/languages/scheme/outline.scm +++ b/crates/zed/src/languages/scheme/outline.scm @@ -6,5 +6,5 @@ (symbol) @name (list . (symbol) @name) ] - (.match? @start-symbol "^define") -) @item + (#match? @start-symbol "^define") +) @item \ No newline at end of file diff --git a/crates/zed/src/languages/svelte/injections.scm b/crates/zed/src/languages/svelte/injections.scm index 17719b325c0c3632e1f6d9bbf7cd131ed9362dcb..8c1ac9fcd0bb16cf59e792487985ac64d6a43f88 100755 --- a/crates/zed/src/languages/svelte/injections.scm +++ b/crates/zed/src/languages/svelte/injections.scm @@ -2,27 +2,27 @@ ; -------------- (script_element (raw_text) @content - (.set! "language" "javascript")) + (#set! "language" "javascript")) ((script_element (start_tag (attribute (quoted_attribute_value (attribute_value) @_language))) (raw_text) @content) - (.eq? @_language "ts") - (.set! "language" "typescript")) + (#eq? @_language "ts") + (#set! "language" "typescript")) ((script_element (start_tag (attribute (quoted_attribute_value (attribute_value) @_language))) (raw_text) @content) - (.eq? @_language "typescript") - (.set! "language" "typescript")) + (#eq? @_language "typescript") + (#set! "language" "typescript")) (style_element (raw_text) @content - (.set! "language" "css")) + (#set! "language" "css")) ((raw_text_expr) @content - (.set! "language" "javascript")) + (#set! "language" "javascript")) diff --git a/crates/zed/src/languages/typescript/highlights.scm b/crates/zed/src/languages/typescript/highlights.scm index 9272108670ac2729dd39f4b54f90b81eeb3218a4..bf086ea156f6ee9c2aca6bb9d2ebdd3f91997999 100644 --- a/crates/zed/src/languages/typescript/highlights.scm +++ b/crates/zed/src/languages/typescript/highlights.scm @@ -43,11 +43,11 @@ ; Special identifiers -((identifier) @method.constructor - (.match? @method.constructor "^[A-Z]")) +((identifier) @constructor + (#match? @constructor "^[A-Z]")) ((identifier) @type - (.match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) (type_identifier) @type (predefined_type) @type.builtin @@ -56,7 +56,7 @@ (shorthand_property_identifier) (shorthand_property_identifier_pattern) ] @constant -(.match? @constant "^_*[A-Z_][A-Z\\d_]*$")) + (#match? @constant "^_*[A-Z_][A-Z\\d_]*$")) ; Literals @@ -218,4 +218,4 @@ "type" "readonly" "override" -] @keyword +] @keyword \ No newline at end of file diff --git a/styles/package.json b/styles/package.json index 3a50ac537166bcde6c30b0bc822481a823cfc8a2..16e95d90d5bebb18e7cfffe88e8d0098b48eb00f 100644 --- a/styles/package.json +++ b/styles/package.json @@ -8,7 +8,6 @@ "build-licenses": "ts-node ./src/build_licenses.ts", "build-tokens": "ts-node ./src/build_tokens.ts", "build-types": "ts-node ./src/build_types.ts", - "generate-syntax": "ts-node ./src/types/extract_syntax_types.ts", "test": "vitest" }, "author": "Zed Industries (https://github.com/zed-industries/)", diff --git a/styles/src/build_themes.ts b/styles/src/build_themes.ts index 4d262f8146ed907035e384dbefd28c0b838a467a..17575663a1f88b17870b1b146b47e7086bf3e2ba 100644 --- a/styles/src/build_themes.ts +++ b/styles/src/build_themes.ts @@ -21,7 +21,9 @@ function clear_themes(theme_directory: string) { } } -const all_themes: Theme[] = themes.map((theme) => create_theme(theme)) +const all_themes: Theme[] = themes.map((theme) => + create_theme(theme) +) function write_themes(themes: Theme[], output_directory: string) { clear_themes(output_directory) @@ -32,7 +34,10 @@ function write_themes(themes: Theme[], output_directory: string) { const style_tree = app() const style_tree_json = JSON.stringify(style_tree, null, 2) const temp_path = path.join(temp_directory, `${theme.name}.json`) - const out_path = path.join(output_directory, `${theme.name}.json`) + const out_path = path.join( + output_directory, + `${theme.name}.json` + ) fs.writeFileSync(temp_path, style_tree_json) fs.renameSync(temp_path, out_path) console.log(`- ${out_path} created`) diff --git a/styles/src/build_tokens.ts b/styles/src/build_tokens.ts index 3c52b6d989640a93025ac5eafe5a959b8bc83163..fd6aa18ced50af53b6bcf4c3c386d1774c7ab00d 100644 --- a/styles/src/build_tokens.ts +++ b/styles/src/build_tokens.ts @@ -83,6 +83,8 @@ function write_tokens(themes: Theme[], tokens_directory: string) { console.log(`- ${METADATA_FILE} created`) } -const all_themes: Theme[] = themes.map((theme) => create_theme(theme)) +const all_themes: Theme[] = themes.map((theme) => + create_theme(theme) +) write_tokens(all_themes, TOKENS_DIRECTORY) diff --git a/styles/src/component/icon_button.ts b/styles/src/component/icon_button.ts index 13dfce6d7762aaf2abc59f298fb6e22583435cf1..6887fc7c30e1f234fd043bb115c2658039b5f806 100644 --- a/styles/src/component/icon_button.ts +++ b/styles/src/component/icon_button.ts @@ -10,7 +10,10 @@ export type Margin = { } interface IconButtonOptions { - layer?: Theme["lowest"] | Theme["middle"] | Theme["highest"] + layer?: + | Theme["lowest"] + | Theme["middle"] + | Theme["highest"] color?: keyof Theme["lowest"] margin?: Partial } diff --git a/styles/src/component/tab_bar_button.ts b/styles/src/component/tab_bar_button.ts index 9e7f9acfc314be75850128690d8d066dde520182..0c43e7010e5469c10f959e00f4df8d177963392f 100644 --- a/styles/src/component/tab_bar_button.ts +++ b/styles/src/component/tab_bar_button.ts @@ -12,47 +12,44 @@ type TabBarButtonProps = TabBarButtonOptions & { state?: Partial>> } -export function tab_bar_button( - theme: Theme, - { icon, color = "base" }: TabBarButtonProps -) { +export function tab_bar_button(theme: Theme, { icon, color = "base" }: TabBarButtonProps) { const button_spacing = 8 - return interactive({ - base: { - icon: { - color: foreground(theme.middle, color), - asset: icon, - dimensions: { - width: 15, - height: 15, + return ( + interactive({ + base: { + icon: { + color: foreground(theme.middle, color), + asset: icon, + dimensions: { + width: 15, + height: 15, + }, }, - }, - container: { - corner_radius: 4, - padding: { - top: 4, - bottom: 4, - left: 4, - right: 4, - }, - margin: { - left: button_spacing / 2, - right: button_spacing / 2, - }, - }, - }, - state: { - hovered: { container: { - background: background(theme.middle, color, "hovered"), + corner_radius: 4, + padding: { + top: 4, bottom: 4, left: 4, right: 4 + }, + margin: { + left: button_spacing / 2, + right: button_spacing / 2, + }, }, }, - clicked: { - container: { - background: background(theme.middle, color, "pressed"), + state: { + hovered: { + container: { + background: background(theme.middle, color, "hovered"), + + } + }, + clicked: { + container: { + background: background(theme.middle, color, "pressed"), + } }, }, - }, - }) + }) + ) } diff --git a/styles/src/component/text_button.ts b/styles/src/component/text_button.ts index 68ec01c92bf1ba12907675dbd4ee87a4f51e4b9c..58b2a1cbf2ff31a8e4fc50b9e1165bca78ec6b4a 100644 --- a/styles/src/component/text_button.ts +++ b/styles/src/component/text_button.ts @@ -9,7 +9,10 @@ import { useTheme, Theme } from "../theme" import { Margin } from "./icon_button" interface TextButtonOptions { - layer?: Theme["lowest"] | Theme["middle"] | Theme["highest"] + layer?: + | Theme["lowest"] + | Theme["middle"] + | Theme["highest"] color?: keyof Theme["lowest"] margin?: Partial text_properties?: TextProperties diff --git a/styles/src/style_tree/app.ts b/styles/src/style_tree/app.ts index ee0aa133a04bd35202d381835e257ddca2b284cc..ccfdd60a981f4d5e763ce35902b0456bf0d703cd 100644 --- a/styles/src/style_tree/app.ts +++ b/styles/src/style_tree/app.ts @@ -57,6 +57,6 @@ export default function app(): any { tooltip: tooltip(), terminal: terminal(), assistant: assistant(), - feedback: feedback(), + feedback: feedback() } } diff --git a/styles/src/style_tree/assistant.ts b/styles/src/style_tree/assistant.ts index 7df5434f91010f778d47dfc9170ef80b909df0cf..cfc1f8d813648654a8fee608ea4d00dc30893b75 100644 --- a/styles/src/style_tree/assistant.ts +++ b/styles/src/style_tree/assistant.ts @@ -8,48 +8,50 @@ type RoleCycleButton = TextStyle & { } // TODO: Replace these with zed types type RemainingTokens = TextStyle & { - background: string - margin: { top: number; right: number } + background: string, + margin: { top: number, right: number }, padding: { - right: number - left: number - top: number - bottom: number - } - corner_radius: number + right: number, + left: number, + top: number, + bottom: number, + }, + corner_radius: number, } export default function assistant(): any { const theme = useTheme() - const interactive_role = ( - color: StyleSets - ): Interactive => { - return interactive({ - base: { - ...text(theme.highest, "sans", color, { size: "sm" }), - }, - state: { - hovered: { + const interactive_role = (color: StyleSets): Interactive => { + return ( + interactive({ + base: { ...text(theme.highest, "sans", color, { size: "sm" }), - background: background(theme.highest, color, "hovered"), }, - clicked: { - ...text(theme.highest, "sans", color, { size: "sm" }), - background: background(theme.highest, color, "pressed"), + state: { + hovered: { + ...text(theme.highest, "sans", color, { size: "sm" }), + background: background(theme.highest, color, "hovered"), + }, + clicked: { + ...text(theme.highest, "sans", color, { size: "sm" }), + background: background(theme.highest, color, "pressed"), + } }, - }, - }) + }) + ) } const tokens_remaining = (color: StyleSets): RemainingTokens => { - return { - ...text(theme.highest, "mono", color, { size: "xs" }), - background: background(theme.highest, "on", "default"), - margin: { top: 12, right: 20 }, - padding: { right: 4, left: 4, top: 1, bottom: 1 }, - corner_radius: 6, - } + return ( + { + ...text(theme.highest, "mono", color, { size: "xs" }), + background: background(theme.highest, "on", "default"), + margin: { top: 12, right: 20 }, + padding: { right: 4, left: 4, top: 1, bottom: 1 }, + corner_radius: 6, + } + ) } return { @@ -91,10 +93,7 @@ export default function assistant(): any { base: { background: background(theme.middle), padding: { top: 4, bottom: 4 }, - border: border(theme.middle, "default", { - top: true, - overlay: true, - }), + border: border(theme.middle, "default", { top: true, overlay: true }), }, state: { hovered: { @@ -102,7 +101,7 @@ export default function assistant(): any { }, clicked: { background: background(theme.middle, "pressed"), - }, + } }, }), saved_at: { diff --git a/styles/src/style_tree/editor.ts b/styles/src/style_tree/editor.ts index deab45d4b21df8b7d130479c277ed317ba78d8d4..9ad008f38d4dd928af5b49c46b148df575b1c6a3 100644 --- a/styles/src/style_tree/editor.ts +++ b/styles/src/style_tree/editor.ts @@ -9,9 +9,9 @@ import { } from "./components" import hover_popover from "./hover_popover" +import { build_syntax } from "../theme/syntax" import { interactive, toggleable } from "../element" import { useTheme } from "../theme" -import chroma from "chroma-js" export default function editor(): any { const theme = useTheme() @@ -48,28 +48,16 @@ export default function editor(): any { } } + const syntax = build_syntax() + return { - text_color: theme.syntax.primary.color, + text_color: syntax.primary.color, background: background(layer), active_line_background: with_opacity(background(layer, "on"), 0.75), highlighted_line_background: background(layer, "on"), // Inline autocomplete suggestions, Co-pilot suggestions, etc. - hint: chroma - .mix( - theme.ramps.neutral(0.6).hex(), - theme.ramps.blue(0.4).hex(), - 0.45, - "lch" - ) - .hex(), - suggestion: chroma - .mix( - theme.ramps.neutral(0.4).hex(), - theme.ramps.blue(0.4).hex(), - 0.45, - "lch" - ) - .hex(), + hint: syntax.hint, + suggestion: syntax.predictive, code_actions: { indicator: toggleable({ base: interactive({ @@ -267,8 +255,8 @@ export default function editor(): any { invalid_warning_diagnostic: diagnostic(theme.middle, "base"), hover_popover: hover_popover(), link_definition: { - color: theme.syntax.link_uri.color, - underline: theme.syntax.link_uri.underline, + color: syntax.link_uri.color, + underline: syntax.link_uri.underline, }, jump_icon: interactive({ base: { @@ -318,7 +306,7 @@ export default function editor(): any { ? with_opacity(theme.ramps.green(0.5).hex(), 0.8) : with_opacity(theme.ramps.green(0.4).hex(), 0.8), }, - selections: foreground(layer, "accent"), + selections: foreground(layer, "accent") }, composition_mark: { underline: { @@ -326,6 +314,6 @@ export default function editor(): any { color: border_color(layer), }, }, - syntax: theme.syntax, + syntax, } } diff --git a/styles/src/style_tree/feedback.ts b/styles/src/style_tree/feedback.ts index 0349359533041d4425df3d0c72d120ed18499a30..b1bd96e165466521804f86d547664c209c7c4671 100644 --- a/styles/src/style_tree/feedback.ts +++ b/styles/src/style_tree/feedback.ts @@ -37,7 +37,7 @@ export default function feedback(): any { ...text(theme.highest, "mono", "on", "disabled"), background: background(theme.highest, "on", "disabled"), border: border(theme.highest, "on", "disabled"), - }, + } }, }), button_margin: 8, diff --git a/styles/src/style_tree/picker.ts b/styles/src/style_tree/picker.ts index 317f600b1e2fca3f6b8756c3ba033fa22e6b0220..28ae85478794a22211dc67cb6ec56cce4bc805f1 100644 --- a/styles/src/style_tree/picker.ts +++ b/styles/src/style_tree/picker.ts @@ -152,7 +152,7 @@ export default function picker(): any { 0.5 ), }, - }, + } }), } } diff --git a/styles/src/style_tree/project_panel.ts b/styles/src/style_tree/project_panel.ts index 51958af145b50afd25510788ff0a530cc77a5a1d..e239f9a84023088d988f74e709c6485ade8a9510 100644 --- a/styles/src/style_tree/project_panel.ts +++ b/styles/src/style_tree/project_panel.ts @@ -64,17 +64,17 @@ export default function project_panel(): any { const unselected_default_style = merge( base_properties, unselected?.default ?? {}, - {} + {}, ) const unselected_hovered_style = merge( base_properties, { background: background(theme.middle, "hovered") }, - unselected?.hovered ?? {} + unselected?.hovered ?? {}, ) const unselected_clicked_style = merge( base_properties, { background: background(theme.middle, "pressed") }, - unselected?.clicked ?? {} + unselected?.clicked ?? {}, ) const selected_default_style = merge( base_properties, @@ -82,7 +82,7 @@ export default function project_panel(): any { background: background(theme.lowest), text: text(theme.lowest, "sans", { size: "sm" }), }, - selected_style?.default ?? {} + selected_style?.default ?? {}, ) const selected_hovered_style = merge( base_properties, @@ -90,7 +90,7 @@ export default function project_panel(): any { background: background(theme.lowest, "hovered"), text: text(theme.lowest, "sans", { size: "sm" }), }, - selected_style?.hovered ?? {} + selected_style?.hovered ?? {}, ) const selected_clicked_style = merge( base_properties, @@ -98,7 +98,7 @@ export default function project_panel(): any { background: background(theme.lowest, "pressed"), text: text(theme.lowest, "sans", { size: "sm" }), }, - selected_style?.clicked ?? {} + selected_style?.clicked ?? {}, ) return toggleable({ @@ -175,7 +175,7 @@ export default function project_panel(): any { default: { icon_color: foreground(theme.middle, "variant"), }, - } + }, ), cut_entry: entry( { @@ -190,7 +190,7 @@ export default function project_panel(): any { size: "sm", }), }, - } + }, ), filename_editor: { background: background(theme.middle, "on"), diff --git a/styles/src/style_tree/status_bar.ts b/styles/src/style_tree/status_bar.ts index 45baf4e87122d73779a3b5100909cfa53e3d87ed..6261939994ac4e7ae7e06090912218d5dcfb7f54 100644 --- a/styles/src/style_tree/status_bar.ts +++ b/styles/src/style_tree/status_bar.ts @@ -34,14 +34,10 @@ export default function status_bar(): any { ...text(layer, "mono", "variant", { size: "xs" }), }, active_language: text_button({ - color: "variant", - }), - auto_update_progress_message: text(layer, "sans", "variant", { - size: "xs", - }), - auto_update_done_message: text(layer, "sans", "variant", { - size: "xs", + color: "variant" }), + auto_update_progress_message: text(layer, "sans", "variant", { size: "xs" }), + auto_update_done_message: text(layer, "sans", "variant", { size: "xs" }), lsp_status: interactive({ base: { ...diagnostic_status_container, diff --git a/styles/src/style_tree/titlebar.ts b/styles/src/style_tree/titlebar.ts index fe0c53e87dac61bdfc93688eea13e74d583017a9..177a8c5bd8db0fa2290eda5e25c4160531d81e4b 100644 --- a/styles/src/style_tree/titlebar.ts +++ b/styles/src/style_tree/titlebar.ts @@ -183,10 +183,10 @@ export function titlebar(): any { project_name_divider: text(theme.lowest, "sans", "variant"), project_menu_button: toggleable_text_button(theme, { - color: "base", + color: 'base', }), git_menu_button: toggleable_text_button(theme, { - color: "variant", + color: 'variant', }), // Collaborators diff --git a/styles/src/theme/create_theme.ts b/styles/src/theme/create_theme.ts index 6df36d7077b934f2acc45f21422159872c6f551a..d2701f8341af973a3a4511c149c983cb221fa14d 100644 --- a/styles/src/theme/create_theme.ts +++ b/styles/src/theme/create_theme.ts @@ -1,28 +1,28 @@ import { Scale, Color } from "chroma-js" +import { Syntax, ThemeSyntax, SyntaxHighlightStyle } from "./syntax" +export { Syntax, ThemeSyntax, SyntaxHighlightStyle } import { ThemeConfig, ThemeAppearance, ThemeConfigInputColors, } from "./theme_config" import { get_ramps } from "./ramps" -import { syntaxStyle } from "./syntax" -import { Syntax } from "../types/syntax" export interface Theme { name: string is_light: boolean /** - * App background, other elements that should sit directly on top of the background. - */ + * App background, other elements that should sit directly on top of the background. + */ lowest: Layer /** - * Panels, tabs, other UI surfaces that sit on top of the background. - */ + * Panels, tabs, other UI surfaces that sit on top of the background. + */ middle: Layer /** - * Editors like code buffers, conversation editors, etc. - */ + * Editors like code buffers, conversation editors, etc. + */ highest: Layer ramps: RampSet @@ -31,7 +31,7 @@ export interface Theme { modal_shadow: Shadow players: Players - syntax: Syntax + syntax?: Partial } export interface Meta { @@ -115,7 +115,12 @@ export interface Style { } export function create_theme(theme: ThemeConfig): Theme { - const { name, appearance, input_color } = theme + const { + name, + appearance, + input_color, + override: { syntax }, + } = theme const is_light = appearance === ThemeAppearance.Light const color_ramps: ThemeConfigInputColors = input_color @@ -157,11 +162,6 @@ export function create_theme(theme: ThemeConfig): Theme { "7": player(ramps.yellow), } - const syntax = syntaxStyle( - ramps, - theme.override.syntax ? theme.override.syntax : {} - ) - return { name, is_light, diff --git a/styles/src/theme/syntax.ts b/styles/src/theme/syntax.ts index db8f98de663bcb3afa8e84ea851363a3f83cbd0c..540a1d0ff9822d5a8c2cf292ddba5ace6839ac6d 100644 --- a/styles/src/theme/syntax.ts +++ b/styles/src/theme/syntax.ts @@ -1,45 +1,325 @@ import deepmerge from "deepmerge" -import { font_weights, ThemeConfigInputSyntax, RampSet } from "../common" -import { Syntax, SyntaxHighlightStyle, allSyntaxKeys } from "../types/syntax" - -// Apply defaults to any missing syntax properties that are not defined manually -function apply_defaults( - ramps: RampSet, - syntax_highlights: Partial -): Syntax { - const restKeys: (keyof Syntax)[] = allSyntaxKeys.filter( - (key) => !syntax_highlights[key] - ) +import { FontWeight, font_weights, useTheme } from "../common" +import chroma from "chroma-js" - const completeSyntax: Syntax = {} as Syntax +export interface SyntaxHighlightStyle { + color?: string + weight?: FontWeight + underline?: boolean + italic?: boolean +} - const defaults: SyntaxHighlightStyle = { - color: ramps.neutral(1).hex(), - } +export interface Syntax { + // == Text Styles ====== / + comment: SyntaxHighlightStyle + // elixir: doc comment + "comment.doc": SyntaxHighlightStyle + primary: SyntaxHighlightStyle + predictive: SyntaxHighlightStyle + hint: SyntaxHighlightStyle - for (const key of restKeys) { - { - completeSyntax[key] = { - ...defaults, - } + // === Formatted Text ====== / + emphasis: SyntaxHighlightStyle + "emphasis.strong": SyntaxHighlightStyle + title: SyntaxHighlightStyle + link_uri: SyntaxHighlightStyle + link_text: SyntaxHighlightStyle + /** md: indented_code_block, fenced_code_block, code_span */ + "text.literal": SyntaxHighlightStyle + + // == Punctuation ====== / + punctuation: SyntaxHighlightStyle + /** Example: `(`, `[`, `{`...*/ + "punctuation.bracket": SyntaxHighlightStyle + /**., ;*/ + "punctuation.delimiter": SyntaxHighlightStyle + // js, ts: ${, } in a template literal + // yaml: *, &, ---, ... + "punctuation.special": SyntaxHighlightStyle + // md: list_marker_plus, list_marker_dot, etc + "punctuation.list_marker": SyntaxHighlightStyle + + // == Strings ====== / + + string: SyntaxHighlightStyle + // css: color_value + // js: this, super + // toml: offset_date_time, local_date_time... + "string.special": SyntaxHighlightStyle + // elixir: atom, quoted_atom, keyword, quoted_keyword + // ruby: simple_symbol, delimited_symbol... + "string.special.symbol"?: SyntaxHighlightStyle + // elixir, python, yaml...: escape_sequence + "string.escape"?: SyntaxHighlightStyle + // Regular expressions + "string.regex"?: SyntaxHighlightStyle + + // == Types ====== / + // We allow Function here because all JS objects literals have this property + constructor: SyntaxHighlightStyle | Function // eslint-disable-line @typescript-eslint/ban-types + variant: SyntaxHighlightStyle + type: SyntaxHighlightStyle + // js: predefined_type + "type.builtin"?: SyntaxHighlightStyle + + // == Values + variable: SyntaxHighlightStyle + // this, ... + // css: -- (var(--foo)) + // lua: self + "variable.special"?: SyntaxHighlightStyle + // c: statement_identifier, + label: SyntaxHighlightStyle + // css: tag_name, nesting_selector, universal_selector... + tag: SyntaxHighlightStyle + // css: attribute, pseudo_element_selector (tag_name), + attribute: SyntaxHighlightStyle + // css: class_name, property_name, namespace_name... + property: SyntaxHighlightStyle + // true, false, null, nullptr + constant: SyntaxHighlightStyle + // css: @media, @import, @supports... + // js: declare, implements, interface, keyof, public... + keyword: SyntaxHighlightStyle + // note: js enum is currently defined as a keyword + enum: SyntaxHighlightStyle + // -, --, ->, !=, &&, ||, <=... + operator: SyntaxHighlightStyle + number: SyntaxHighlightStyle + boolean: SyntaxHighlightStyle + // elixir: __MODULE__, __DIR__, __ENV__, etc + // go: nil, iota + "constant.builtin"?: SyntaxHighlightStyle + + // == Functions ====== / + + function: SyntaxHighlightStyle + // lua: assert, error, loadfile, tostring, unpack... + "function.builtin"?: SyntaxHighlightStyle + // go: call_expression, method_declaration + // js: call_expression, method_definition, pair (key, arrow function) + // rust: function_item name: (identifier) + "function.definition"?: SyntaxHighlightStyle + // rust: macro_definition name: (identifier) + "function.special.definition"?: SyntaxHighlightStyle + "function.method"?: SyntaxHighlightStyle + // ruby: identifier/"defined?" // Nate note: I don't fully understand this one. + "function.method.builtin"?: SyntaxHighlightStyle + + // == Unsorted ====== / + // lua: hash_bang_line + preproc: SyntaxHighlightStyle + // elixir, python: interpolation (ex: foo in ${foo}) + // js: template_substitution + embedded: SyntaxHighlightStyle +} + +export type ThemeSyntax = Partial + +const default_syntax_highlight_style: Omit = { + weight: "normal", + underline: false, + italic: false, +} + +function build_default_syntax(): Syntax { + const theme = useTheme() + + // Make a temporary object that is allowed to be missing + // the "color" property for each style + const syntax: { + [key: string]: Omit + } = {} + + // then spread the default to each style + for (const key of Object.keys({} as Syntax)) { + syntax[key as keyof Syntax] = { + ...default_syntax_highlight_style, } } - const mergedBaseSyntax = Object.assign(completeSyntax, syntax_highlights) + // Mix the neutral and blue colors to get a + // predictive color distinct from any other color in the theme + const predictive = chroma + .mix( + theme.ramps.neutral(0.4).hex(), + theme.ramps.blue(0.4).hex(), + 0.45, + "lch" + ) + .hex() + // Mix the neutral and green colors to get a + // hint color distinct from any other color in the theme + const hint = chroma + .mix( + theme.ramps.neutral(0.6).hex(), + theme.ramps.blue(0.4).hex(), + 0.45, + "lch" + ) + .hex() - return mergedBaseSyntax + const color = { + primary: theme.ramps.neutral(1).hex(), + comment: theme.ramps.neutral(0.71).hex(), + punctuation: theme.ramps.neutral(0.86).hex(), + predictive: predictive, + hint: hint, + emphasis: theme.ramps.blue(0.5).hex(), + string: theme.ramps.orange(0.5).hex(), + function: theme.ramps.yellow(0.5).hex(), + type: theme.ramps.cyan(0.5).hex(), + constructor: theme.ramps.blue(0.5).hex(), + variant: theme.ramps.blue(0.5).hex(), + property: theme.ramps.blue(0.5).hex(), + enum: theme.ramps.orange(0.5).hex(), + operator: theme.ramps.orange(0.5).hex(), + number: theme.ramps.green(0.5).hex(), + boolean: theme.ramps.green(0.5).hex(), + constant: theme.ramps.green(0.5).hex(), + keyword: theme.ramps.blue(0.5).hex(), + } + + // Then assign colors and use Syntax to enforce each style getting it's own color + const default_syntax: Syntax = { + ...syntax, + comment: { + color: color.comment, + }, + "comment.doc": { + color: color.comment, + }, + primary: { + color: color.primary, + }, + predictive: { + color: color.predictive, + italic: true, + }, + hint: { + color: color.hint, + weight: font_weights.bold, + }, + emphasis: { + color: color.emphasis, + }, + "emphasis.strong": { + color: color.emphasis, + weight: font_weights.bold, + }, + title: { + color: color.primary, + weight: font_weights.bold, + }, + link_uri: { + color: theme.ramps.green(0.5).hex(), + underline: true, + }, + link_text: { + color: theme.ramps.orange(0.5).hex(), + italic: true, + }, + "text.literal": { + color: color.string, + }, + punctuation: { + color: color.punctuation, + }, + "punctuation.bracket": { + color: color.punctuation, + }, + "punctuation.delimiter": { + color: color.punctuation, + }, + "punctuation.special": { + color: theme.ramps.neutral(0.86).hex(), + }, + "punctuation.list_marker": { + color: color.punctuation, + }, + string: { + color: color.string, + }, + "string.special": { + color: color.string, + }, + "string.special.symbol": { + color: color.string, + }, + "string.escape": { + color: color.comment, + }, + "string.regex": { + color: color.string, + }, + constructor: { + color: theme.ramps.blue(0.5).hex(), + }, + variant: { + color: theme.ramps.blue(0.5).hex(), + }, + type: { + color: color.type, + }, + variable: { + color: color.primary, + }, + label: { + color: theme.ramps.blue(0.5).hex(), + }, + tag: { + color: theme.ramps.blue(0.5).hex(), + }, + attribute: { + color: theme.ramps.blue(0.5).hex(), + }, + property: { + color: theme.ramps.blue(0.5).hex(), + }, + constant: { + color: color.constant, + }, + keyword: { + color: color.keyword, + }, + enum: { + color: color.enum, + }, + operator: { + color: color.operator, + }, + number: { + color: color.number, + }, + boolean: { + color: color.boolean, + }, + function: { + color: color.function, + }, + preproc: { + color: color.primary, + }, + embedded: { + color: color.primary, + }, + } + + return default_syntax } -// Merge the base syntax with the theme syntax overrides -// This is a deep merge, so any nested properties will be merged as well -// This allows for a theme to only override a single property of a syntax highlight style -const merge_syntax = ( - baseSyntax: Syntax, - theme_syntax_overrides: ThemeConfigInputSyntax -): Syntax => { - return deepmerge( - baseSyntax, - theme_syntax_overrides, +export function build_syntax(): Syntax { + const theme = useTheme() + + const default_syntax: Syntax = build_default_syntax() + + if (!theme.syntax) { + return default_syntax + } + + const syntax = deepmerge>( + default_syntax, + theme.syntax, { arrayMerge: (destinationArray, sourceArray) => [ ...destinationArray, @@ -47,49 +327,6 @@ const merge_syntax = ( ], } ) -} - -/** Returns a complete Syntax object of the combined styles of a theme's syntax overrides and the default syntax styles */ -export const syntaxStyle = ( - ramps: RampSet, - theme_syntax_overrides: ThemeConfigInputSyntax -): Syntax => { - const syntax_highlights: Partial = { - comment: { color: ramps.neutral(0.71).hex() }, - "comment.doc": { color: ramps.neutral(0.71).hex() }, - primary: { color: ramps.neutral(1).hex() }, - emphasis: { color: ramps.blue(0.5).hex() }, - "emphasis.strong": { - color: ramps.blue(0.5).hex(), - weight: font_weights.bold, - }, - link_uri: { color: ramps.green(0.5).hex(), underline: true }, - link_text: { color: ramps.orange(0.5).hex(), italic: true }, - "text.literal": { color: ramps.orange(0.5).hex() }, - punctuation: { color: ramps.neutral(0.86).hex() }, - "punctuation.bracket": { color: ramps.neutral(0.86).hex() }, - "punctuation.special": { color: ramps.neutral(0.86).hex() }, - "punctuation.delimiter": { color: ramps.neutral(0.86).hex() }, - "punctuation.list_marker": { color: ramps.neutral(0.86).hex() }, - string: { color: ramps.orange(0.5).hex() }, - "string.special": { color: ramps.orange(0.5).hex() }, - "string.special.symbol": { color: ramps.orange(0.5).hex() }, - "string.escape": { color: ramps.neutral(0.71).hex() }, - "string.regex": { color: ramps.orange(0.5).hex() }, - "method.constructor": { color: ramps.blue(0.5).hex() }, - type: { color: ramps.cyan(0.5).hex() }, - label: { color: ramps.blue(0.5).hex() }, - attribute: { color: ramps.blue(0.5).hex() }, - property: { color: ramps.blue(0.5).hex() }, - constant: { color: ramps.green(0.5).hex() }, - keyword: { color: ramps.blue(0.5).hex() }, - operator: { color: ramps.orange(0.5).hex() }, - number: { color: ramps.green(0.5).hex() }, - boolean: { color: ramps.green(0.5).hex() }, - function: { color: ramps.yellow(0.5).hex() }, - } - const baseSyntax = apply_defaults(ramps, syntax_highlights) - const mergedSyntax = merge_syntax(baseSyntax, theme_syntax_overrides) - return mergedSyntax + return syntax } diff --git a/styles/src/theme/theme_config.ts b/styles/src/theme/theme_config.ts index f5f83590743278508ba16b7245c2e7fc8e4d2650..bc8f07425f9e676a27d36ec929ea9a116006c694 100644 --- a/styles/src/theme/theme_config.ts +++ b/styles/src/theme/theme_config.ts @@ -1,5 +1,5 @@ import { Scale, Color } from "chroma-js" -import { SyntaxHighlightStyle, SyntaxProperty } from "../types/syntax" +import { Syntax } from "./syntax" interface ThemeMeta { /** The name of the theme */ @@ -55,9 +55,7 @@ export type ThemeConfigInputColorsKeys = keyof ThemeConfigInputColors * } * ``` */ -export type ThemeConfigInputSyntax = Partial< - Record> -> +export type ThemeConfigInputSyntax = Partial interface ThemeConfigOverrides { syntax: ThemeConfigInputSyntax diff --git a/styles/src/theme/tokens/theme.ts b/styles/src/theme/tokens/theme.ts index d93079366961a1079df0858ceef980a0b9b59aec..f759bc813910416d88a2097134dc95654d6ab3b3 100644 --- a/styles/src/theme/tokens/theme.ts +++ b/styles/src/theme/tokens/theme.ts @@ -4,13 +4,17 @@ import { SingleOtherToken, TokenTypes, } from "@tokens-studio/types" -import { Shadow } from "../create_theme" +import { + Shadow, + SyntaxHighlightStyle, + ThemeSyntax, +} from "../create_theme" import { LayerToken, layer_token } from "./layer" import { PlayersToken, players_token } from "./players" import { color_token } from "./token" +import { Syntax } from "../syntax" import editor from "../../style_tree/editor" import { useTheme } from "../../../src/common" -import { Syntax, SyntaxHighlightStyle } from "../../types/syntax" interface ThemeTokens { name: SingleOtherToken @@ -47,7 +51,7 @@ const modal_shadow_token = (): SingleBoxShadowToken => { return create_shadow_token(shadow, "modal_shadow") } -type ThemeSyntaxColorTokens = Record +type ThemeSyntaxColorTokens = Record function syntax_highlight_style_color_tokens( syntax: Syntax diff --git a/styles/src/themes/atelier/common.ts b/styles/src/themes/atelier/common.ts index 9a0029581c565b0eb820e7bc8686f62e5e3627b2..b76ccc5b607a2f149a35114a519ddaaf2d1b254d 100644 --- a/styles/src/themes/atelier/common.ts +++ b/styles/src/themes/atelier/common.ts @@ -1,8 +1,4 @@ -import { - ThemeLicenseType, - ThemeFamilyMeta, - ThemeConfigInputSyntax, -} from "../../common" +import { ThemeLicenseType, ThemeSyntax, ThemeFamilyMeta } from "../../common" export interface Variant { colors: { @@ -33,7 +29,7 @@ export const meta: ThemeFamilyMeta = { "https://atelierbram.github.io/syntax-highlighting/atelier-schemes/cave/", } -export const build_syntax = (variant: Variant): ThemeConfigInputSyntax => { +export const build_syntax = (variant: Variant): ThemeSyntax => { const { colors } = variant return { primary: { color: colors.base06 }, @@ -54,6 +50,7 @@ export const build_syntax = (variant: Variant): ThemeConfigInputSyntax => { property: { color: colors.base08 }, variable: { color: colors.base06 }, "variable.special": { color: colors.base0E }, + variant: { color: colors.base0A }, keyword: { color: colors.base0E }, } } diff --git a/styles/src/themes/ayu/common.ts b/styles/src/themes/ayu/common.ts index 870445588646b57f347fe9e90e07b286b3b73790..2bd0bbf259aef2d9fc6c084f1da3c72379927026 100644 --- a/styles/src/themes/ayu/common.ts +++ b/styles/src/themes/ayu/common.ts @@ -3,8 +3,8 @@ import { chroma, color_ramp, ThemeLicenseType, + ThemeSyntax, ThemeFamilyMeta, - ThemeConfigInputSyntax, } from "../../common" export const ayu = { @@ -27,7 +27,7 @@ export const build_theme = (t: typeof dark, light: boolean) => { purple: t.syntax.constant.hex(), } - const syntax: ThemeConfigInputSyntax = { + const syntax: ThemeSyntax = { constant: { color: t.syntax.constant.hex() }, "string.regex": { color: t.syntax.regexp.hex() }, string: { color: t.syntax.string.hex() }, @@ -61,7 +61,7 @@ export const build_theme = (t: typeof dark, light: boolean) => { } } -export const build_syntax = (t: typeof dark): ThemeConfigInputSyntax => { +export const build_syntax = (t: typeof dark): ThemeSyntax => { return { constant: { color: t.syntax.constant.hex() }, "string.regex": { color: t.syntax.regexp.hex() }, diff --git a/styles/src/themes/gruvbox/gruvbox-common.ts b/styles/src/themes/gruvbox/gruvbox-common.ts index 95e45efa95122ec3ca37d2dc57360ca55ec83e85..2fa6b58faadb91b5689c5eac93baf706f6faa391 100644 --- a/styles/src/themes/gruvbox/gruvbox-common.ts +++ b/styles/src/themes/gruvbox/gruvbox-common.ts @@ -4,8 +4,8 @@ import { ThemeAppearance, ThemeLicenseType, ThemeConfig, + ThemeSyntax, ThemeFamilyMeta, - ThemeConfigInputSyntax, } from "../../common" const meta: ThemeFamilyMeta = { @@ -214,7 +214,7 @@ const build_variant = (variant: Variant): ThemeConfig => { magenta: color_ramp(chroma(variant.colors.gray)), } - const syntax: ThemeConfigInputSyntax = { + const syntax: ThemeSyntax = { primary: { color: neutral[is_light ? 0 : 8] }, "text.literal": { color: colors.blue }, comment: { color: colors.gray }, @@ -229,7 +229,7 @@ const build_variant = (variant: Variant): ThemeConfig => { "string.special.symbol": { color: colors.aqua }, "string.regex": { color: colors.orange }, type: { color: colors.yellow }, - // enum: { color: colors.orange }, + enum: { color: colors.orange }, tag: { color: colors.aqua }, constant: { color: colors.yellow }, keyword: { color: colors.red }, diff --git a/styles/src/themes/one/one-dark.ts b/styles/src/themes/one/one-dark.ts index 97f3922f36f57c7452c8face077a8b2bc8997858..f672b892ee040e60745f3d0f8bd6875c743ed46a 100644 --- a/styles/src/themes/one/one-dark.ts +++ b/styles/src/themes/one/one-dark.ts @@ -54,6 +54,7 @@ export const theme: ThemeConfig = { syntax: { boolean: { color: color.orange }, comment: { color: color.grey }, + enum: { color: color.red }, "emphasis.strong": { color: color.orange }, function: { color: color.blue }, keyword: { color: color.purple }, @@ -72,7 +73,8 @@ export const theme: ThemeConfig = { "text.literal": { color: color.green }, type: { color: color.teal }, "variable.special": { color: color.orange }, - "method.constructor": { color: color.blue }, + variant: { color: color.blue }, + constructor: { color: color.blue }, }, }, } diff --git a/styles/src/themes/one/one-light.ts b/styles/src/themes/one/one-light.ts index 655428757898a7f07f4524377721ab62ef1f5b53..c3de7826c96679fb1c1f2b1a9d81324687d919b9 100644 --- a/styles/src/themes/one/one-light.ts +++ b/styles/src/themes/one/one-light.ts @@ -55,6 +55,7 @@ export const theme: ThemeConfig = { syntax: { boolean: { color: color.orange }, comment: { color: color.grey }, + enum: { color: color.red }, "emphasis.strong": { color: color.orange }, function: { color: color.blue }, keyword: { color: color.purple }, @@ -72,6 +73,7 @@ export const theme: ThemeConfig = { "text.literal": { color: color.green }, type: { color: color.teal }, "variable.special": { color: color.orange }, + variant: { color: color.blue }, }, }, } diff --git a/styles/src/themes/rose-pine/common.ts b/styles/src/themes/rose-pine/common.ts index decccc0a6dc8b1062ec8d5a88a699350a79bf322..5c5482a754a634bd2338af2613327554ec36d13c 100644 --- a/styles/src/themes/rose-pine/common.ts +++ b/styles/src/themes/rose-pine/common.ts @@ -1,4 +1,4 @@ -import { ThemeConfigInputSyntax } from "../../common" +import { ThemeSyntax } from "../../common" export const color = { default: { @@ -54,7 +54,7 @@ export const color = { }, } -export const syntax = (c: typeof color.default): ThemeConfigInputSyntax => { +export const syntax = (c: typeof color.default): Partial => { return { comment: { color: c.muted }, operator: { color: c.pine }, diff --git a/styles/src/types/extract_syntax_types.ts b/styles/src/types/extract_syntax_types.ts deleted file mode 100644 index eb21d2418b9c830099cffc0c03f9ecf4c88ba7ed..0000000000000000000000000000000000000000 --- a/styles/src/types/extract_syntax_types.ts +++ /dev/null @@ -1,111 +0,0 @@ -import fs from "fs" -import path from "path" -import readline from "readline" - -function escapeTypeName(name: string): string { - return `'${name.replace("@", "").toLowerCase()}'` -} - -const generatedNote = `// This file is generated by extract_syntax_types.ts -// Do not edit this file directly -// It is generated from the highlight.scm files in the zed crate - -// To regenerate this file manually: -// 'npm run extract-syntax-types' from ./styles` - -const defaultTextProperty = ` /** Default text color */ - | 'primary'` - -const main = async () => { - const pathFromRoot = "crates/zed/src/languages" - const directoryPath = path.join(__dirname, "../../../", pathFromRoot) - const stylesMap: Record> = {} - const propertyLanguageMap: Record> = {} - - const processFile = async (filePath: string, language: string) => { - const fileStream = fs.createReadStream(filePath) - const rl = readline.createInterface({ - input: fileStream, - crlfDelay: Infinity, - }) - - for await (const line of rl) { - const cleanedLine = line.replace(/"@[a-zA-Z0-9_.]*"/g, "") - const match = cleanedLine.match(/@(\w+\.*)*/g) - if (match) { - match.forEach((property) => { - const formattedProperty = escapeTypeName(property) - // Only add non-empty properties - if (formattedProperty !== "''") { - if (!propertyLanguageMap[formattedProperty]) { - propertyLanguageMap[formattedProperty] = new Set() - } - propertyLanguageMap[formattedProperty].add(language) - } - }) - } - } - } - - const directories = fs - .readdirSync(directoryPath, { withFileTypes: true }) - .filter((dirent) => dirent.isDirectory()) - .map((dirent) => dirent.name) - - for (const dir of directories) { - const highlightsFilePath = path.join( - directoryPath, - dir, - "highlights.scm" - ) - if (fs.existsSync(highlightsFilePath)) { - await processFile(highlightsFilePath, dir) - } - } - - for (const [language, properties] of Object.entries(stylesMap)) { - console.log(`${language}: ${Array.from(properties).join(", ")}`) - } - - const sortedProperties = Object.entries(propertyLanguageMap).sort( - ([propA], [propB]) => propA.localeCompare(propB) - ) - - const outStream = fs.createWriteStream(path.join(__dirname, "syntax.ts")) - let allProperties = "" - const syntaxKeys = [] - for (const [property, languages] of sortedProperties) { - let languagesArray = Array.from(languages) - const moreThanSeven = languagesArray.length > 7 - // Limit to the first 7 languages, append "..." if more than 7 - languagesArray = languagesArray.slice(0, 7) - if (moreThanSeven) { - languagesArray.push("...") - } - const languagesString = languagesArray.join(", ") - const comment = `/** ${languagesString} */` - allProperties += ` ${comment}\n | ${property} \n` - syntaxKeys.push(property) - } - outStream.write(`${generatedNote} - -export type SyntaxHighlightStyle = { - color: string, - fade_out?: number, - italic?: boolean, - underline?: boolean, - weight?: string, -} - -export type Syntax = Record -export type SyntaxOverride = Partial - -export type SyntaxProperty = \n${defaultTextProperty}\n\n${allProperties} - -export const allSyntaxKeys: SyntaxProperty[] = [\n ${syntaxKeys.join( - ",\n " - )}\n]`) - outStream.end() -} - -main().catch(console.error) diff --git a/styles/src/types/syntax.ts b/styles/src/types/syntax.ts deleted file mode 100644 index 9b23dbde3cc799090e1dd848706f2b96a88e7ba6..0000000000000000000000000000000000000000 --- a/styles/src/types/syntax.ts +++ /dev/null @@ -1,202 +0,0 @@ -// This file is generated by extract_syntax_types.ts -// Do not edit this file directly -// It is generated from the highlight.scm files in the zed crate - -// To regenerate this file manually: -// 'npm run extract-syntax-types' from ./styles - -export type SyntaxHighlightStyle = { - color: string - fade_out?: number - italic?: boolean - underline?: boolean - weight?: string -} - -export type Syntax = Record -export type SyntaxOverride = Partial - -export type SyntaxProperty = - /** Default text color */ - | "primary" - - /** elixir */ - | "__attribute__" - /** elixir */ - | "__name__" - /** elixir */ - | "_sigil_name" - /** css, heex, lua */ - | "attribute" - /** javascript, lua, tsx, typescript, yaml */ - | "boolean" - /** elixir */ - | "comment.doc" - /** elixir */ - | "comment.unused" - /** bash, c, cpp, css, elixir, elm, erb, ... */ - | "comment" - /** elixir, go, javascript, lua, php, python, racket, ... */ - | "constant.builtin" - /** bash, c, cpp, elixir, elm, glsl, heex, ... */ - | "constant" - /** glsl */ - | "delimiter" - /** bash, elixir, javascript, python, ruby, tsx, typescript */ - | "embedded" - /** markdown */ - | "emphasis.strong" - /** markdown */ - | "emphasis" - /** go, python, racket, ruby, scheme */ - | "escape" - /** lua */ - | "field" - /** lua, php, python */ - | "function.builtin" - /** elm, lua, rust */ - | "function.definition" - /** ruby */ - | "function.method.builtin" - /** go, javascript, php, python, ruby, rust, tsx, ... */ - | "function.method" - /** rust */ - | "function.special.definition" - /** c, cpp, glsl, rust */ - | "function.special" - /** bash, c, cpp, css, elixir, elm, glsl, ... */ - | "function" - /** elm */ - | "identifier" - /** glsl */ - | "keyword.function" - /** bash, c, cpp, css, elixir, elm, erb, ... */ - | "keyword" - /** c, cpp, glsl */ - | "label" - /** markdown */ - | "link_text" - /** markdown */ - | "link_uri" - /** lua, php, tsx, typescript */ - | "method.constructor" - /** lua */ - | "method" - /** heex */ - | "module" - /** svelte */ - | "none" - /** bash, c, cpp, css, elixir, glsl, go, ... */ - | "number" - /** bash, c, cpp, css, elixir, elm, glsl, ... */ - | "operator" - /** lua */ - | "parameter" - /** lua */ - | "preproc" - /** bash, c, cpp, css, glsl, go, html, ... */ - | "property" - /** c, cpp, elixir, elm, heex, html, javascript, ... */ - | "punctuation.bracket" - /** c, cpp, css, elixir, elm, heex, javascript, ... */ - | "punctuation.delimiter" - /** markdown */ - | "punctuation.list_marker" - /** elixir, javascript, python, ruby, tsx, typescript, yaml */ - | "punctuation.special" - /** elixir */ - | "punctuation" - /** glsl */ - | "storageclass" - /** elixir, elm, yaml */ - | "string.escape" - /** elixir, javascript, racket, ruby, tsx, typescript */ - | "string.regex" - /** elixir, ruby */ - | "string.special.symbol" - /** css, elixir, toml */ - | "string.special" - /** bash, c, cpp, css, elixir, elm, glsl, ... */ - | "string" - /** svelte */ - | "tag.delimiter" - /** css, heex, php, svelte */ - | "tag" - /** markdown */ - | "text.literal" - /** markdown */ - | "title" - /** javascript, php, rust, tsx, typescript */ - | "type.builtin" - /** glsl */ - | "type.qualifier" - /** c, cpp, css, elixir, elm, glsl, go, ... */ - | "type" - /** glsl, php */ - | "variable.builtin" - /** cpp, css, javascript, lua, racket, ruby, rust, ... */ - | "variable.special" - /** c, cpp, elm, glsl, go, javascript, lua, ... */ - | "variable" - -export const allSyntaxKeys: SyntaxProperty[] = [ - "__attribute__", - "__name__", - "_sigil_name", - "attribute", - "boolean", - "comment.doc", - "comment.unused", - "comment", - "constant.builtin", - "constant", - "delimiter", - "embedded", - "emphasis.strong", - "emphasis", - "escape", - "field", - "function.builtin", - "function.definition", - "function.method.builtin", - "function.method", - "function.special.definition", - "function.special", - "function", - "identifier", - "keyword.function", - "keyword", - "label", - "link_text", - "link_uri", - "method.constructor", - "method", - "module", - "none", - "number", - "operator", - "parameter", - "preproc", - "property", - "punctuation.bracket", - "punctuation.delimiter", - "punctuation.list_marker", - "punctuation.special", - "punctuation", - "storageclass", - "string.escape", - "string.regex", - "string.special.symbol", - "string.special", - "string", - "tag.delimiter", - "tag", - "text.literal", - "title", - "type.builtin", - "type.qualifier", - "type", - "variable.builtin", - "variable.special", - "variable", -] diff --git a/styles/tsconfig.json b/styles/tsconfig.json index a1913027b705df7d349c78bcc6b74bb96851fe8c..281bd74b215bd16426bb6a8f9d68ddeb5a5bea43 100644 --- a/styles/tsconfig.json +++ b/styles/tsconfig.json @@ -24,5 +24,7 @@ "useUnknownInCatchVariables": false, "baseUrl": "." }, - "exclude": ["node_modules"] + "exclude": [ + "node_modules" + ] }