Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Fleet Dark
# A take on the JetBrains Fleet theme. Feel free to contribute

# Original author: @krfl
# Contributors:
# @matoous
# @kirawi

"attribute" = "Lime"

"type" = "Blue"
"type.return" = "Blue Light"
"type.parameter" = "Blue Light"
"constructor" = "Yellow"

"constant" = "Violet"
# "constant.builtin" = {} # .boolean
"constant.builtin.boolean" = "Cyan"
"constant.character" = "Yellow"
"constant.character.escape" = "Cyan"
"constant.numeric" = "Yellow"
"string" = "Pink"
"string.regexp" = "Cyan"
"string.special" = { fg = "Yellow", modifiers = ["underlined"] } #.path / .url / .symbol

"comment" = "Gray 90" # .line
# "comment.block" = {} # .documentation
"variable" = "Gray 120" # .builtin
"variable.builtin" = { fg = "Coral" }
# "variable.other" = {} # .member
"variable.other.member" = "Violet"
"label" = "Yellow"
"keyword" = "Cyan" # .operator / .directive / .function
"function" = "Yellow"
"function.declaration" = "#EFEFEF"
"function.macro" = "Lime"
"function.builtin" = "Lime"
"function.special" = "Lime"
#"function.declaration.method" = { fg = "lightest", modifiers = ["bold"] } #depends on #4892
"tag" = "Blue"
"special" = "Lime"
"namespace" = "Blue"

# used in theming
# "markup" = {} # .normal / .quote / .raw
# "markup.normal" = {} # .completion / .hover
"markup.bold" = {  modifiers = ["bold"] }
"markup.italic" = { modifiers = ["italic"] }
"markup.strikethrough" = { modifiers = ["crossed_out"] }
"markup.heading" = { fg = "Cyan", modifiers = ["bold"] } # .marker / .1 / .2 / .3 / .4 / .5 / .6
"markup.list" = "Pink" # .unnumbered / .numbered
"markup.list.numbered" = "Cyan"
"markup.list.unnumbered" = "Cyan"
# "markup.link" = "green"
"markup.link.url" = { fg = "Pink", modifiers = ['italic', 'underlined'] }
"markup.link.text" = "Cyan"
"markup.link.label" = "Purple 20"
"markup.quote" = "Pink"
"markup.raw" = "Pink"
"markup.raw.inline" = "Cyan" # .completion / .hover
"markup.raw.block" = "#EB83E2"

"diff.plus" = "Green 50"
"diff.minus" = "Red 50"
"diff.delta" = "Blue 80"

# ui specific
"ui.background" = { bg = "Gray 10" } # .separator
"ui.statusline" = { fg = "Gray 120", bg = "Gray 20" } # .inactive / .normal / .insert / .select
"ui.statusline.normal" = { fg = "Gray 120", bg = "Gray 20" }
"ui.statusline.inactive" = { fg = "Gray 90"}
"ui.statusline.insert" = { fg = "Gray 20", bg = "Blue 90" }
"ui.statusline.select" = { fg = "Gray 20", bg = "Yellow 60" }

"ui.cursor" = { modifiers = ["reversed"] } # .insert / .select / .match / .primary
"ui.cursor.match" = { bg = "Blue 30" } # .insert / .select / .match / .primary
"ui.selection" = { bg = "Gray 50" } # .primary
"ui.selection.primary" = { bg = "Blue 40" }

"ui.cursorline" = { bg = "Gray 20" }
"ui.linenr" = "Gray 70"
"ui.linenr.selected" = "Gray 110"

"ui.popup" = { fg = "Gray 120", bg = "Gray 20" } # .info
"ui.window" = { fg = "Gray 50" }
"ui.help" = { fg = "Gray 120", bg = "Gray 20" }
"ui.menu" = { fg = "Gray 120", bg = "Gray 20" } # .selected
"ui.menu.selected" = { fg = "White", bg = "Blue 40" } # .selected
# Calculated as #ffffff with 30% opacity
"ui.menu.scroll" = { fg = "#dfdfdf" }

"ui.text" = "Gray 120" # .focus / .info
"ui.text.focus" = { fg = "White", bg = "Blue 40" }

"ui.virtual" = "Gray 90" # .whitespace
"ui.virtual.inlay-hint" = { fg = "Gray 70" }
"ui.virtual.ruler" = { bg = "Gray 20" }

"hint" = "Gray 80"
"info" = "#A366C4"
"warning" = "#FACb66"
"error" = "#FF5269"

"diagnostic.hint" = { underline = { color = "Gray 80", style = "line" } }
"diagnostic.info" = { underline = { color = "#A366C4", style = "line" } }
"diagnostic.warning" = { underline = { color = "#FACB66", style = "line" } }
"diagnostic.error" = { underline = { color = "#FF5269", style = "line" } }

[palette]
"White" = "#ffffff"
"Gray 120" = "#d1d1d1"
"Gray 110" = "#c2c2c2"
"Gray 100" = "#a0a0a0"
"Gray 90" = "#898989"
"Gray 80" = "#767676"
"Gray 70" = "#5d5d5d"
"Gray 60" = "#484848"
"Gray 50" = "#383838"
"Gray 40" = "#333333"
"Gray 30" = "#2d2d2d"
"Gray 20" = "#292929"
"Gray 10" = "#181818"
"Black" = "#000000"
"Blue 110" = "#6daaf7"
"Blue 100" = "#4d9bf8"
"Blue 90" = "#3691f9"
"Blue 80" = "#1a85f6"
"Blue 70" = "#0273eb"
"Blue 60" = "#0c6ddd"
"Blue 50" = "#195eb5"
"Blue 40" = "#194176"
"Blue 30" = "#163764"
"Blue 20" = "#132c4f"
"Blue 10" = "#0b1b32"
"Red 80" = "#ec7388"
"Red 70" = "#ea4b67"
"Red 60" = "#d93953"
"Red 50" = "#ce364d"
"Red 40" = "#c03248"
"Red 30" = "#a72a3f"
"Red 20" = "#761b2d"
"Red 10" = "#390813"
"Green 50" = "#4ca988"
"Green 40" = "#3ea17f"
"Green 30" = "#028764"
"Green 20" = "#134939"
"Green 10" = "#081f19"
"Yellow 60" = "#f8ab17"
"Yellow 50" = "#e1971b"
"Yellow 40" = "#b5791f"
"Yellow 30" = "#7c511a"
"Yellow 20" = "#5a3a14"
"Yellow 10" = "#281806"
"Purple 20" = "#c07bf3"
"Purple 10" = "#b35def"

"Blue" = "#87C3FF"
"Blue Light" = "#ADD1DE"
"Coral" = "#CC7C8A"
"Cyan" = "#82D2CE"
"Cyan Dark" = "#779E9E"
"Lime" = "#A8CC7C"
"Orange" = "#E09B70"
"Pink" = "#E394DC"
"Violet" = "#AF9CFF"
"Yellow" = "#EBC88D"
rame { jump_to_stack_frame(editor, frame); } } pub async fn fetch_stack_trace(debugger: &mut Client, thread_id: ThreadId) { let (frames, _) = match debugger.stack_trace(thread_id).await { Ok(frames) => frames, Err(_) => return, }; debugger.stack_frames.insert(thread_id, frames); debugger.active_frame = Some(0); } pub fn jump_to_stack_frame(editor: &mut Editor, frame: &helix_dap::StackFrame) { let path = if let Some(helix_dap::Source { path: Some(ref path), .. }) = frame.source { path.clone() } else { return; }; if let Err(e) = editor.open(&path, Action::Replace) { editor.set_error(format!("Unable to jump to stack frame: {}", e)); return; } let (view, doc) = current!(editor); let text_end = doc.text().len_chars().saturating_sub(1); let start = dap_pos_to_pos(doc.text(), frame.line, frame.column).unwrap_or(0); let end = frame .end_line .and_then(|end_line| dap_pos_to_pos(doc.text(), end_line, frame.end_column.unwrap_or(0))) .unwrap_or(start); let selection = Selection::single(start.min(text_end), end.min(text_end)); doc.set_selection(view.id, selection); align_view(doc, view, Align::Center); } pub fn breakpoints_changed( debugger: &mut dap::Client, path: PathBuf, breakpoints: &mut [Breakpoint], ) -> Result<(), anyhow::Error> { // TODO: handle capabilities correctly again, by filtering breakpoints when emitting // if breakpoint.condition.is_some() // && !debugger // .caps // .as_ref() // .unwrap() // .supports_conditional_breakpoints // .unwrap_or_default() // { // bail!( // "Can't edit breakpoint: debugger does not support conditional breakpoints" // ) // } // if breakpoint.log_message.is_some() // && !debugger // .caps // .as_ref() // .unwrap() // .supports_log_points // .unwrap_or_default() // { // bail!("Can't edit breakpoint: debugger does not support logpoints") // } let source_breakpoints = breakpoints .iter() .map(|breakpoint| helix_dap::SourceBreakpoint { line: breakpoint.line + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init) ..Default::default() }) .collect::<Vec<_>>(); let request = debugger.set_breakpoints(path, source_breakpoints); match block_on(request) { Ok(Some(dap_breakpoints)) => { for (breakpoint, dap_breakpoint) in breakpoints.iter_mut().zip(dap_breakpoints) { breakpoint.id = dap_breakpoint.id; breakpoint.verified = dap_breakpoint.verified; breakpoint.message = dap_breakpoint.message; // TODO: handle breakpoint.message // TODO: verify source matches breakpoint.line = dap_breakpoint.line.unwrap_or(0).saturating_sub(1); // convert to 0-indexing // TODO: no unwrap breakpoint.column = dap_breakpoint.column; // TODO: verify end_linef/col instruction reference, offset } } Err(e) => anyhow::bail!("Failed to set breakpoints: {}", e), _ => {} }; Ok(()) } impl Editor { pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) -> bool { use dap::requests::RunInTerminal; use helix_dap::{events, Event}; let debugger = match self.debugger.as_mut() { Some(debugger) => debugger, None => return false, }; match payload { Payload::Event(ev) => match *ev { Event::Stopped(events::Stopped { thread_id, description, text, reason, all_threads_stopped, .. }) => { let all_threads_stopped = all_threads_stopped.unwrap_or_default(); if all_threads_stopped { if let Ok(response) = debugger.request::<dap::requests::Threads>(()).await { for thread in response.threads { fetch_stack_trace(debugger, thread.id).await; } select_thread_id(self, thread_id.unwrap_or_default(), false).await; } } else if let Some(thread_id) = thread_id { debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here // whichever thread stops is made "current" (if no previously selected thread). select_thread_id(self, thread_id, false).await; } let scope = match thread_id { Some(id) => format!("Thread {}", id), None => "Target".to_owned(), }; let mut status = format!("{} stopped because of {}", scope, reason); if let Some(desc) = description { write!(status, " {}", desc).unwrap(); } if let Some(text) = text { write!(status, " {}", text).unwrap(); } if all_threads_stopped { status.push_str(" (all threads stopped)"); } self.set_status(status); } Event::Continued(events::Continued { thread_id, .. }) => { debugger .thread_states .insert(thread_id, "running".to_owned()); if debugger.thread_id == Some(thread_id) { debugger.resume_application(); } } Event::Thread(_) => { // TODO: update thread_states, make threads request } Event::Breakpoint(events::Breakpoint { reason, breakpoint }) => { match &reason[..] { "new" => { if let Some(source) = breakpoint.source { self.breakpoints .entry(source.path.unwrap()) // TODO: no unwraps .or_default() .push(Breakpoint { id: breakpoint.id, verified: breakpoint.verified, message: breakpoint.message, line: breakpoint.line.unwrap().saturating_sub(1), // TODO: no unwrap column: breakpoint.column, ..Default::default() }); } } "changed" => { for breakpoints in self.breakpoints.values_mut() { if let Some(i) = breakpoints.iter().position(|b| b.id == breakpoint.id) { breakpoints[i].verified = breakpoint.verified; breakpoints[i].message = breakpoint.message.clone(); breakpoints[i].line = breakpoint.line.unwrap().saturating_sub(1); // TODO: no unwrap breakpoints[i].column = breakpoint.column; } } } "removed" => { for breakpoints in self.breakpoints.values_mut() { if let Some(i) = breakpoints.iter().position(|b| b.id == breakpoint.id) { breakpoints.remove(i); } } } reason => { warn!("Unknown breakpoint event: {}", reason); } } } Event::Output(events::Output { category, output, .. }) => { let prefix = match category { Some(category) => { if &category == "telemetry" { return false; } format!("Debug ({}):", category) } None => "Debug:".to_owned(), }; log::info!("{}", output); self.set_status(format!("{} {}", prefix, output)); } Event::Initialized(_) => { // send existing breakpoints for (path, breakpoints) in &mut self.breakpoints { // TODO: call futures in parallel, await all let _ = breakpoints_changed(debugger, path.clone(), breakpoints); } // TODO: fetch breakpoints (in case we're attaching) if debugger.configuration_done().await.is_ok() { self.set_status("Debugged application started"); }; // TODO: do we need to handle error? } Event::Terminated(terminated) => { let restart_args = if let Some(terminated) = terminated { terminated.restart } else { None }; let disconnect_args = Some(DisconnectArguments { restart: Some(restart_args.is_some()), terminate_debuggee: None, suspend_debuggee: None, }); if let Err(err) = debugger.disconnect(disconnect_args).await { self.set_error(format!( "Cannot disconnect debugger upon terminated event receival {:?}", err )); return false; } match restart_args { Some(restart_args) => { log::info!("Attempting to restart debug session."); let connection_type = match debugger.connection_type() { Some(connection_type) => connection_type, None => { self.set_error("No starting request found, to be used in restarting the debugging session."); return false; } }; let relaunch_resp = if let ConnectionType::Launch = connection_type { debugger.launch(restart_args).await } else { debugger.attach(restart_args).await }; if let Err(err) = relaunch_resp { self.set_error(format!( "Failed to restart debugging session: {:?}", err )); } } None => { self.set_status( "Terminated debugging session and disconnected debugger.", ); } } } Event::Exited(resp) => { let exit_code = resp.exit_code; if exit_code != 0 { self.set_error(format!( "Debuggee failed to exit successfully (exit code: {exit_code})." )); } } ev => { log::warn!("Unhandled event {:?}", ev); return false; // return early to skip render } }, Payload::Response(_) => unreachable!(), Payload::Request(request) => match request.command.as_str() { RunInTerminal::COMMAND => { let arguments: dap::requests::RunInTerminalArguments = serde_json::from_value(request.arguments.unwrap_or_default()).unwrap(); // TODO: no unwrap let config = match self.config().terminal.clone() { Some(config) => config, None => { self.set_error("No external terminal defined"); return true; } }; // Re-borrowing debugger to avoid issues when loading config let debugger = match self.debugger.as_mut() { Some(debugger) => debugger, None => return false, }; let process = match std::process::Command::new(config.command) .args(config.args) .arg(arguments.args.join(" ")) .spawn() { Ok(process) => process, Err(err) => { // TODO replace the pretty print {:?} with a regular format {} // when the MSRV is raised to 1.60.0 self.set_error(format!("Error starting external terminal: {:?}", err)); return true; } }; let _ = debugger .reply( request.seq, dap::requests::RunInTerminal::COMMAND, serde_json::to_value(dap::requests::RunInTerminalResponse { process_id: Some(process.id()), shell_process_id: None, }) .map_err(|e| e.into()), ) .await; } _ => log::error!("DAP reverse request not implemented: {:?}", request), }, } true } }