From 63ed15c9cbcf6bcb3f6aa22f98b7a3fafa31b8cd Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Wed, 11 Nov 2026 09:11:23 +0700 Subject: [PATCH] editor: rename code/diff view features and modules --- crates/editor/Cargo.toml | 12 ++++---- crates/editor/src/{code_view.rs => code.rs} | 0 crates/editor/src/{diff_view.rs => diff.rs} | 0 crates/editor/src/lib.rs | 10 +++---- crates/editor/src/utils.rs | 28 +++++++++---------- crates/editor/tests/{code_view.rs => code.rs} | 6 ++-- .../{code_view_bench.rs => code_bench.rs} | 2 +- crates/editor/tests/{diff_view.rs => diff.rs} | 2 +- .../{diff_view_bench.rs => diff_bench.rs} | 2 +- examples/gallery/src/main.rs | 6 ++-- 10 files changed, 34 insertions(+), 34 deletions(-) rename crates/editor/src/{code_view.rs => code.rs} (100%) rename crates/editor/src/{diff_view.rs => diff.rs} (100%) rename crates/editor/tests/{code_view.rs => code.rs} (96%) rename crates/editor/tests/{code_view_bench.rs => code_bench.rs} (98%) rename crates/editor/tests/{diff_view.rs => diff.rs} (99%) rename crates/editor/tests/{diff_view_bench.rs => diff_bench.rs} (98%) diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index 226ca09..4d0998b 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -27,21 +27,21 @@ gpui = { workspace = true, features = ["test-support"] } [features] default = ["full"] full = [ - "code_view", - "diff_view", - "markdown_view", + "code", + "diff", + "markdown", "rust", "typescript", "javascript", "python", ] -code_view = [ +code = [ "dep:gpui-native-core", "gpui-native-core/scroll_area", "gpui-native-core/scrollbar", ] -diff_view = ["code_view"] -markdown_view = [ +diff = ["code"] +markdown = [ "dep:gpui-native-core", "gpui-native-core/button", "gpui-native-core/checkbox", diff --git a/crates/editor/src/code_view.rs b/crates/editor/src/code.rs similarity index 100% rename from crates/editor/src/code_view.rs rename to crates/editor/src/code.rs diff --git a/crates/editor/src/diff_view.rs b/crates/editor/src/diff.rs similarity index 100% rename from crates/editor/src/diff_view.rs rename to crates/editor/src/diff.rs diff --git a/crates/editor/src/lib.rs b/crates/editor/src/lib.rs index 4b63f15..32c158b 100644 --- a/crates/editor/src/lib.rs +++ b/crates/editor/src/lib.rs @@ -2,13 +2,13 @@ //! code views, one cargo feature per language grammar. A language whose //! grammar feature is off renders as plain text. -#[cfg(feature = "code_view")] -pub mod code_view; +#[cfg(feature = "code")] +pub mod code; -#[cfg(feature = "diff_view")] -pub mod diff_view; +#[cfg(feature = "diff")] +pub mod diff; -#[cfg(feature = "markdown_view")] +#[cfg(feature = "markdown")] pub mod markdown; pub mod highlight; diff --git a/crates/editor/src/utils.rs b/crates/editor/src/utils.rs index 6a9ba56..285a2d1 100644 --- a/crates/editor/src/utils.rs +++ b/crates/editor/src/utils.rs @@ -1,24 +1,24 @@ //! Shared helpers for the editor's views: gutter cells, role colors and run //! styles, code line text, language mapping and change washes. -#[cfg(any(feature = "code_view", feature = "markdown_view"))] +#[cfg(any(feature = "code", feature = "markdown"))] use std::ops::Range; -#[cfg(feature = "markdown_view")] +#[cfg(feature = "markdown")] use crate::highlight::{Language, Line}; -#[cfg(feature = "markdown_view")] +#[cfg(feature = "markdown")] use gpui::StyledText; -#[cfg(any(feature = "code_view", feature = "markdown_view"))] +#[cfg(any(feature = "code", feature = "markdown"))] use gpui::{App, HighlightStyle, Hsla, IntoElement, ParentElement as _, Styled as _, div}; -#[cfg(any(feature = "code_view", feature = "markdown_view"))] +#[cfg(any(feature = "code", feature = "markdown"))] use gpui_native_theme::{ActiveTheme as _, ColorTokens, Ramps}; -#[cfg(feature = "diff_view")] +#[cfg(feature = "diff")] use gpui_native_theme::{WASH_ALPHA, WASH_ALPHA_GUTTER, WASH_ALPHA_STRONG}; -#[cfg(any(feature = "code_view", feature = "markdown_view"))] +#[cfg(any(feature = "code", feature = "markdown"))] use crate::highlight::Role; -#[cfg(any(feature = "code_view", feature = "markdown_view"))] +#[cfg(any(feature = "code", feature = "markdown"))] impl Role { /// Maps the role to the theme's semantic palette. pub(crate) fn color(self, colors: ColorTokens, ramps: Ramps) -> Hsla { @@ -50,7 +50,7 @@ impl Role { } } -#[cfg(feature = "markdown_view")] +#[cfg(feature = "markdown")] impl Language { /// Maps a fence info string to a bundled grammar. pub(crate) fn from_fence_info(info: &str) -> Option { @@ -65,7 +65,7 @@ impl Language { } /// A gutter cell sized to the whole row. -#[cfg(feature = "code_view")] +#[cfg(feature = "code")] pub(crate) fn gutter_cell(cx: &App, color: Hsla, content: E) -> gpui::Div where E: IntoElement, @@ -86,7 +86,7 @@ where } /// A change wash: the ramp color at the alpha rows tint with. -#[cfg(feature = "diff_view")] +#[cfg(feature = "diff")] pub(crate) fn wash(color: Hsla) -> Hsla { Hsla { a: color.a * WASH_ALPHA, @@ -95,7 +95,7 @@ pub(crate) fn wash(color: Hsla) -> Hsla { } /// The stronger wash under number gutters and intra-line word changes. -#[cfg(feature = "diff_view")] +#[cfg(feature = "diff")] pub(crate) fn wash_strong(color: Hsla) -> Hsla { Hsla { a: color.a * WASH_ALPHA_STRONG, @@ -104,7 +104,7 @@ pub(crate) fn wash_strong(color: Hsla) -> Hsla { } /// The subtle wash that sets the number gutter off from the code. -#[cfg(feature = "diff_view")] +#[cfg(feature = "diff")] pub(crate) fn wash_gutter(colors: &ColorTokens) -> Hsla { Hsla { a: colors.muted.a * WASH_ALPHA_GUTTER, @@ -113,7 +113,7 @@ pub(crate) fn wash_gutter(colors: &ColorTokens) -> Hsla { } /// One highlighted code line as styled text, roles resolved from the theme. -#[cfg(feature = "markdown_view")] +#[cfg(feature = "markdown")] pub(crate) fn code_line(line: &Line, colors: ColorTokens, ramps: Ramps) -> StyledText { let mut highlights: Vec<(Range, HighlightStyle)> = Vec::new(); let mut offset = 0usize; diff --git a/crates/editor/tests/code_view.rs b/crates/editor/tests/code.rs similarity index 96% rename from crates/editor/tests/code_view.rs rename to crates/editor/tests/code.rs index 4570ad9..22f1376 100644 --- a/crates/editor/tests/code_view.rs +++ b/crates/editor/tests/code.rs @@ -5,7 +5,7 @@ use gpui::{ AppContext as _, Context, Entity, Focusable as _, IntoElement, ParentElement as _, Render, Styled as _, TestAppContext, VisualTestContext, Window, div, }; -use gpui_native_editor::code_view::{CodeViewState, bind_code_view_keys}; +use gpui_native_editor::code::{CodeViewState, bind_code_view_keys}; use gpui_native_editor::highlight::{HighlightedCode, Language, Role, highlight}; fn spans_with_role(code: &HighlightedCode, role: Role) -> Vec<&str> { @@ -176,8 +176,8 @@ fn selecting_then_copying_writes_the_clipboard() { cx.update(|cx| { state.update(cx, |state, cx| { state.select_range( - gpui_native_editor::code_view::SelectionPoint { row: 0, col: 0 }, - gpui_native_editor::code_view::SelectionPoint { row: 0, col: 3 }, + gpui_native_editor::code::SelectionPoint { row: 0, col: 0 }, + gpui_native_editor::code::SelectionPoint { row: 0, col: 3 }, cx, ); }); diff --git a/crates/editor/tests/code_view_bench.rs b/crates/editor/tests/code_bench.rs similarity index 98% rename from crates/editor/tests/code_view_bench.rs rename to crates/editor/tests/code_bench.rs index 52efc70..3fca0a8 100644 --- a/crates/editor/tests/code_view_bench.rs +++ b/crates/editor/tests/code_bench.rs @@ -8,7 +8,7 @@ use gpui::{ ScrollDelta, ScrollEvent, Styled as _, TestAppContext, VisualTestContext, Window, div, point, px, }; -use gpui_native_editor::code_view::{CodeViewState, bind_code_view_keys}; +use gpui_native_editor::code::{CodeViewState, bind_code_view_keys}; use gpui_native_editor::highlight::Language; /// Deterministic pseudo-Rust with mixed tokens, roughly `lines` lines long. diff --git a/crates/editor/tests/diff_view.rs b/crates/editor/tests/diff.rs similarity index 99% rename from crates/editor/tests/diff_view.rs rename to crates/editor/tests/diff.rs index 0110b45..dfffbac 100644 --- a/crates/editor/tests/diff_view.rs +++ b/crates/editor/tests/diff.rs @@ -5,7 +5,7 @@ use gpui::{ AppContext as _, Context, Entity, IntoElement, MouseButton, ParentElement as _, Render, Styled as _, TestAppContext, VisualTestContext, Window, div, point, px, }; -use gpui_native_editor::diff_view::{DiffRow, DiffRowKind, DiffViewState}; +use gpui_native_editor::diff::{DiffRow, DiffRowKind, DiffViewState}; use gpui_native_editor::highlight::{Language, Role}; const OLD: &str = "fn a() {}\nfn b() {}\nfn c() {}\n"; diff --git a/crates/editor/tests/diff_view_bench.rs b/crates/editor/tests/diff_bench.rs similarity index 98% rename from crates/editor/tests/diff_view_bench.rs rename to crates/editor/tests/diff_bench.rs index c31f423..27d20b5 100644 --- a/crates/editor/tests/diff_view_bench.rs +++ b/crates/editor/tests/diff_bench.rs @@ -8,7 +8,7 @@ use gpui::{ ScrollDelta, ScrollEvent, Styled as _, TestAppContext, VisualTestContext, Window, div, point, px, }; -use gpui_native_editor::diff_view::DiffViewState; +use gpui_native_editor::diff::DiffViewState; /// Deterministic old/new pairs of roughly `lines` lines each, with changes /// sprinkled through. diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index 3dd10c9..d30c2e6 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -44,8 +44,8 @@ use gpui_native_data::list::{List, ListItem}; use gpui_native_data::sidebar::{Sidebar, SidebarEntry}; use gpui_native_data::tabs::{Tab, Tabs, TabsVariant}; use gpui_native_data::tree::{Tree, TreeItem}; -use gpui_native_editor::code_view::CodeViewState; -use gpui_native_editor::diff_view::{DiffRowKind, DiffViewState}; +use gpui_native_editor::code::CodeViewState; +use gpui_native_editor::diff::{DiffRowKind, DiffViewState}; use gpui_native_editor::highlight::Language; use gpui_native_editor::markdown::{ListMarker, MarkdownBlock, MarkdownViewState, TextView}; use gpui_native_icons::{IconAssets, IconRole, icon}; @@ -4163,7 +4163,7 @@ fn main() { .with_http_client(std::sync::Arc::new(reqwest_client::ReqwestClient::new())) .run(|cx: &mut App| { gpui_native_core::init(cx); - gpui_native_editor::code_view::bind_code_view_keys(cx); + gpui_native_editor::code::bind_code_view_keys(cx); gpui_native_editor::markdown::bind_text_view_keys(cx); cx.bind_keys([