From 38888696db1ba85964b8f1e058075ac724c98eaa Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Mon, 13 Nov 2023 19:46:15 -0500 Subject: [PATCH 1/4] Allow a button to take a color --- crates/ui2/src/components/button.rs | 33 ++++++++++-------- crates/ui2/src/components/icon.rs | 44 ++++++++++++++++++++---- crates/ui2/src/components/icon_button.rs | 6 ++-- crates/ui2/src/components/label.rs | 36 ++++++++++++------- crates/workspace2/src/workspace2.rs | 26 +++++++++++--- 5 files changed, 104 insertions(+), 41 deletions(-) diff --git a/crates/ui2/src/components/button.rs b/crates/ui2/src/components/button.rs index 5787616832e354a501e1f2e10ddf6fec6e480bea..1418a977f1f1d9a0cd0085e3e42d932c4ad4ab4f 100644 --- a/crates/ui2/src/components/button.rs +++ b/crates/ui2/src/components/button.rs @@ -87,6 +87,7 @@ pub struct Button { label: SharedString, variant: ButtonVariant, width: Option, + color: Option, } impl Button { @@ -99,6 +100,7 @@ impl Button { label: label.into(), variant: Default::default(), width: Default::default(), + color: None, } } @@ -139,25 +141,24 @@ impl Button { self } - fn label_color(&self) -> LabelColor { - if self.disabled { - LabelColor::Disabled - } else { - Default::default() - } + pub fn color(mut self, color: Option) -> Self { + self.color = color; + self } - fn icon_color(&self) -> IconColor { + pub fn label_color(&self, color: Option) -> LabelColor { if self.disabled { - IconColor::Disabled + LabelColor::Disabled + } else if let Some(color) = color { + color } else { Default::default() } } - fn render_label(&self) -> Label { + fn render_label(&self, color: LabelColor) -> Label { Label::new(self.label.clone()) - .color(self.label_color()) + .color(color) .line_height_style(LineHeightStyle::UILabel) } @@ -166,7 +167,11 @@ impl Button { } pub fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { - let icon_color = self.icon_color(); + let (icon_color, label_color) = match (self.disabled, self.color) { + (true, _) => (IconColor::Disabled, LabelColor::Disabled), + (_, None) => (IconColor::Default, LabelColor::Default), + (_, Some(color)) => (IconColor::from(color), color), + }; let mut button = h_stack() .id(SharedString::from(format!("{}", self.label))) @@ -182,16 +187,16 @@ impl Button { (Some(_), Some(IconPosition::Left)) => { button = button .gap_1() - .child(self.render_label()) + .child(self.render_label(label_color)) .children(self.render_icon(icon_color)) } (Some(_), Some(IconPosition::Right)) => { button = button .gap_1() .children(self.render_icon(icon_color)) - .child(self.render_label()) + .child(self.render_label(label_color)) } - (_, _) => button = button.child(self.render_label()), + (_, _) => button = button.child(self.render_label(label_color)), } if let Some(width) = self.width { diff --git a/crates/ui2/src/components/icon.rs b/crates/ui2/src/components/icon.rs index 907f3f91871b5c614944e821244d10228d2853bb..75c8129608f8b1fda354461102afc5387806ce20 100644 --- a/crates/ui2/src/components/icon.rs +++ b/crates/ui2/src/components/icon.rs @@ -1,7 +1,7 @@ use gpui::{rems, svg, Hsla}; use strum::EnumIter; -use crate::prelude::*; +use crate::{prelude::*, LabelColor}; #[derive(Default, PartialEq, Copy, Clone)] pub enum IconSize { @@ -14,15 +14,20 @@ pub enum IconSize { pub enum IconColor { #[default] Default, - Muted, - Disabled, - Placeholder, Accent, + Created, + Deleted, + Disabled, Error, - Warning, - Success, + Hidden, Info, + Modified, + Muted, + Placeholder, + Player(u32), Selected, + Success, + Warning, } impl IconColor { @@ -38,6 +43,33 @@ impl IconColor { IconColor::Success => cx.theme().status().success, IconColor::Info => cx.theme().status().info, IconColor::Selected => cx.theme().colors().icon_accent, + IconColor::Player(i) => cx.theme().styles.player.0[i.clone() as usize].cursor, + IconColor::Created => cx.theme().status().created, + IconColor::Modified => cx.theme().status().modified, + IconColor::Deleted => cx.theme().status().deleted, + IconColor::Hidden => cx.theme().status().hidden, + } + } +} + +impl From for IconColor { + fn from(label: LabelColor) -> Self { + match label { + LabelColor::Default => IconColor::Default, + LabelColor::Muted => IconColor::Muted, + LabelColor::Disabled => IconColor::Disabled, + LabelColor::Placeholder => IconColor::Placeholder, + LabelColor::Accent => IconColor::Accent, + LabelColor::Error => IconColor::Error, + LabelColor::Warning => IconColor::Warning, + LabelColor::Success => IconColor::Success, + LabelColor::Info => IconColor::Info, + LabelColor::Selected => IconColor::Selected, + LabelColor::Player(i) => IconColor::Player(i), + LabelColor::Created => IconColor::Created, + LabelColor::Modified => IconColor::Modified, + LabelColor::Deleted => IconColor::Deleted, + LabelColor::Hidden => IconColor::Hidden, } } } diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index 91653ea8cdd0158d88294886b826c680b5cbf9b3..b648683a8b32e6782d9ffb1013bf7e783ca9282d 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use gpui::{rems, MouseButton}; +use gpui::MouseButton; use crate::{h_stack, prelude::*}; use crate::{ClickHandler, Icon, IconColor, IconElement}; @@ -88,9 +88,7 @@ impl IconButton { .id(self.id.clone()) .justify_center() .rounded_md() - // todo!("Where do these numbers come from?") - .py(rems(0.21875)) - .px(rems(0.375)) + .p_1() .bg(bg_color) .hover(|style| style.bg(bg_hover_color)) .active(|style| style.bg(bg_active_color)) diff --git a/crates/ui2/src/components/label.rs b/crates/ui2/src/components/label.rs index 827ba87918a0cd4dd3f3255c8b7852436ea06a79..d1d2e0cc9deb5cca89036d9e7121e996473dc092 100644 --- a/crates/ui2/src/components/label.rs +++ b/crates/ui2/src/components/label.rs @@ -8,28 +8,40 @@ use crate::styled_ext::StyledExt; pub enum LabelColor { #[default] Default, - Muted, + Accent, Created, - Modified, Deleted, Disabled, + Error, Hidden, + Info, + Modified, + Muted, Placeholder, - Accent, + Player(u32), + Selected, + Success, + Warning, } impl LabelColor { pub fn hsla(&self, cx: &WindowContext) -> Hsla { match self { - Self::Default => cx.theme().colors().text, - Self::Muted => cx.theme().colors().text_muted, - Self::Created => cx.theme().status().created, - Self::Modified => cx.theme().status().modified, - Self::Deleted => cx.theme().status().deleted, - Self::Disabled => cx.theme().colors().text_disabled, - Self::Hidden => cx.theme().status().hidden, - Self::Placeholder => cx.theme().colors().text_placeholder, - Self::Accent => cx.theme().colors().text_accent, + LabelColor::Default => cx.theme().colors().text, + LabelColor::Muted => cx.theme().colors().text_muted, + LabelColor::Created => cx.theme().status().created, + LabelColor::Modified => cx.theme().status().modified, + LabelColor::Deleted => cx.theme().status().deleted, + LabelColor::Disabled => cx.theme().colors().text_disabled, + LabelColor::Hidden => cx.theme().status().hidden, + LabelColor::Info => cx.theme().status().info, + LabelColor::Placeholder => cx.theme().colors().text_placeholder, + LabelColor::Accent => cx.theme().colors().text_accent, + LabelColor::Player(i) => cx.theme().styles.player.0[i.clone() as usize].cursor, + LabelColor::Error => cx.theme().status().error, + LabelColor::Selected => cx.theme().colors().text_accent, + LabelColor::Success => cx.theme().status().success, + LabelColor::Warning => cx.theme().status().warning, } } } diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index 14a7685a9bff1f91d2171a807bddb83f42cff9b9..d55d38209a77050bbf542380f891974b86d33612 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -69,7 +69,7 @@ use std::{ }; use theme2::ActiveTheme; pub use toolbar::{ToolbarItemLocation, ToolbarItemView}; -use ui::{h_stack, Label}; +use ui::{h_stack, Button, ButtonVariant, Label, LabelColor}; use util::ResultExt; use uuid::Uuid; use workspace_settings::{AutosaveSetting, WorkspaceSettings}; @@ -2641,19 +2641,35 @@ impl Workspace { h_stack() .id("titlebar") .justify_between() - .w_full() - .h(rems(1.75)) - .bg(cx.theme().colors().title_bar_background) .when( !matches!(cx.window_bounds(), WindowBounds::Fullscreen), |s| s.pl_20(), ) + .w_full() + .h(rems(1.75)) + .bg(cx.theme().colors().title_bar_background) .on_click(|_, event, cx| { if event.up.click_count == 2 { cx.zoom_window(); } }) - .child(h_stack().child(Label::new("Left side titlebar item"))) // self.titlebar_item + .child( + h_stack() + // TODO - Add player menu + .child( + Button::new("player") + .variant(ButtonVariant::Ghost) + .color(Some(LabelColor::Player(0))), + ) + // TODO - Add project menu + .child(Button::new("project_name").variant(ButtonVariant::Ghost)) + // TODO - Add git menu + .child( + Button::new("branch_name") + .variant(ButtonVariant::Ghost) + .color(Some(LabelColor::Muted)), + ), + ) // self.titlebar_item .child(h_stack().child(Label::new("Right side titlebar item"))) } From 516a8790b9e790e3b863f8242fa55b2708ac309a Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 14 Nov 2023 08:28:57 -0500 Subject: [PATCH 2/4] Add gpt-4-1106-preview model --- Cargo.lock | 5 ++--- Cargo.toml | 3 +++ assets/settings/default.json | 14 ++++---------- crates/Cargo.toml | 2 +- crates/ai/Cargo.toml | 2 +- crates/ai2/Cargo.toml | 2 +- crates/assistant/Cargo.toml | 2 +- crates/assistant/src/assistant_settings.rs | 7 ++++++- crates/semantic_index/Cargo.toml | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97653e124a49e3f41fdfe1d9a13682960a7777d1..d61fe45cf8b8420dfb9b9269b4b4571bfe730f14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9256,9 +9256,8 @@ dependencies = [ [[package]] name = "tiktoken-rs" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9ae5a3c24361e5f038af22517ba7f8e3af4099e30e78a3d56f86b48238fce9d" +version = "0.5.6" +source = "git+https://github.com/JosephTLyons/tiktoken-rs/?rev=edb3ea9eda1b906205b346599c43c5c0e8da1392#edb3ea9eda1b906205b346599c43c5c0e8da1392" dependencies = [ "anyhow", "base64 0.21.4", diff --git a/Cargo.toml b/Cargo.toml index 905750f8352b02422fa0815b7a51e17d74b0daff..2e43fa45d065d6b0ad9b36407aeb29d75cb7c3f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -160,6 +160,9 @@ pretty_assertions = "1.3.0" git2 = { version = "0.15", default-features = false} uuid = { version = "1.1.2", features = ["v4"] } +# Point back to original crate when this is merged: +# https://github.com/zurawiki/tiktoken-rs/pull/49 +tiktoken-rs = { git = "https://github.com/JosephTLyons/tiktoken-rs/", rev="edb3ea9eda1b906205b346599c43c5c0e8da1392" } tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "7331995b19b8f8aba2d5e26deb51d2195c18bc94" } tree-sitter-c = "0.20.1" tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev="f44509141e7e483323d2ec178f2d2e6c0fc041c1" } diff --git a/assets/settings/default.json b/assets/settings/default.json index 42f3b3128666e84274a472fadd498652eadaa8a5..85f8a8fbc4b290c8fc7f913a44fbe0f767341510 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -174,7 +174,8 @@ // // 1. "gpt-3.5-turbo-0613"" // 2. "gpt-4-0613"" - "default_open_ai_model": "gpt-4-0613" + // 3. "gpt-4-1106-preview" + "default_open_ai_model": "gpt-4-1106-preview" }, // Whether the screen sharing icon is shown in the os status bar. "show_call_status_icon": true, @@ -270,9 +271,7 @@ "copilot": { // The set of glob patterns for which copilot should be disabled // in any matching file. - "disabled_globs": [ - ".env" - ] + "disabled_globs": [".env"] }, // Settings specific to journaling "journal": { @@ -381,12 +380,7 @@ // Default directories to search for virtual environments, relative // to the current working directory. We recommend overriding this // in your project's settings, rather than globally. - "directories": [ - ".env", - "env", - ".venv", - "venv" - ], + "directories": [".env", "env", ".venv", "venv"], // Can also be 'csh', 'fish', and `nushell` "activate_script": "default" } diff --git a/crates/Cargo.toml b/crates/Cargo.toml index fb49a4b515540836a757610db5c268321f9f068b..6516e07cd43e402b78998330cd7f536f958f5bc5 100644 --- a/crates/Cargo.toml +++ b/crates/Cargo.toml @@ -29,7 +29,7 @@ postage.workspace = true rand.workspace = true log.workspace = true parse_duration = "2.1.1" -tiktoken-rs = "0.5.0" +tiktoken-rs.workspace = true matrixmultiply = "0.3.7" rusqlite = { version = "0.29.0", features = ["blob", "array", "modern_sqlite"] } bincode = "1.3.3" diff --git a/crates/ai/Cargo.toml b/crates/ai/Cargo.toml index fb49a4b515540836a757610db5c268321f9f068b..6516e07cd43e402b78998330cd7f536f958f5bc5 100644 --- a/crates/ai/Cargo.toml +++ b/crates/ai/Cargo.toml @@ -29,7 +29,7 @@ postage.workspace = true rand.workspace = true log.workspace = true parse_duration = "2.1.1" -tiktoken-rs = "0.5.0" +tiktoken-rs.workspace = true matrixmultiply = "0.3.7" rusqlite = { version = "0.29.0", features = ["blob", "array", "modern_sqlite"] } bincode = "1.3.3" diff --git a/crates/ai2/Cargo.toml b/crates/ai2/Cargo.toml index aee265db6eb4364c074b5182a7ec785f330a2aa5..25c9965915ddb573908ba1447b236c75c96d8edf 100644 --- a/crates/ai2/Cargo.toml +++ b/crates/ai2/Cargo.toml @@ -29,7 +29,7 @@ postage.workspace = true rand.workspace = true log.workspace = true parse_duration = "2.1.1" -tiktoken-rs = "0.5.0" +tiktoken-rs.workspace = true matrixmultiply = "0.3.7" rusqlite = { version = "0.29.0", features = ["blob", "array", "modern_sqlite"] } bincode = "1.3.3" diff --git a/crates/assistant/Cargo.toml b/crates/assistant/Cargo.toml index fc885f6b36248d67bd2ce288c6f5d2931d8540da..876e5e0b76ef287d6ed52b732dd082e67919f8a5 100644 --- a/crates/assistant/Cargo.toml +++ b/crates/assistant/Cargo.toml @@ -40,7 +40,7 @@ schemars.workspace = true serde.workspace = true serde_json.workspace = true smol.workspace = true -tiktoken-rs = "0.5" +tiktoken-rs.workspace = true [dev-dependencies] editor = { path = "../editor", features = ["test-support"] } diff --git a/crates/assistant/src/assistant_settings.rs b/crates/assistant/src/assistant_settings.rs index 05d8d9ffebe485204108969bc4ec308eedbd2d1d..65dd588b3c171516588cc604940d7727583d089e 100644 --- a/crates/assistant/src/assistant_settings.rs +++ b/crates/assistant/src/assistant_settings.rs @@ -9,6 +9,8 @@ pub enum OpenAIModel { ThreePointFiveTurbo, #[serde(rename = "gpt-4-0613")] Four, + #[serde(rename = "gpt-4-1106-preview")] + FourTurbo, } impl OpenAIModel { @@ -16,6 +18,7 @@ impl OpenAIModel { match self { OpenAIModel::ThreePointFiveTurbo => "gpt-3.5-turbo-0613", OpenAIModel::Four => "gpt-4-0613", + OpenAIModel::FourTurbo => "gpt-4-1106-preview", } } @@ -23,13 +26,15 @@ impl OpenAIModel { match self { OpenAIModel::ThreePointFiveTurbo => "gpt-3.5-turbo", OpenAIModel::Four => "gpt-4", + OpenAIModel::FourTurbo => "gpt-4-turbo", } } pub fn cycle(&self) -> Self { match self { OpenAIModel::ThreePointFiveTurbo => OpenAIModel::Four, - OpenAIModel::Four => OpenAIModel::ThreePointFiveTurbo, + OpenAIModel::Four => OpenAIModel::FourTurbo, + OpenAIModel::FourTurbo => OpenAIModel::ThreePointFiveTurbo, } } } diff --git a/crates/semantic_index/Cargo.toml b/crates/semantic_index/Cargo.toml index 875440ef3fa866734c734830ff5c7b95550fd33c..03089279446d888b7e8554fccfadff8a460d0d97 100644 --- a/crates/semantic_index/Cargo.toml +++ b/crates/semantic_index/Cargo.toml @@ -33,7 +33,7 @@ lazy_static.workspace = true serde.workspace = true serde_json.workspace = true async-trait.workspace = true -tiktoken-rs = "0.5.0" +tiktoken-rs.workspace = true parking_lot.workspace = true rand.workspace = true schemars.workspace = true From 946a696d3de3fbbfc91a120a24f3f78122249aac Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 14 Nov 2023 09:00:04 -0500 Subject: [PATCH 3/4] Update `tiktoken-rs` dependency The PR to add the `gpt-4-1106-preview` model was merged: https://github.com/zurawiki/tiktoken-rs/pull/49 --- Cargo.lock | 2 +- Cargo.toml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d61fe45cf8b8420dfb9b9269b4b4571bfe730f14..1b1758dd8a971034f033438ee0a2c881b12c64bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9257,7 +9257,7 @@ dependencies = [ [[package]] name = "tiktoken-rs" version = "0.5.6" -source = "git+https://github.com/JosephTLyons/tiktoken-rs/?rev=edb3ea9eda1b906205b346599c43c5c0e8da1392#edb3ea9eda1b906205b346599c43c5c0e8da1392" +source = "git+https://github.com/zurawiki/tiktoken-rs?rev=6fd80d41d5c31e256cd760b52cd0257586033eb2#6fd80d41d5c31e256cd760b52cd0257586033eb2" dependencies = [ "anyhow", "base64 0.21.4", diff --git a/Cargo.toml b/Cargo.toml index 2e43fa45d065d6b0ad9b36407aeb29d75cb7c3f3..a04a6d10b51991a2245c053c6b58acdd79362b59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -160,9 +160,7 @@ pretty_assertions = "1.3.0" git2 = { version = "0.15", default-features = false} uuid = { version = "1.1.2", features = ["v4"] } -# Point back to original crate when this is merged: -# https://github.com/zurawiki/tiktoken-rs/pull/49 -tiktoken-rs = { git = "https://github.com/JosephTLyons/tiktoken-rs/", rev="edb3ea9eda1b906205b346599c43c5c0e8da1392" } +tiktoken-rs = { git = "https://github.com/zurawiki/tiktoken-rs", rev="6fd80d41d5c31e256cd760b52cd0257586033eb2" } tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "7331995b19b8f8aba2d5e26deb51d2195c18bc94" } tree-sitter-c = "0.20.1" tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev="f44509141e7e483323d2ec178f2d2e6c0fc041c1" } From a5fc5819f12d5726dc9a0e80ac52674f9225157c Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 14 Nov 2023 09:12:25 -0500 Subject: [PATCH 4/4] Bump `tiktoken-rs` to official release --- Cargo.lock | 5 +++-- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b1758dd8a971034f033438ee0a2c881b12c64bd..0882435df934b8225238ad1ed19d409a723b4d0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9256,8 +9256,9 @@ dependencies = [ [[package]] name = "tiktoken-rs" -version = "0.5.6" -source = "git+https://github.com/zurawiki/tiktoken-rs?rev=6fd80d41d5c31e256cd760b52cd0257586033eb2#6fd80d41d5c31e256cd760b52cd0257586033eb2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4427b6b1c6b38215b92dd47a83a0ecc6735573d0a5a4c14acc0ac5b33b28adb" dependencies = [ "anyhow", "base64 0.21.4", diff --git a/Cargo.toml b/Cargo.toml index a04a6d10b51991a2245c053c6b58acdd79362b59..8434acdfd3d595d3cd3c3afd62cba52228e9e75f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -154,13 +154,13 @@ tempdir = { version = "0.3.7" } thiserror = { version = "1.0.29" } time = { version = "0.3", features = ["serde", "serde-well-known"] } toml = { version = "0.5" } +tiktoken-rs = "0.5.7" tree-sitter = "0.20" unindent = { version = "0.1.7" } pretty_assertions = "1.3.0" git2 = { version = "0.15", default-features = false} uuid = { version = "1.1.2", features = ["v4"] } -tiktoken-rs = { git = "https://github.com/zurawiki/tiktoken-rs", rev="6fd80d41d5c31e256cd760b52cd0257586033eb2" } tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "7331995b19b8f8aba2d5e26deb51d2195c18bc94" } tree-sitter-c = "0.20.1" tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev="f44509141e7e483323d2ec178f2d2e6c0fc041c1" }