Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(debug): draw the top stack frame column arrow

rokartur5cdb9242e1ef
diff --git a/native/crates/app/src/editor/injected_text.rs b/native/crates/app/src/editor/injected_text.rs
index b28c0710421..ee0109293a3 100644
--- a/native/crates/app/src/editor/injected_text.rs
+++ b/native/crates/app/src/editor/injected_text.rs
@@ -19,6 +19,8 @@ pub enum InjectionOwner {
InlineProgress,
/// A debug inline value after its line (debugEditorContribution.ts `createInlineValueDecoration`).
DebugInlineValue,
+ /// The arrow before a top stack frame's column (callStackEditorContribution.ts `makeStackFrameColumnDecoration`).
+ StackFrameColumn,
}
impl InjectionOwner {
@@ -30,7 +32,7 @@ impl InjectionOwner {
InjectionOwner::InlayHint => CursorStops::Right,
// A debug inline value's `InjectedTextCursorStops.None` sits at the line's end, where Left is the one stop.
InjectionOwner::GhostText | InjectionOwner::DecorationContent | InjectionOwner::DebugInlineValue => CursorStops::Left,
- InjectionOwner::Color | InjectionOwner::InlineProgress => CursorStops::Both,
+ InjectionOwner::Color | InjectionOwner::InlineProgress | InjectionOwner::StackFrameColumn => CursorStops::Both,
}
}
}
diff --git a/native/crates/app/src/workbench.rs b/native/crates/app/src/workbench.rs
index 424b4641925..c556d1e6cf8 100644
--- a/native/crates/app/src/workbench.rs
+++ b/native/crates/app/src/workbench.rs
@@ -623,6 +623,7 @@ impl Render for Workbench {
self.follow_marker_navigation_cursor();
self.follow_references_peek_editor();
self.follow_hierarchy_peek_editor(window, cx);
+ self.sync_stack_frame_columns();
// The floating widgets sit on the rows of each file's diff, recomputed after an edit.
self.update_multi_diff_editor();
self.append_multi_diff_layout_logs();
diff --git a/native/crates/app/src/workbench/breakpoint_widget.rs b/native/crates/app/src/workbench/breakpoint_widget.rs
index c8ea9ad02b0..4c2ca6ff43a 100644
--- a/native/crates/app/src/workbench/breakpoint_widget.rs
+++ b/native/crates/app/src/workbench/breakpoint_widget.rs
@@ -9,6 +9,7 @@ use super::Workbench;
use super::input_box_view::{InputId, InputLook};
use crate::commands::Outcome;
use crate::debug::{Breakpoint, BreakpointData, DebugModel};
+use crate::editor::injected_text::{InjectedText, InjectionOwner, WrapWidth};
use crate::editor::{OpenEditor, Position};
use crate::input_box::InputBox;
use crate::menus::MenuAction;
@@ -348,6 +349,51 @@ impl Workbench {
Some(div().absolute().inset_0().bg(self.color(color)))
}
+ /// `makeStackFrameColumnDecoration` in every editor, run on every render: `\uEB8B` before each stopped thread's
+ /// top frame's column past 1, `width: 0.9em` of the 16px codicon plus `margin-right: 4px` wide, or no room with
+ /// nothing but whitespace before it (`.start-of-line` is absolute).
+ pub(super) fn sync_stack_frame_columns(&mut self) {
+ let char_width = self.editors.viewport.char_width;
+ let wanted: Vec<Vec<InjectedText>> = self.editors.editors.iter().chain(&self.editors.models).map(|editor| self.stack_frame_columns(editor, char_width)).collect();
+ for (editor, injections) in self.editors.editors.iter_mut().chain(&mut self.editors.models).zip(wanted) {
+ let current = editor.injected_text.iter().filter(|injection| injection.owner == InjectionOwner::StackFrameColumn);
+ if !current.eq(injections.iter()) {
+ editor.set_injected_text(InjectionOwner::StackFrameColumn, injections);
+ }
+ }
+ }
+
+ fn stack_frame_columns(&self, editor: &OpenEditor, char_width: f32) -> Vec<InjectedText> {
+ let document = editor.document();
+ if document.scheme != "file" {
+ return Vec::new();
+ }
+ let path = document.path.to_string_lossy();
+ let mut injections = Vec::new();
+ for thread in self.debug.sessions.iter().flat_map(|session| &session.threads).filter(|thread| thread.stopped) {
+ let Some(top) = thread.frames.first().filter(|frame| frame.column > 1 && frame.path() == Some(&*path)) else { continue };
+ // An adapter's line out of the model (callStackEditorContribution.ts warns and skips it).
+ let Some((index, line)) = (top.line as usize).checked_sub(1).and_then(|index| Some((index, document.lines.get(index)?))) else { continue };
+ let column = (top.column as usize - 1).min(line.chars().count());
+ let position = Position::new(index, column);
+ // `getLineFirstNonWhitespaceColumn() >= startColumn`.
+ let start_of_line = line.chars().take(column).all(|c| c == ' ' || c == '\t');
+ let columns = if start_of_line { 0. } else { (0.9 * 16. + 4.) / char_width };
+ if !injections.iter().any(|injection: &InjectedText| injection.position == position) {
+ injections.push(InjectedText { position, columns, content: "\u{EB8B}".into(), wrap: WrapWidth::Fixed, owner: InjectionOwner::StackFrameColumn, id: usize::from(start_of_line), at_range_start: true });
+ }
+ }
+ injections.sort_by_key(|injection| injection.position);
+ injections
+ }
+
+ /// `.debug-top-stack-frame-column`: the codicon 1px up, or `.start-of-line` 17px left of the column, centered.
+ pub(super) fn stack_frame_column_element(&self, start_of_line: bool, left: f32, line_height: f32) -> AnyElement {
+ let icon = self.icon("debug-stackframe", 16., 16., self.color("editor.foreground"));
+ let (left, top) = if start_of_line { (left - 17., 0.) } else { (left, -1.) };
+ div().absolute().top(px(top)).left(px(left)).h(px(line_height)).flex().items_center().child(icon).into_any_element()
+ }
+
/// breakpointEditorContribution.ts `onEditorMouseDown` on the glyph margin: Shift toggles enablement, a click
/// removes (asking first when a condition would be lost) or adds a breakpoint.
fn glyph_margin_clicked(&mut self, uri: &Value, line: u32, shift: bool, window: &mut Window, cx: &mut Context<Self>) {
@@ -692,6 +738,54 @@ mod tests {
std::fs::remove_dir_all(dir).unwrap();
}
+ /// callStackEditorContribution.ts `makeStackFrameColumnDecoration`: a top frame past column 1 injects the arrow
+ /// before its column, 18.4px wide after code; after only whitespace it takes no room.
+ #[gpui::test]
+ fn a_top_frame_past_column_1_injects_the_column_arrow(cx: &mut TestAppContext) {
+ let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
+ let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
+ let theme = crate::theme::load_theme(&[themes], "Dark Modern").unwrap();
+ let dir = std::env::temp_dir().join(format!("vsrustium-{}", crate::test_name()));
+ std::fs::create_dir_all(&dir).unwrap();
+ let file = dir.join("a.js");
+ std::fs::write(&file, "let a = f();\n g();\n").unwrap();
+ let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx));
+ let stop_at = |line: u32, column: u32, workbench: &mut Workbench| {
+ let mut session = Session::new("s".into(), 1, json!({ "name": "s", "type": "node", "request": "launch" }), json!({}), None, json!({}));
+ session.set_threads(&[json!({ "id": 1, "name": "main" })]);
+ let thread = session.thread_mut(1).unwrap();
+ thread.stopped = true;
+ thread.frames = vec![crate::debug::session::StackFrame { id: 3, source: json!({ "path": file.to_string_lossy() }), line, column, ..Default::default() }];
+ workbench.debug.sessions = vec![session];
+ };
+ workbench.update_in(cx, |workbench, window, cx| {
+ workbench.open_file(file.clone(), true, window, cx);
+ stop_at(1, 9, workbench);
+ });
+ cx.run_until_parked();
+ let injected = |workbench: &Workbench| workbench.editors.active().unwrap().injected_text.iter().map(|injection| (injection.position.line, injection.position.column, injection.columns * workbench.editors.viewport.char_width)).collect::<Vec<_>>();
+ let first = workbench.read_with(cx, |workbench, _| injected(workbench));
+ assert_eq!(first.len(), 1);
+ assert_eq!((first[0].0, first[0].1), (0, 8));
+ assert!((first[0].2 - 18.4).abs() < 0.01, "{first:?}");
+ assert!(cx.debug_bounds("codicon-debug-stackframe").is_some(), "the arrow draws");
+
+ workbench.update(cx, |workbench, cx| {
+ stop_at(2, 3, workbench);
+ cx.notify();
+ });
+ cx.run_until_parked();
+ assert_eq!(workbench.read_with(cx, |workbench, _| injected(workbench)), [(1, 2, 0.)]);
+
+ workbench.update(cx, |workbench, cx| {
+ workbench.debug.sessions.clear();
+ cx.notify();
+ });
+ cx.run_until_parked();
+ assert!(workbench.read_with(cx, |workbench, _| injected(workbench)).is_empty());
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
/// A debugger and an extension taking breakpoints in the open document's language.
fn add_debugger(workbench: &mut Workbench) {
workbench.debug.debuggers.push(crate::debug::configuration::Debugger { debug_type: "node".into(), contribution: json!({}), extension_id: "a.node".into() });
diff --git a/native/crates/app/src/workbench/editor_view/injected_text_view.rs b/native/crates/app/src/workbench/editor_view/injected_text_view.rs
index a93430e6404..2b3a6308697 100644
--- a/native/crates/app/src/workbench/editor_view/injected_text_view.rs
+++ b/native/crates/app/src/workbench/editor_view/injected_text_view.rs
@@ -70,6 +70,7 @@ impl Workbench {
InjectionOwner::DecorationContent => self.decoration_content_element(editor, injection.id, left, metrics.line_height),
InjectionOwner::InlineProgress => None,
InjectionOwner::DebugInlineValue => Some(self.debug_inline_value_element(&injection.content, left, metrics.line_height)),
+ InjectionOwner::StackFrameColumn => Some(self.stack_frame_column_element(injection.id == 1, left, metrics.line_height)),
};
elements.extend(element);
}
diff --git a/port/ledger.md b/port/ledger.md
index 32b987ca434..8f2a8edde09 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -530,7 +530,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/contrib/commands | workbench contribution | M9 | verified | | runCommands (commands.rs register_run_commands): cargo test -p app commands::, argument checks, spread args, order, stop at a failure; argument errors and the failure notify (cargo test -p app run_commands_argument_errors_notify) |
| workbench/contrib/comments | workbench contribution | M13 | verified | | workbench/comments_view.rs, workbench/comment_thread_widget.rs, comment_thread_floating.rs, workbench/comment_thread_floating_layout.rs, workbench/comment_node.rs, workbench/commenting_ranges.rs, workbench/comment_navigation.rs, workbench/editor_view/comment_glyph.rs, multi_diff_editor_view.rs: cargo test -p app comment diff floating room multi_diff comment_thread_floating two_threads_keep_their_reply_forms_open_together a_wrapped_comment_body_grows_its_zone the_reached_thread_takes_the_focus a_markdown_comment_previews_its_first_rendered_block the_filter_keeps_its_history_and_escape_clears_it the_thread_menu_replies_to_the_thread a_comment_s_code_span_draws_no_code_block_background additional_actions_show_under_the_body_and_run_with_the_thread a_commenting_range_is_reached_at_its_columns_unless_it_holds_the_cursor dismissing_a_new_template_keeps_it_open an_expanded_thread_shows_a_zone_and_replies_run_the_form_actions a_comment_switched_to_editing_runs_the_edit_actions rows_sit_in_the_pane_s_inset_with_the_tree_s_indent_and_guides (commentThreadFloatingWidget.test.ts); ui-pair `portComments.openDiff` (modified, original, multi, floating), steps-comment-floating.json, steps-comment-additional.json, steps-comment-escape-typed.json, steps-comment-reply-editor.json, steps-comments.json (port/results/language-features.md Comments, Comment editing and commands, Floating comment threads); cargo test -p app reactions_are_action_items_4px_apart |
| workbench/contrib/customEditor | workbench contribution | M17 | ported | [3 L] custom_editors.rs: a diff always opens in the text diff editor, where customEditors.ts `createDiffEditorInput` opens a diff of resources matching an editor's selector (`workbench.diffEditorAssociations`, `priority.diffEditor`) as a `CustomEditorDiffInput` (customEditorDiffInput.ts, inline) or a `DiffEditorInput` of two `CustomEditorSideBySideDiffInput`s or `CustomEditorInput`s, with the proposed `customEditorDiffs` capabilities (`supportsInlineDiff`, `supportsSideBySideDiff`, used by markdown-language-features' preview); so `activeCustomEditorTextDiff` (contextkeys.ts) is never set and Reopen as Text (editor.contribution.ts `ReOpenInTextEditorAction`, `enableInModalMode`) is missing from the editor title and the modal header | cargo test -p app custom_editors each_group_s_custom_text_editor_has_its_own_webview a_custom_text_editor_s_navigation_drives_the_outline a_custom_document_open_in_another_group_moves_to_the_active_one a_custom_document_with_multiple_editors_opens_one_more_in_the_active_group a_workspace_association_wins_over_a_user_one_of_the_same_length a_reopened_preview_keeps_its_tab_position two_default_editors_for_a_resource_ask_once_which_to_keep markdown_editor_files_offer; `FIXTURE=custom-editor-tests port/tools/webview-check` 8/8 |
-| workbench/contrib/debug | workbench contribution | M16 | ported | [3 M] variable_menu.rs: no View Binary Data: debug.contribution.ts registers it only in the rows' `inline` group, and the port's Variables, Watch and hover rows have no inline action bar, no `vscode-debug-memory` file system and no hex editor install prompt (variablesView.ts `VIEW_MEMORY_ID`) <br> [3 S] debug_view.rs: the focused frame's Call Stack row draws `list.inactiveSelectionBackground` where the reference's, with js-debug's compact child session, draws none (ui-pair `debug/variables-menu.json` stopped.png; callStackView.ts `updateTreeSelection`, why its selection does not show not traced) <br> [3 M] debug_visualizers.rs: visualized rows draw only in the Variables view; the Watch view's and the debug hover's expression children keep their plain rows (watchExpressionsView.ts:98, debugHover.ts:142 register `VisualizedVariableRenderer`) <br> [3 S] debug_service.rs: `guess_debugger`'s Select Debugger picker has no "More {0} options..." picks of the dynamic configuration providers (debugAdapterManager.ts `getDynamicProviders`), which the port does not have <br> [3 S] debugQuickAccess.ts: the picker has no dynamic configuration providers' `{label}...` picks with the `contributed` description, where the reference lists `Node.js...` (ui-pair `debug/quick-access.json`, `FOLDER=port/fixtures/debug-node`) <br> [3 M] debug_editor: the stopped line has no `debug-top-stack-frame-column` inline arrow before the frame's column (callStackEditorContribution.ts `makeStackFrameColumnDecoration`) and no inline breakpoint candidate dots (breakpointEditorContribution.ts, `breakpointLocations` request) (ui-pair `debug/variables-menu.json`, line 5 of app.js) | cargo test -p app debug launch_picker_shrinks the_debug_container_more_actions debug_service a_workbench_hover_draws_over_the_debug_hover the_tree_height_keeps_an_above_hover_off_the_hovered_line watch_expression_labels_use_the_monospace_font debug_view debug_task_runner debug_commands debug_console debug::ansi an_ended_session_stays_in_the_picker_until_cleared_or_started_again a_start_or_restart_saves_the_dirty_editors a_hit_breakpoint_enables_its_dependents debug_inline_values debug_hover alt_click_toggles_the_loaded_subtree a_click_on_a_hover_row_focuses_the_tree a_lazy_row_takes_its_value_from_the_eye_button the_find_widget_filters_the_hover_tree disassembly list_tree a_step_in_the_disassembly_view debug::tests::instruction_breakpoints debug::tests::remove_instruction_breakpoints a_right_clicked_call_stack_row_takes_the_list_focus the_debug_toolbar_and_create_configuration_menus_take_contributed_items debug_toolbar variable_menu a_stop_on_a_line_in_view_keeps_the_scroll the_debug_picker_lists_and_starts_the_launch_configurations the_first_scope_expands_only_once_the_variables_view_exists the_find_widget_filters_the_console a_variable_row_draws_its_scopes_indent_guide; ui-pair port/fixtures/debug-node (breakpoint, F5, views, REPL, toolbar, `greeting` and `numbers` hovers), menus/view-container-title.json, port/fixtures/ui-pair/debug/hover-find.json, port/fixtures/ui-pair/debug/unverified-breakpoints.json, port/fixtures/ui-pair/debug/call-stack-menu.json, port/fixtures/ui-pair/debug/toolbar.json, port/fixtures/ui-pair/debug/variables-menu.json, port/fixtures/ui-pair/debug/lazy-variable.json, port/fixtures/ui-pair/debug/quick-access.json; shortcuts in port/notes.md |
+| workbench/contrib/debug | workbench contribution | M16 | ported | [3 M] variable_menu.rs: no View Binary Data: debug.contribution.ts registers it only in the rows' `inline` group, and the port's Variables, Watch and hover rows have no inline action bar, no `vscode-debug-memory` file system and no hex editor install prompt (variablesView.ts `VIEW_MEMORY_ID`) <br> [3 S] debug_view.rs: the focused frame's Call Stack row draws `list.inactiveSelectionBackground` where the reference's, with js-debug's compact child session, draws none (ui-pair `debug/variables-menu.json` stopped.png; callStackView.ts `updateTreeSelection`, why its selection does not show not traced) <br> [3 M] debug_visualizers.rs: visualized rows draw only in the Variables view; the Watch view's and the debug hover's expression children keep their plain rows (watchExpressionsView.ts:98, debugHover.ts:142 register `VisualizedVariableRenderer`) <br> [3 S] debug_service.rs: `guess_debugger`'s Select Debugger picker has no "More {0} options..." picks of the dynamic configuration providers (debugAdapterManager.ts `getDynamicProviders`), which the port does not have <br> [3 S] debugQuickAccess.ts: the picker has no dynamic configuration providers' `{label}...` picks with the `contributed` description, where the reference lists `Node.js...` (ui-pair `debug/quick-access.json`, `FOLDER=port/fixtures/debug-node`) <br> [3 M] debug_editor: no inline breakpoint widgets: neither the candidate dots (breakpointEditorContribution.ts `requestBreakpointCandidateLocations`, `breakpointLocations` request on the breakpoints' lines) nor the `InlineBreakpointWidget` of a column breakpoint (ui-pair `debug/variables-menu.json`, line 5 of app.js) | cargo test -p app debug launch_picker_shrinks the_debug_container_more_actions debug_service a_workbench_hover_draws_over_the_debug_hover the_tree_height_keeps_an_above_hover_off_the_hovered_line watch_expression_labels_use_the_monospace_font debug_view debug_task_runner debug_commands debug_console debug::ansi an_ended_session_stays_in_the_picker_until_cleared_or_started_again a_start_or_restart_saves_the_dirty_editors a_hit_breakpoint_enables_its_dependents debug_inline_values debug_hover alt_click_toggles_the_loaded_subtree a_click_on_a_hover_row_focuses_the_tree a_lazy_row_takes_its_value_from_the_eye_button the_find_widget_filters_the_hover_tree disassembly list_tree a_step_in_the_disassembly_view debug::tests::instruction_breakpoints debug::tests::remove_instruction_breakpoints a_right_clicked_call_stack_row_takes_the_list_focus the_debug_toolbar_and_create_configuration_menus_take_contributed_items debug_toolbar variable_menu a_stop_on_a_line_in_view_keeps_the_scroll the_debug_picker_lists_and_starts_the_launch_configurations the_first_scope_expands_only_once_the_variables_view_exists the_find_widget_filters_the_console a_variable_row_draws_its_scopes_indent_guide a_top_frame_past_column_1_injects_the_column_arrow; ui-pair port/fixtures/debug-node (breakpoint, F5, views, REPL, toolbar, `greeting` and `numbers` hovers), menus/view-container-title.json, port/fixtures/ui-pair/debug/hover-find.json, port/fixtures/ui-pair/debug/unverified-breakpoints.json, port/fixtures/ui-pair/debug/call-stack-menu.json, port/fixtures/ui-pair/debug/toolbar.json, port/fixtures/ui-pair/debug/variables-menu.json, port/fixtures/ui-pair/debug/lazy-variable.json, port/fixtures/ui-pair/debug/quick-access.json; shortcuts in port/notes.md |
| workbench/contrib/dropOrPasteInto | workbench contribution | M13 | verified | | commands.ts `configurePreferredPasteAction`/`configurePreferredDropAction`: the widgets' menus and the Paste As pick open user settings JSON at `editor.pasteAs.preferences` or `editor.dropIntoEditor.preferences` (workbench/paste_edits.rs); the `editor.pasteAs.*` and `editor.dropIntoEditor.*` settings come from core-settings.json; ui-pair paste-menu (port/results/language-features.md) |
| workbench/contrib/editSessions | workbench contribution | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
| workbench/contrib/editTelemetry | workbench contribution | | removed | | no AI or Microsoft services by decision (port/notes.md); API stays inert |