debugger: Add run to cursor and evaluate selected text actions (#28405)
## Summary ### Actions This PR implements actions that allow a user to "run to cursor" and "evaluate selected text" while there's an active debug session and exposes the functionality to the UI as well. - Run to cursor: Can be accessed by right clicking on the gutter - Evaluate selected text: Can be accessed by selecting text then right clicking in the editor ### Bug fixes I also fixed these bugs as well - Panic when using debugger: Stop action - Debugger actions command palette filter not working properly in all cases - We stopped displaying the correct label in the session's context menu when a session was terminated Release Notes: - N/A --------- Co-authored-by: Max Brunsfeld <max@zed.dev> Co-authored-by: Remco Smits <djsmits12@gmail.com>
This commit is contained in:
parent
780143298a
commit
2752c08810
15 changed files with 334 additions and 102 deletions
|
@ -35,6 +35,7 @@ assets.workspace = true
|
|||
client.workspace = true
|
||||
clock.workspace = true
|
||||
collections.workspace = true
|
||||
command_palette_hooks.workspace = true
|
||||
convert_case.workspace = true
|
||||
db.workspace = true
|
||||
buffer_diff.workspace = true
|
||||
|
|
|
@ -408,6 +408,8 @@ actions!(
|
|||
DisableBreakpoint,
|
||||
EnableBreakpoint,
|
||||
EditLogBreakpoint,
|
||||
DebuggerRunToCursor,
|
||||
DebuggerEvaluateSelectedText,
|
||||
ToggleAutoSignatureHelp,
|
||||
ToggleGitBlameInline,
|
||||
OpenGitBlameCommit,
|
||||
|
|
|
@ -6415,6 +6415,9 @@ impl Editor {
|
|||
"Set Breakpoint"
|
||||
};
|
||||
|
||||
let run_to_cursor = command_palette_hooks::CommandPaletteFilter::try_global(cx)
|
||||
.map_or(false, |filter| !filter.is_hidden(&DebuggerRunToCursor));
|
||||
|
||||
let toggle_state_msg = breakpoint.as_ref().map_or(None, |bp| match bp.1.state {
|
||||
BreakpointState::Enabled => Some("Disable"),
|
||||
BreakpointState::Disabled => Some("Enable"),
|
||||
|
@ -6426,6 +6429,21 @@ impl Editor {
|
|||
ui::ContextMenu::build(window, cx, |menu, _, _cx| {
|
||||
menu.on_blur_subscription(Subscription::new(|| {}))
|
||||
.context(focus_handle)
|
||||
.when(run_to_cursor, |this| {
|
||||
let weak_editor = weak_editor.clone();
|
||||
this.entry("Run to cursor", None, move |window, cx| {
|
||||
weak_editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
s.select_ranges([Point::new(row, 0)..Point::new(row, 0)])
|
||||
});
|
||||
})
|
||||
.ok();
|
||||
|
||||
window.dispatch_action(Box::new(DebuggerRunToCursor), cx);
|
||||
})
|
||||
.separator()
|
||||
})
|
||||
.when_some(toggle_state_msg, |this, msg| {
|
||||
this.entry(msg, None, {
|
||||
let weak_editor = weak_editor.clone();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use crate::CopyAndTrim;
|
||||
use crate::actions::FormatSelections;
|
||||
use crate::{
|
||||
Copy, CopyPermalinkToLine, Cut, DisplayPoint, DisplaySnapshot, Editor, EditorMode,
|
||||
FindAllReferences, GoToDeclaration, GoToDefinition, GoToImplementation, GoToTypeDefinition,
|
||||
Paste, Rename, RevealInFileManager, SelectMode, ToDisplayPoint, ToggleCodeActions,
|
||||
actions::Format, selections_collection::SelectionsCollection,
|
||||
Copy, CopyAndTrim, CopyPermalinkToLine, Cut, DebuggerEvaluateSelectedText, DisplayPoint,
|
||||
DisplaySnapshot, Editor, EditorMode, FindAllReferences, GoToDeclaration, GoToDefinition,
|
||||
GoToImplementation, GoToTypeDefinition, Paste, Rename, RevealInFileManager, SelectMode,
|
||||
ToDisplayPoint, ToggleCodeActions,
|
||||
actions::{Format, FormatSelections},
|
||||
selections_collection::SelectionsCollection,
|
||||
};
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{Context, DismissEvent, Entity, Focusable as _, Pixels, Point, Subscription, Window};
|
||||
|
@ -169,9 +169,19 @@ pub fn deploy_context_menu(
|
|||
.is_some()
|
||||
});
|
||||
|
||||
let evaluate_selection = command_palette_hooks::CommandPaletteFilter::try_global(cx)
|
||||
.map_or(false, |filter| {
|
||||
!filter.is_hidden(&DebuggerEvaluateSelectedText)
|
||||
});
|
||||
|
||||
ui::ContextMenu::build(window, cx, |menu, _window, _cx| {
|
||||
let builder = menu
|
||||
.on_blur_subscription(Subscription::new(|| {}))
|
||||
.when(evaluate_selection && has_selections, |builder| {
|
||||
builder
|
||||
.action("Evaluate Selection", Box::new(DebuggerEvaluateSelectedText))
|
||||
.separator()
|
||||
})
|
||||
.action("Go to Definition", Box::new(GoToDefinition))
|
||||
.action("Go to Declaration", Box::new(GoToDeclaration))
|
||||
.action("Go to Type Definition", Box::new(GoToTypeDefinition))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue