10748 lines · 387.7 KB · Rust
RawDownload
pub mod dock;pub mod history_manager;pub mod item;mod modal_layer;pub mod notifications;pub mod pane;pub mod pane_group;mod persistence;pub mod searchable;pub mod shared_screen;mod status_bar;pub mod tasks;mod theme_preview;mod toast_layer;mod toolbar;mod workspace_settings; 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};pub use dock::Panel;use dock::{Dock, DockPosition, PanelButtons, PanelHandle, RESIZE_HANDLE_SIZE};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, 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};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::*;use persistence::{    DB, SerializedWindowBounds,    model::{SerializedSshProject, SerializedWorkspace},};pub use persistence::{    DB as WORKSPACE_DB, WorkspaceDb, delete_unloaded_items,    model::{ItemId, LocalPaths, SerializedWorkspaceLocation},};use postage::stream::Stream;use project::{    DirectoryLister, Project, ProjectEntryId, ProjectPath, ResolvedPath, Worktree, WorktreeId,    debugger::{breakpoint_store::BreakpointStoreEvent, session::ThreadStatus},};use remote::{SshClientDelegate, SshConnectionOptions, ssh_session::ConnectionIdentifier};use schemars::JsonSchema;use serde::Deserialize;use session::AppSession;use settings::Settings;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::AtomicUsize},    time::Duration,};use task::{DebugScenario, SpawnInTerminal, TaskContext};use theme::{ActiveTheme, SystemAppearance, ThemeSettings};pub use toolbar::{Toolbar, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};pub use ui;use ui::{Window, prelude::*};use util::{ResultExt, TryFutureExt, paths::SanitizedPath, serde::default_true};use uuid::Uuid;pub use workspace_settings::{    AutosaveSetting, BottomDockLayout, RestoreOnStartupBehavior, TabBarSettings, WorkspaceSettings,};use zed_actions::{Spawn, feedback::FileBugReport}; use crate::notifications::NotificationId;use crate::persistence::{    SerializedAxis,    model::{DockData, DockStructure, SerializedItem, SerializedPane, SerializedPaneGroup},}; 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,        /// Closes the active dock.        CloseActiveDock,        /// Closes all docks.        CloseAllDocks,        /// 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,        /// 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 the left dock.        ToggleLeftDock,        /// Toggles the right dock.        ToggleRightDock,        /// Toggles zoom on the active pane.        ToggleZoom,        /// Stops following a collaborator.        Unfollow,        /// Shows the welcome screen.        Welcome,        /// Restores the banner.        RestoreBanner,        /// Toggles expansion of the selected item.        ToggleExpandItem,    ]); #[derive(Clone, PartialEq)]pub struct OpenPaths {    pub paths: Vec<PathBuf>,} /// 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,} 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); /// Reloads the active item or workspace.#[derive(Clone, Deserialize, PartialEq, Default, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct Reload {    pub binary_path: Option<PathBuf>,} 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,    ]); #[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 {        Toast {            id,            msg: msg.into(),            on_click: None,            autohide: false,        }    }     pub fn on_click<F, M>(mut self, message: M, on_click: F) -> Self    where        M: Into<Cow<'static, str>>,        F: Fn(&mut Window, &mut App) + 'static,    {        self.on_click = Some((message.into(), Arc::new(on_click)));        self    }     pub fn autohide(mut self) -> Self {        self.autohide = true;        self    }} impl PartialEq for Toast {    fn eq(&self, other: &Self) -> bool {        self.id == other.id            && self.msg == other.msg            && self.on_click.is_some() == other.on_click.is_some()    }} /// Opens a new terminal with the specified working directory.#[derive(Debug, Default, Clone, Deserialize, PartialEq, JsonSchema, Action)]#[action(namespace = workspace)]#[serde(deny_unknown_fields)]pub struct OpenTerminal {    pub working_directory: PathBuf,} #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]pub struct WorkspaceId(i64); impl StaticColumnCount for WorkspaceId {}impl Bind for WorkspaceId {    fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {        self.0.bind(statement, start_index)    }}impl Column for WorkspaceId {    fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {        i64::column(statement, start_index)            .map(|(i, next_index)| (Self(i), next_index))            .with_context(|| format!("Failed to read WorkspaceId at index {start_index}"))    }}

Lines 1–500 of 10748.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t