11987 lines · 442.7 KB · Rust
RawDownload
pub mod dock;pub mod history_manager;pub mod invalid_item_view;pub mod item;mod modal_layer;pub mod notifications;pub mod pane;pub mod pane_group;mod path_list;mod persistence;pub mod searchable;mod security_modal;pub mod shared_screen;mod status_bar;pub mod tasks;mod theme_preview;mod toast_layer;mod toolbar;pub mod utility_pane;pub mod welcome;mod workspace_settings; pub use crate::notifications::NotificationFrame;pub use dock::Panel;pub use path_list::PathList;pub use toast_layer::{ToastAction, ToastLayer, ToastView}; use anyhow::{Context as _, Result, anyhow};use call::{ActiveCall, call_settings::CallSettings};use client::{    ChannelId, Client, ErrorExt, Status, TypedEnvelope, UserStore,    proto::{self, ErrorCode, PanelId, PeerId},};use collections::{HashMap, HashSet, hash_map};use dock::{Dock, DockPosition, PanelButtons, PanelHandle, RESIZE_HANDLE_SIZE};use feature_flags::{AgentV2FeatureFlag, FeatureFlagAppExt};use futures::{    Future, FutureExt, StreamExt,    channel::{        mpsc::{self, UnboundedReceiver, UnboundedSender},        oneshot,    },    future::{Shared, try_join_all},};use gpui::{    Action, AnyEntity, AnyView, AnyWeakView, App, AsyncApp, AsyncWindowContext, Bounds, Context,    CursorStyle, Decorations, DragMoveEvent, Entity, EntityId, EventEmitter, FocusHandle,    Focusable, Global, HitboxBehavior, Hsla, KeyContext, Keystroke, ManagedView, MouseButton,    PathPromptOptions, Point, PromptLevel, Render, ResizeEdge, Size, Stateful, Subscription,    SystemWindowTabController, Task, Tiling, WeakEntity, WindowBounds, WindowHandle, WindowId,    WindowOptions, actions, canvas, point, relative, size, transparent_black,};pub use history_manager::*;pub use item::{    FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, PreviewTabsSettings,    ProjectItem, SerializableItem, SerializableItemHandle, WeakItemHandle,};use itertools::Itertools;use language::{Buffer, LanguageRegistry, Rope, language_settings::all_language_settings};pub use modal_layer::*;use node_runtime::NodeRuntime;use notifications::{    DetachAndPromptErr, Notifications, dismiss_app_notification,    simple_message_notification::MessageNotification,};pub use pane::*;pub use pane_group::{    ActivePaneDecorator, HANDLE_HITBOX_SIZE, Member, PaneAxis, PaneGroup, PaneRenderContext,    SplitDirection,};use persistence::{DB, SerializedWindowBounds, model::SerializedWorkspace};pub use persistence::{    DB as WORKSPACE_DB, WorkspaceDb, delete_unloaded_items,    model::{ItemId, SerializedWorkspaceLocation},};use postage::stream::Stream;use project::{    DirectoryLister, Project, ProjectEntryId, ProjectPath, ResolvedPath, Worktree, WorktreeId,    WorktreeSettings,    debugger::{breakpoint_store::BreakpointStoreEvent, session::ThreadStatus},    project_settings::ProjectSettings,    toolchain_store::ToolchainStoreEvent,    trusted_worktrees::{RemoteHostLocation, TrustedWorktrees, TrustedWorktreesEvent},};use remote::{    RemoteClientDelegate, RemoteConnection, RemoteConnectionOptions,    remote_client::ConnectionIdentifier,};use schemars::JsonSchema;use serde::Deserialize;use session::AppSession;use settings::{    CenteredPaddingSettings, Settings, SettingsLocation, SettingsStore, update_settings_file,};use shared_screen::SharedScreen;use sqlez::{    bindable::{Bind, Column, StaticColumnCount},    statement::Statement,};use status_bar::StatusBar;pub use status_bar::StatusItemView;use std::{    any::TypeId,    borrow::Cow,    cell::RefCell,    cmp,    collections::{VecDeque, hash_map::DefaultHasher},    env,    hash::{Hash, Hasher},    path::{Path, PathBuf},    process::ExitStatus,    rc::Rc,    sync::{        Arc, LazyLock, Weak,        atomic::{AtomicBool, AtomicUsize},    },    time::Duration,};use task::{DebugScenario, SpawnInTerminal, TaskContext};use theme::{ActiveTheme, GlobalTheme, SystemAppearance, ThemeSettings};pub use toolbar::{Toolbar, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};pub use ui;use ui::{Window, prelude::*};use util::{    ResultExt, TryFutureExt,    paths::{PathStyle, SanitizedPath},    rel_path::RelPath,    serde::default_true,};use uuid::Uuid;pub use workspace_settings::{    AutosaveSetting, BottomDockLayout, RestoreOnStartupBehavior, StatusBarSettings, TabBarSettings,    WorkspaceSettings,};use zed_actions::{Spawn, feedback::FileBugReport}; use crate::{    item::ItemBufferKind,    notifications::NotificationId,    utility_pane::{UTILITY_PANE_MIN_WIDTH, utility_slot_for_dock_position},};use crate::{    persistence::{        SerializedAxis,        model::{DockData, DockStructure, SerializedItem, SerializedPane, SerializedPaneGroup},    },    security_modal::SecurityModal,    utility_pane::{DraggedUtilityPane, UtilityPaneFrame, UtilityPaneSlot, UtilityPaneState},}; pub const SERIALIZATION_THROTTLE_TIME: Duration = Duration::from_millis(200); static ZED_WINDOW_SIZE: LazyLock<Option<Size<Pixels>>> = LazyLock::new(|| {    env::var("ZED_WINDOW_SIZE")        .ok()        .as_deref()        .and_then(parse_pixel_size_env_var)}); static ZED_WINDOW_POSITION: LazyLock<Option<Point<Pixels>>> = LazyLock::new(|| {    env::var("ZED_WINDOW_POSITION")        .ok()        .as_deref()        .and_then(parse_pixel_position_env_var)}); pub trait TerminalProvider {    fn spawn(        &self,        task: SpawnInTerminal,        window: &mut Window,        cx: &mut App,    ) -> Task<Option<Result<ExitStatus>>>;} pub trait DebuggerProvider {    // `active_buffer` is used to resolve build task's name against language-specific tasks.    fn start_session(        &self,        definition: DebugScenario,        task_context: TaskContext,        active_buffer: Option<Entity<Buffer>>,        worktree_id: Option<WorktreeId>,        window: &mut Window,        cx: &mut App,    );     fn spawn_task_or_modal(        &self,        workspace: &mut Workspace,        action: &Spawn,        window: &mut Window,        cx: &mut Context<Workspace>,    );     fn task_scheduled(&self, cx: &mut App);    fn debug_scenario_scheduled(&self, cx: &mut App);    fn debug_scenario_scheduled_last(&self, cx: &App) -> bool;     fn active_thread_state(&self, cx: &App) -> Option<ThreadStatus>;} actions!(    workspace,    [        /// Activates the next pane in the workspace.        ActivateNextPane,        /// Activates the previous pane in the workspace.        ActivatePreviousPane,        /// Switches to the next window.        ActivateNextWindow,        /// Switches to the previous window.        ActivatePreviousWindow,        /// Adds a folder to the current project.        AddFolderToProject,        /// Clears all notifications.        ClearAllNotifications,        /// Clears all navigation history, including forward/backward navigation, recently opened files, and recently closed tabs. **This action is irreversible**.        ClearNavigationHistory,        /// Closes the active dock.        CloseActiveDock,        /// Closes all docks.        CloseAllDocks,        /// Toggles all docks.        ToggleAllDocks,        /// Closes the current window.        CloseWindow,        /// Opens the feedback dialog.        Feedback,        /// Follows the next collaborator in the session.        FollowNextCollaborator,        /// Moves the focused panel to the next position.        MoveFocusedPanelToNextPosition,        /// Opens a new terminal in the center.        NewCenterTerminal,        /// Creates a new file.        NewFile,        /// Creates a new file in a vertical split.        NewFileSplitVertical,        /// Creates a new file in a horizontal split.        NewFileSplitHorizontal,        /// Opens a new search.        NewSearch,        /// Opens a new terminal.        NewTerminal,        /// Opens a new window.        NewWindow,        /// Opens a file or directory.        Open,        /// Opens multiple files.        OpenFiles,        /// Opens the current location in terminal.        OpenInTerminal,        /// Opens the component preview.        OpenComponentPreview,        /// Reloads the active item.        ReloadActiveItem,        /// Resets the active dock to its default size.        ResetActiveDockSize,        /// Resets all open docks to their default sizes.        ResetOpenDocksSize,        /// Reloads the application        Reload,        /// Saves the current file with a new name.        SaveAs,        /// Saves without formatting.        SaveWithoutFormat,        /// Shuts down all debug adapters.        ShutdownDebugAdapters,        /// Suppresses the current notification.        SuppressNotification,        /// Toggles the bottom dock.        ToggleBottomDock,        /// Toggles centered layout mode.        ToggleCenteredLayout,        /// Toggles edit prediction feature globally for all files.        ToggleEditPrediction,        /// Toggles the left dock.        ToggleLeftDock,        /// Toggles the right dock.        ToggleRightDock,        /// Toggles zoom on the active pane.        ToggleZoom,        /// Toggles read-only mode for the active item (if supported by that item).        ToggleReadOnlyFile,        /// Zooms in on the active pane.        ZoomIn,        /// Zooms out of the active pane.        ZoomOut,        /// If any worktrees are in restricted mode, shows a modal with possible actions.        /// If the modal is shown already, closes it without trusting any worktree.        ToggleWorktreeSecurity,        /// Clears all trusted worktrees, placing them in restricted mode on next open.        /// Requires restart to take effect on already opened projects.        ClearTrustedWorktrees,        /// Stops following a collaborator.        Unfollow,        /// Restores the banner.        RestoreBanner,        /// Toggles expansion of the selected item.        ToggleExpandItem,    ]); /// Activates a specific pane by its index.#[derive(Clone, Deserialize, PartialEq, JsonSchema, Action)]#[action(namespace = workspace)]pub struct ActivatePane(pub usize); /// Moves an item to a specific pane by index.#[derive(Clone, Deserialize, PartialEq, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct MoveItemToPane {    #[serde(default = "default_1")]    pub destination: usize,    #[serde(default = "default_true")]    pub focus: bool,    #[serde(default)]    pub clone: bool,} fn default_1() -> usize {    1} /// Moves an item to a pane in the specified direction.#[derive(Clone, Deserialize, PartialEq, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct MoveItemToPaneInDirection {    #[serde(default = "default_right")]    pub direction: SplitDirection,    #[serde(default = "default_true")]    pub focus: bool,    #[serde(default)]    pub clone: bool,} /// Creates a new file in a split of the desired direction.#[derive(Clone, Deserialize, PartialEq, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct NewFileSplit(pub SplitDirection); fn default_right() -> SplitDirection {    SplitDirection::Right} /// Saves all open files in the workspace.#[derive(Clone, PartialEq, Debug, Deserialize, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct SaveAll {    #[serde(default)]    pub save_intent: Option<SaveIntent>,} /// Saves the current file with the specified options.#[derive(Clone, PartialEq, Debug, Deserialize, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct Save {    #[serde(default)]    pub save_intent: Option<SaveIntent>,} /// Closes all items and panes in the workspace.#[derive(Clone, PartialEq, Debug, Deserialize, Default, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct CloseAllItemsAndPanes {    #[serde(default)]    pub save_intent: Option<SaveIntent>,} /// Closes all inactive tabs and panes in the workspace.#[derive(Clone, PartialEq, Debug, Deserialize, Default, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct CloseInactiveTabsAndPanes {    #[serde(default)]    pub save_intent: Option<SaveIntent>,} /// Sends a sequence of keystrokes to the active element.#[derive(Clone, Deserialize, PartialEq, JsonSchema, Action)]#[action(namespace = workspace)]pub struct SendKeystrokes(pub String); actions!(    project_symbols,    [        /// Toggles the project symbols search.        #[action(name = "Toggle")]        ToggleProjectSymbols    ]); /// Toggles the file finder interface.#[derive(Default, PartialEq, Eq, Clone, Deserialize, JsonSchema, Action)]#[action(namespace = file_finder, name = "Toggle")]#[serde(deny_unknown_fields)]pub struct ToggleFileFinder {    #[serde(default)]    pub separate_history: bool,} /// Increases size of a currently focused dock by a given amount of pixels.#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct IncreaseActiveDockSize {    /// For 0px parameter, uses UI font size value.    #[serde(default)]    pub px: u32,} /// Decreases size of a currently focused dock by a given amount of pixels.#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct DecreaseActiveDockSize {    /// For 0px parameter, uses UI font size value.    #[serde(default)]    pub px: u32,} /// Increases size of all currently visible docks uniformly, by a given amount of pixels.#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct IncreaseOpenDocksSize {    /// For 0px parameter, uses UI font size value.    #[serde(default)]    pub px: u32,} /// Decreases size of all currently visible docks uniformly, by a given amount of pixels.#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct DecreaseOpenDocksSize {    /// For 0px parameter, uses UI font size value.    #[serde(default)]    pub px: u32,} actions!(    workspace,    [        /// Activates the pane to the left.        ActivatePaneLeft,        /// Activates the pane to the right.        ActivatePaneRight,        /// Activates the pane above.        ActivatePaneUp,        /// Activates the pane below.        ActivatePaneDown,        /// Swaps the current pane with the one to the left.        SwapPaneLeft,        /// Swaps the current pane with the one to the right.        SwapPaneRight,        /// Swaps the current pane with the one above.        SwapPaneUp,        /// Swaps the current pane with the one below.        SwapPaneDown,        // Swaps the current pane with the first available adjacent pane (searching in order: below, above, right, left) and activates that pane.        SwapPaneAdjacent,        /// Move the current pane to be at the far left.        MovePaneLeft,        /// Move the current pane to be at the far right.        MovePaneRight,        /// Move the current pane to be at the very top.        MovePaneUp,        /// Move the current pane to be at the very bottom.        MovePaneDown,    ]); #[derive(PartialEq, Eq, Debug)]pub enum CloseIntent {    /// Quit the program entirely.    Quit,    /// Close a window.    CloseWindow,    /// Replace the workspace in an existing window.    ReplaceWindow,} #[derive(Clone)]pub struct Toast {    id: NotificationId,    msg: Cow<'static, str>,    autohide: bool,    on_click: Option<(Cow<'static, str>, Arc<dyn Fn(&mut Window, &mut App)>)>,} impl Toast {    pub fn new<I: Into<Cow<'static, str>>>(id: NotificationId, msg: I) -> Self {

Lines 1–500 of 11987.