Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'main' into setting-store
Max Brunsfeld89204e85c098
diff --cc Cargo.lockindex 216103959ca,41c3eab8219..c2e0790cf49--- a/Cargo.lock+++ b/Cargo.lock@@@ -4832,12 -4714,13 +4836,13 @@@ dependencies ="copilot","ctor","db",- "env_logger",+ "env_logger 0.9.3","fs","fsevent",- "futures 0.3.25",+ "futures 0.3.28","fuzzy","git",+ "git2","glob","gpui","ignore",@@@ -5930,9 -5774,9 +5935,10 @@@ name = "searchversion = "0.1.0"dependencies = ["anyhow",++ "client","collections","editor",- "futures 0.3.25",+ "futures 0.3.28","glob","gpui","language",@@@ -6702,11 -6540,17 +6708,17 @@@ dependencies ="winx",]+ [[package]]+ name = "take-until"+ version = "0.2.0"+ source = "registry+https://github.com/rust-lang/crates.io-index"+ checksum = "8bdb6fa0dfa67b38c1e66b7041ba9dcf23b99d8121907cd31c807a332f7a0bbb"+[[package]]name = "target-lexicon"-version = "0.12.5"+version = "0.12.7"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d"+checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5"[[package]]name = "tempdir"diff --cc crates/diagnostics/src/diagnostics.rsindex f7746496aa5,d82c653a092..4ce1303ba4b--- a/crates/diagnostics/src/diagnostics.rs+++ b/crates/diagnostics/src/diagnostics.rs@@@ -1494,15 -1489,6 +1494,16 @@@ mod tests});}+ fn init_test(cx: &mut TestAppContext) {+ cx.update(|cx| {+ cx.set_global(Settings::test(cx));+ cx.set_global(SettingsStore::test(cx));+ language::init(cx);++ client::init_settings(cx);+ workspace::init_settings(cx);+ });+ }+fn editor_blocks(editor: &ViewHandle<Editor>, cx: &mut WindowContext) -> Vec<(u32, String)> {editor.update(cx, |editor, cx| {let snapshot = editor.snapshot(cx);diff --cc crates/editor/src/editor.rsindex 791f67be29f,21d495d6ee9..915e041100b--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@@ -1255,7 -1247,17 +1255,17 @@@ impl Editorlet blink_manager = cx.add_model(|cx| BlinkManager::new(CURSOR_BLINK_INTERVAL, cx));let soft_wrap_mode_override =- (mode == EditorMode::SingleLine).then(|| settings::SoftWrap::None);+ (mode == EditorMode::SingleLine).then(|| language_settings::SoftWrap::None);++ let mut project_subscription = None;+ if mode == EditorMode::Full && buffer.read(cx).is_singleton() {+ if let Some(project) = project.as_ref() {+ project_subscription = Some(cx.observe(project, |_, _, cx| {+ cx.emit(Event::TitleChanged);+ }))+ }+ }+let mut this = Self {handle: cx.weak_handle(),buffer: buffer.clone(),@@@ -6853,48 -6880,84 +6872,88 @@@.collect()}- fn report_editor_event(&self, name: &'static str, cx: &AppContext) {- if let Some((project, file)) = self.project.as_ref().zip(- self.buffer- .read(cx)- .as_singleton()- .and_then(|b| b.read(cx).file()),- ) {- let vim_mode = cx- .global::<SettingsStore>()- .untyped_user_settings()- .get("vim_mode")- == Some(&serde_json::Value::Bool(true));- let telemetry_settings = *settings::get_setting::<TelemetrySettings>(None, cx);- let copilot_enabled = all_language_settings(None, cx).copilot_enabled(None, None);- let copilot_enabled_for_language = self- .buffer- .read(cx)- .settings_at(0, cx)- .show_copilot_suggestions;-- let extension = Path::new(file.file_name(cx))- .extension()- .and_then(|e| e.to_str());- let telemetry = project.read(cx).client().telemetry().clone();- telemetry.report_mixpanel_event(- match name {- "open" => "open editor",- "save" => "save editor",- _ => name,- },- json!({ "File Extension": extension, "Vim Mode": vim_mode, "In Clickhouse": true }),- telemetry_settings,- );- let event = ClickhouseEvent::Editor {- file_extension: extension.map(ToString::to_string),- vim_mode,- operation: name,- copilot_enabled,- copilot_enabled_for_language,- };- telemetry.report_clickhouse_event(event, telemetry_settings)- }+ fn report_copilot_event(+ &self,+ suggestion_id: Option<String>,+ suggestion_accepted: bool,+ cx: &AppContext,+ ) {+ let Some(project) = &self.project else {+ return+ };++ // If None, we are either getting suggestions in a new, unsaved file, or in a file without an extension+ let file_extension = self+ .buffer+ .read(cx)+ .as_singleton()+ .and_then(|b| b.read(cx).file())+ .and_then(|file| Path::new(file.file_name(cx)).extension())+ .and_then(|e| e.to_str())+ .map(|a| a.to_string());++ let telemetry = project.read(cx).client().telemetry().clone();- let telemetry_settings = cx.global::<Settings>().telemetry();++ let telemetry_settings = *settings::get_setting::<TelemetrySettings>(None, cx);++ let event = ClickhouseEvent::Copilot {+ suggestion_id,+ suggestion_accepted,+ file_extension,+ };+ telemetry.report_clickhouse_event(event, telemetry_settings);+ }++ fn report_editor_event(+ &self,+ name: &'static str,+ file_extension: Option<String>,+ cx: &AppContext,+ ) {+ let Some(project) = &self.project else {+ return+ };++ // If None, we are in a file without an extension+ let file_extension = file_extension.or(self+ .buffer+ .read(cx)+ .as_singleton()+ .and_then(|b| b.read(cx).file())+ .and_then(|file| Path::new(file.file_name(cx)).extension())+ .and_then(|e| e.to_str())+ .map(|a| a.to_string()));+- let settings = cx.global::<Settings>();++ let vim_mode = cx++ .global::<SettingsStore>()++ .untyped_user_settings()++ .get("vim_mode")++ == Some(&serde_json::Value::Bool(true));++ let telemetry_settings = *settings::get_setting::<TelemetrySettings>(None, cx);++ let copilot_enabled = all_language_settings(None, cx).copilot_enabled(None, None);++ let copilot_enabled_for_language = self++ .buffer++ .read(cx)++ .settings_at(0, cx)++ .show_copilot_suggestions;++ let telemetry = project.read(cx).client().telemetry().clone();+ telemetry.report_mixpanel_event(- match name {- "open" => "open editor",- "save" => "save editor",- _ => name,- },- json!({ "File Extension": file_extension, "Vim Mode": settings.vim_mode, "In Clickhouse": true }),- settings.telemetry(),- );++ match name {++ "open" => "open editor",++ "save" => "save editor",++ _ => name,++ },++ json!({ "File Extension": file_extension, "Vim Mode": vim_mode, "In Clickhouse": true }),++ telemetry_settings,++ );+ let event = ClickhouseEvent::Editor {+ file_extension,- vim_mode: settings.vim_mode,++ vim_mode,+ operation: name,- copilot_enabled: settings.features.copilot,- copilot_enabled_for_language: settings.show_copilot_suggestions(- self.language_at(0, cx)- .map(|language| language.name())- .as_deref(),- self.file_at(0, cx)- .map(|file| file.path().clone())- .as_deref(),- ),++ copilot_enabled,++ copilot_enabled_for_language,+ };- telemetry.report_clickhouse_event(event, settings.telemetry())++ telemetry.report_clickhouse_event(event, telemetry_settings)}/// Copy the highlighted chunks to the clipboard as JSON. The format is an array of lines,diff --cc crates/editor/src/editor_tests.rsindex cce10eb05e0,0f749bde484..cf72f0286cf--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@@ -6664,29 -6596,3 +6664,30 @@@ fn handle_copilot_completion_request}});}++pub(crate) fn update_test_settings(+ cx: &mut TestAppContext,+ f: impl Fn(&mut AllLanguageSettingsContent),+) {+ cx.update(|cx| {+ cx.update_global::<SettingsStore, _, _>(|store, cx| {+ store.update_user_settings::<AllLanguageSettings>(cx, f);+ });+ });+}++pub(crate) fn init_test(cx: &mut TestAppContext, f: fn(&mut AllLanguageSettingsContent)) {+ cx.foreground().forbid_parking();++ cx.update(|cx| {+ cx.set_global(SettingsStore::test(cx));+ cx.set_global(Settings::test(cx));++ client::init_settings(cx);+ language::init(cx);- crate::init(cx);+ Project::init_settings(cx);+ workspace::init_settings(cx);++ crate::init(cx);+ });++ update_test_settings(cx, f);+}diff --cc crates/file_finder/src/file_finder.rsindex ad865ec2f73,063067891a9..37ab4218a8f--- a/crates/file_finder/src/file_finder.rs+++ b/crates/file_finder/src/file_finder.rs@@@ -268,9 -344,9 +344,11 @@@ impl PickerDelegate for FileFinderDeleg#[cfg(test)]mod tests {++ use std::time::Duration;++use super::*;use editor::Editor;- use gpui::executor::Deterministic;+ use gpui::TestAppContext;use menu::{Confirm, SelectNext};use serde_json::json;use workspace::{AppState, Workspace};@@@ -283,8 -359,13 +361,8 @@@}#[gpui::test]-- async fn test_matching_paths(cx: &mut gpui::TestAppContext) {- let app_state = cx.update(|cx| {- super::init(cx);- editor::init(cx);- AppState::test(cx)- });-++ async fn test_matching_paths(cx: &mut TestAppContext) {+ let app_state = init_test(cx);app_state.fs.as_fake()@@@ -334,8 -415,188 +412,174 @@@}#[gpui::test]- async fn test_matching_cancellation(cx: &mut gpui::TestAppContext) {- async fn test_row_column_numbers_query_inside_file(- deterministic: Arc<Deterministic>,- cx: &mut gpui::TestAppContext,- ) {- let app_state = cx.update(|cx| {- super::init(cx);- editor::init(cx);- AppState::test(cx)- });++ async fn test_row_column_numbers_query_inside_file(cx: &mut TestAppContext) {++ let app_state = init_test(cx);++ let first_file_name = "first.rs";+ let first_file_contents = "// First Rust file";+ app_state+ .fs+ .as_fake()+ .insert_tree(+ "/src",+ json!({+ "test": {+ first_file_name: first_file_contents,+ "second.rs": "// Second Rust file",+ }+ }),+ )+ .await;++ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;+ let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ cx.dispatch_action(window_id, Toggle);+ let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());++ let file_query = &first_file_name[..3];+ let file_row = 1;+ let file_column = 3;+ assert!(file_column <= first_file_contents.len());+ let query_inside_file = format!("{file_query}:{file_row}:{file_column}");+ finder+ .update(cx, |finder, cx| {+ finder+ .delegate_mut()+ .update_matches(query_inside_file.to_string(), cx)+ })+ .await;+ finder.read_with(cx, |finder, _| {+ let finder = finder.delegate();+ assert_eq!(finder.matches.len(), 1);+ let latest_search_query = finder+ .latest_search_query+ .as_ref()+ .expect("Finder should have a query after the update_matches call");+ assert_eq!(latest_search_query.path_like.raw_query, query_inside_file);+ assert_eq!(+ latest_search_query.path_like.file_query_end,+ Some(file_query.len())+ );+ assert_eq!(latest_search_query.row, Some(file_row));+ assert_eq!(latest_search_query.column, Some(file_column as u32));+ });++ let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());+ cx.dispatch_action(window_id, SelectNext);+ cx.dispatch_action(window_id, Confirm);+ active_pane+ .condition(cx, |pane, _| pane.active_item().is_some())+ .await;+ let editor = cx.update(|cx| {+ let active_item = active_pane.read(cx).active_item().unwrap();+ active_item.downcast::<Editor>().unwrap()+ });- deterministic.advance_clock(std::time::Duration::from_secs(2));- deterministic.start_waiting();- deterministic.finish_waiting();++ cx.foreground().advance_clock(Duration::from_secs(2));++ cx.foreground().start_waiting();++ cx.foreground().finish_waiting();+ editor.update(cx, |editor, cx| {+ let all_selections = editor.selections.all_adjusted(cx);+ assert_eq!(+ all_selections.len(),+ 1,+ "Expected to have 1 selection (caret) after file finder confirm, but got: {all_selections:?}"+ );+ let caret_selection = all_selections.into_iter().next().unwrap();+ assert_eq!(caret_selection.start, caret_selection.end,+ "Caret selection should have its start and end at the same position");+ assert_eq!(file_row, caret_selection.start.row + 1,+ "Query inside file should get caret with the same focus row");+ assert_eq!(file_column, caret_selection.start.column as usize + 1,+ "Query inside file should get caret with the same focus column");+ });+ }++ #[gpui::test]- async fn test_row_column_numbers_query_outside_file(- deterministic: Arc<Deterministic>,- cx: &mut gpui::TestAppContext,- ) {- let app_state = cx.update(|cx| {- super::init(cx);- editor::init(cx);- AppState::test(cx)- });++ async fn test_row_column_numbers_query_outside_file(cx: &mut TestAppContext) {++ let app_state = init_test(cx);++ let first_file_name = "first.rs";+ let first_file_contents = "// First Rust file";+ app_state+ .fs+ .as_fake()+ .insert_tree(+ "/src",+ json!({+ "test": {+ first_file_name: first_file_contents,+ "second.rs": "// Second Rust file",+ }+ }),+ )+ .await;++ let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;+ let (window_id, workspace) = cx.add_window(|cx| Workspace::test_new(project, cx));+ cx.dispatch_action(window_id, Toggle);+ let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());++ let file_query = &first_file_name[..3];+ let file_row = 200;+ let file_column = 300;+ assert!(file_column > first_file_contents.len());+ let query_outside_file = format!("{file_query}:{file_row}:{file_column}");+ finder+ .update(cx, |finder, cx| {+ finder+ .delegate_mut()+ .update_matches(query_outside_file.to_string(), cx)+ })+ .await;+ finder.read_with(cx, |finder, _| {+ let finder = finder.delegate();+ assert_eq!(finder.matches.len(), 1);+ let latest_search_query = finder+ .latest_search_query+ .as_ref()+ .expect("Finder should have a query after the update_matches call");+ assert_eq!(latest_search_query.path_like.raw_query, query_outside_file);+ assert_eq!(+ latest_search_query.path_like.file_query_end,+ Some(file_query.len())+ );+ assert_eq!(latest_search_query.row, Some(file_row));+ assert_eq!(latest_search_query.column, Some(file_column as u32));+ });++ let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());+ cx.dispatch_action(window_id, SelectNext);+ cx.dispatch_action(window_id, Confirm);+ active_pane+ .condition(cx, |pane, _| pane.active_item().is_some())+ .await;+ let editor = cx.update(|cx| {+ let active_item = active_pane.read(cx).active_item().unwrap();+ active_item.downcast::<Editor>().unwrap()+ });- deterministic.advance_clock(std::time::Duration::from_secs(2));- deterministic.start_waiting();- deterministic.finish_waiting();++ cx.foreground().advance_clock(Duration::from_secs(2));++ cx.foreground().start_waiting();++ cx.foreground().finish_waiting();+ editor.update(cx, |editor, cx| {+ let all_selections = editor.selections.all_adjusted(cx);+ assert_eq!(+ all_selections.len(),+ 1,+ "Expected to have 1 selection (caret) after file finder confirm, but got: {all_selections:?}"+ );+ let caret_selection = all_selections.into_iter().next().unwrap();+ assert_eq!(caret_selection.start, caret_selection.end,+ "Caret selection should have its start and end at the same position");+ assert_eq!(0, caret_selection.start.row,+ "Excessive rows (as in query outside file borders) should get trimmed to last file row");+ assert_eq!(first_file_contents.len(), caret_selection.start.column as usize,+ "Excessive columns (as in query outside file borders) should get trimmed to selected row's last column");+ });+ }++ #[gpui::test]- async fn test_matching_cancellation(cx: &mut gpui::TestAppContext) {- let app_state = cx.update(AppState::test);++ async fn test_matching_cancellation(cx: &mut TestAppContext) {+ let app_state = init_test(cx);app_state.fs.as_fake()@@@ -403,8 -664,8 +647,8 @@@}#[gpui::test]-- async fn test_ignored_files(cx: &mut gpui::TestAppContext) {- let app_state = cx.update(AppState::test);++ async fn test_ignored_files(cx: &mut TestAppContext) {+ let app_state = init_test(cx);app_state.fs.as_fake()@@@ -457,8 -720,8 +703,8 @@@}#[gpui::test]-- async fn test_single_file_worktrees(cx: &mut gpui::TestAppContext) {- let app_state = cx.update(AppState::test);++ async fn test_single_file_worktrees(cx: &mut TestAppContext) {+ let app_state = init_test(cx);app_state.fs.as_fake()@@@ -511,8 -778,10 +761,8 @@@}#[gpui::test]-- async fn test_multiple_matches_with_same_relative_path(cx: &mut gpui::TestAppContext) {- cx.foreground().forbid_parking();-- let app_state = cx.update(AppState::test);++ async fn test_multiple_matches_with_same_relative_path(cx: &mut TestAppContext) {+ let app_state = init_test(cx);app_state.fs.as_fake()@@@ -563,8 -834,10 +815,8 @@@}#[gpui::test]-- async fn test_path_distance_ordering(cx: &mut gpui::TestAppContext) {- cx.foreground().forbid_parking();-- let app_state = cx.update(AppState::test);++ async fn test_path_distance_ordering(cx: &mut TestAppContext) {+ let app_state = init_test(cx);app_state.fs.as_fake()@@@ -613,8 -886,8 +865,8 @@@}#[gpui::test]-- async fn test_search_worktree_without_files(cx: &mut gpui::TestAppContext) {- let app_state = cx.update(AppState::test);++ async fn test_search_worktree_without_files(cx: &mut TestAppContext) {+ let app_state = init_test(cx);app_state.fs.as_fake()@@@ -651,15 -926,17 +905,29 @@@});}+ fn init_test(cx: &mut TestAppContext) -> Arc<AppState> {+ cx.foreground().forbid_parking();+ cx.update(|cx| {+ let state = AppState::test(cx);+ language::init(cx);+ super::init(cx);+ editor::init(cx);+ workspace::init_settings(cx);+ state+ })+ }+++ fn test_path_like(test_str: &str) -> PathLikeWithPosition<FileSearchQuery> {+ PathLikeWithPosition::parse_str(test_str, |path_like_str| {+ Ok::<_, std::convert::Infallible>(FileSearchQuery {+ raw_query: test_str.to_owned(),+ file_query_end: if path_like_str == test_str {+ None+ } else {+ Some(path_like_str.len())+ },+ })+ })+ .unwrap()+ }}diff --cc crates/search/Cargo.tomlindex ab3c35c1fe4,ab3c35c1fe4..14e658e8f84--- a/crates/search/Cargo.toml+++ b/crates/search/Cargo.toml@@@ -30,6 -30,6 +30,7 @@@ smol.workspace = truglob.workspace = true[dev-dependencies]++client = { path = "../client", features = ["test-support"] }editor = { path = "../editor", features = ["test-support"] }gpui = { path = "../gpui", features = ["test-support"] }serde_json.workspace = truediff --cc crates/search/src/project_search.rsindex 7364431407d,05d27b824c7..0d020da5706--- a/crates/search/src/project_search.rs+++ b/crates/search/src/project_search.rs@@@ -1272,23 -1279,4 +1272,24 @@@ pub mod tests);});}++ pub fn init_test(cx: &mut TestAppContext) {+ let fonts = cx.font_cache();+ let mut theme = gpui::fonts::with_font_cache(fonts.clone(), theme::Theme::default);+ theme.search.match_background = Color::red();++ cx.update(|cx| {+ cx.set_global(SettingsStore::test(cx));+ cx.set_global(ActiveSearches::default());++ let mut settings = Settings::test(cx);+ settings.theme = Arc::new(theme);+ cx.set_global(settings);++ language::init(cx);++ client::init_settings(cx);+ editor::init_settings(cx);+ workspace::init_settings(cx);+ });+ }}diff --cc crates/workspace/src/persistence/model.rsindex ac1bcf6eede,dd81109d8c2..b73dfa495d4--- a/crates/workspace/src/persistence/model.rs+++ b/crates/workspace/src/persistence/model.rs@@@ -1,6 -1,6 +1,6 @@@use crate::{- dock::DockPosition, DockAnchor, ItemDeserializers, Member, Pane, PaneAxis, Workspace,- dock::DockPosition, item::ItemHandle, ItemDeserializers, Member, Pane, PaneAxis, Workspace,-- WorkspaceId,++ dock::DockPosition, item::ItemHandle, DockAnchor, ItemDeserializers, Member, Pane, PaneAxis,++ Workspace, WorkspaceId,};use anyhow::{anyhow, Context, Result};use async_recursion::async_recursion;diff --cc crates/workspace/src/workspace.rsindex dcc4d017dd0,4bdaaedc645..d956db10b69--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@@ -83,8 -82,7 +83,8 @@@ use status_bar::StatusBarpub use status_bar::StatusItemView;use theme::{Theme, ThemeRegistry};pub use toolbar::{ToolbarItemLocation, ToolbarItemView};- use util::{paths, ResultExt};+ use util::{async_iife, paths, ResultExt};+pub use workspace_settings::{AutosaveSetting, DockAnchor, GitGutterSetting, WorkspaceSettings};lazy_static! {static ref ZED_WINDOW_SIZE: Option<Vector2F> = env::var("ZED_WINDOW_SIZE")diff --cc crates/zed/src/main.rsindex 3466daebe9a,1947095bf55..b290460cca6--- a/crates/zed/src/main.rs+++ b/crates/zed/src/main.rs@@@ -6,18 -6,18 +6,18 @@@ use assets::Assetsuse backtrace::Backtrace;use cli::{ipc::{self, IpcSender},- CliRequest, CliResponse, IpcHandshake,+ CliRequest, CliResponse, IpcHandshake, FORCE_CLI_MODE_ENV_VAR_NAME,};-use client::{self, UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN};+use client::{self, TelemetrySettings, UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN};use db::kvp::KEY_VALUE_STORE;- use editor::Editor;+ use editor::{scroll::autoscroll::Autoscroll, Editor};use futures::{channel::{mpsc, oneshot},FutureExt, SinkExt, StreamExt,};use gpui::{Action, App, AppContext, AssetSource, AsyncAppContext, Task, ViewContext};use isahc::{config::Configurable, Request};--use language::LanguageRegistry;++use language::{LanguageRegistry, Point};use log::LevelFilter;use node_runtime::NodeRuntime;use parking_lot::Mutex;@@@ -36,14 -37,21 +37,21 @@@ use std::io::Write as _,os::unix::prelude::OsStrExt,panic,- path::PathBuf,+ path::{Path, PathBuf},+ str,- sync::{Arc, Weak},+ sync::{+ atomic::{AtomicBool, Ordering},+ Arc, Weak,+ },thread,time::Duration,};+ use sum_tree::Bias;-use terminal_view::{get_working_directory, TerminalView};-use text::Point;+use terminal_view::{get_working_directory, TerminalSettings, TerminalView};- use util::http::{self, HttpClient};+ use util::{+ http::{self, HttpClient},+ paths::PathLikeWithPosition,+ };use welcome::{show_welcome_experience, FIRST_OPEN};use fs::RealFs;