on master help sign in
dap: Split out launch from init
a54b09eBlaž Hrastnik
helix-dap/src/client.rs+1−1
@@ -265,7 +265,7 @@ impl Client {
265
265
266 pub async fn set_breakpoints(
266 pub async fn set_breakpoints(
267 &mut self,
267 &mut self,
268− file: String,
268+ file: PathBuf,
269 breakpoints: Vec<SourceBreakpoint>,
269 breakpoints: Vec<SourceBreakpoint>,
270 ) -> Result<Option<Vec<Breakpoint>>> {
270 ) -> Result<Option<Vec<Breakpoint>>> {
271 let args = requests::SetBreakpointsArguments {
271 let args = requests::SetBreakpointsArguments {
helix-dap/src/types.rs+8−7
@@ -1,5 +1,6 @@
1use serde::{Deserialize, Serialize};
1use serde::{Deserialize, Serialize};
2use serde_json::Value;
2use serde_json::Value;
3+use std::path::PathBuf;
3
4
4pub trait Request {
5pub trait Request {
5 type Arguments: serde::de::DeserializeOwned + serde::Serialize;
6 type Arguments: serde::de::DeserializeOwned + serde::Serialize;
@@ -91,7 +92,7 @@ pub struct Checksum {
91#[serde(rename_all = "camelCase")]
92#[serde(rename_all = "camelCase")]
92pub struct Source {
93pub struct Source {
93 pub name: Option<String>,
94 pub name: Option<String>,
94− pub path: Option<String>,
95+ pub path: Option<PathBuf>,
95 pub source_reference: Option<usize>,
96 pub source_reference: Option<usize>,
96 pub presentation_hint: Option<String>,
97 pub presentation_hint: Option<String>,
97 pub origin: Option<String>,
98 pub origin: Option<String>,
@@ -207,7 +208,7 @@ pub struct Variable {
207
208
208pub mod requests {
209pub mod requests {
209 use super::*;
210 use super::*;
210− #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
211+ #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
211 #[serde(rename_all = "camelCase")]
212 #[serde(rename_all = "camelCase")]
212 pub struct InitializeArguments {
213 pub struct InitializeArguments {
213 #[serde(rename = "clientID")]
214 #[serde(rename = "clientID")]
@@ -274,7 +275,7 @@ pub mod requests {
274 const COMMAND: &'static str = "configurationDone";
275 const COMMAND: &'static str = "configurationDone";
275 }
276 }
276
277
277− #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
278+ #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
278 #[serde(rename_all = "camelCase")]
279 #[serde(rename_all = "camelCase")]
279 pub struct SetBreakpointsArguments {
280 pub struct SetBreakpointsArguments {
280 pub source: Source,
281 pub source: Source,
@@ -283,7 +284,7 @@ pub mod requests {
283 pub source_modified: Option<bool>,
284 pub source_modified: Option<bool>,
284 }
285 }
285
286
286− #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
287+ #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
287 #[serde(rename_all = "camelCase")]
288 #[serde(rename_all = "camelCase")]
288 pub struct SetBreakpointsResponse {
289 pub struct SetBreakpointsResponse {
289 pub breakpoints: Option<Vec<Breakpoint>>,
290 pub breakpoints: Option<Vec<Breakpoint>>,
@@ -298,7 +299,7 @@ pub mod requests {
298 const COMMAND: &'static str = "setBreakpoints";
299 const COMMAND: &'static str = "setBreakpoints";
299 }
300 }
300
301
301− #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
302+ #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
302 #[serde(rename_all = "camelCase")]
303 #[serde(rename_all = "camelCase")]
303 pub struct ContinueArguments {
304 pub struct ContinueArguments {
304 pub thread_id: usize,
305 pub thread_id: usize,
@@ -319,7 +320,7 @@ pub mod requests {
319 const COMMAND: &'static str = "continue";
320 const COMMAND: &'static str = "continue";
320 }
321 }
321
322
322− #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
323+ #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
323 #[serde(rename_all = "camelCase")]
324 #[serde(rename_all = "camelCase")]
324 pub struct StackTraceArguments {
325 pub struct StackTraceArguments {
325 pub thread_id: usize,
326 pub thread_id: usize,
@@ -380,7 +381,7 @@ pub mod requests {
380 const COMMAND: &'static str = "scopes";
381 const COMMAND: &'static str = "scopes";
381 }
382 }
382
383
383− #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
384+ #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
384 #[serde(rename_all = "camelCase")]
385 #[serde(rename_all = "camelCase")]
385 pub struct VariablesArguments {
386 pub struct VariablesArguments {
386 pub variables_reference: usize,
387 pub variables_reference: usize,
helix-term/src/commands.rs+32−18
@@ -33,7 +33,7 @@ use crate::{
33use crate::job::{self, Job, Jobs};
33use crate::job::{self, Job, Jobs};
34use futures_util::FutureExt;
34use futures_util::FutureExt;
35use std::num::NonZeroUsize;
35use std::num::NonZeroUsize;
36−use std::{fmt, future::Future};
36+use std::{collections::HashMap, fmt, future::Future};
37
37
38use std::{
38use std::{
39 borrow::Cow,
39 borrow::Cow,
@@ -302,7 +302,8 @@ impl Command {
302 surround_delete, "Surround delete",
302 surround_delete, "Surround delete",
303 select_textobject_around, "Select around object",
303 select_textobject_around, "Select around object",
304 select_textobject_inner, "Select inside object",
304 select_textobject_inner, "Select inside object",
305− toggle_breakpoint, "Toggle breakpoint",
305+ dap_toggle_breakpoint, "Toggle breakpoint",
306+ dap_launch, "Launch debugger",
306 suspend, "Suspend"
307 suspend, "Suspend"
307 );
308 );
308}
309}
@@ -1337,7 +1338,6 @@ fn append_mode(cx: &mut Context) {
1337
1338
1338mod cmd {
1339mod cmd {
1339 use super::*;
1340 use super::*;
1340− use std::collections::HashMap;
1341
1341
1342 use helix_view::editor::Action;
1342 use helix_view::editor::Action;
1343 use ui::completers::{self, Completer};
1343 use ui::completers::{self, Completer};
@@ -1908,27 +1908,20 @@ mod cmd {
1908 ) -> anyhow::Result<()> {
1908 ) -> anyhow::Result<()> {
1909 use helix_dap::Client;
1909 use helix_dap::Client;
1910 use helix_lsp::block_on;
1910 use helix_lsp::block_on;
1911− use serde_json::to_value;
1912 let (_, doc) = current!(cx.editor);
1911 let (_, doc) = current!(cx.editor);
1913
1912
1914 // look up config for filetype
1913 // look up config for filetype
1915 // if multiple available, open picker
1914 // if multiple available, open picker
1916
1915
1917− let client = Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0);
1916+ let debugger = Client::tcp_process("dlv", vec!["dap"], "-l 127.0.0.1:{}", 0);
1918− let mut client = block_on(client)?;
1917+ let mut debugger = block_on(debugger)?;
1919
1918
1920− let request = client.initialize("go".to_owned());
1919+ let request = debugger.initialize("go".to_owned());
1921 let _ = block_on(request)?;
1920 let _ = block_on(request)?;
1922
1921
1923− let mut args = HashMap::new();
1922+ // TODO: either await "initialized" or buffer commands until event is received
1924− args.insert("mode", "debug");
1925− args.insert("program", "main.go");
1926−
1927− let request = client.launch(to_value(args)?);
1928− let _ = block_on(request)?;
1929
1923
1930− log::error!("4");
1931− cx.editor.debugger = Some(client);
1924+ cx.editor.debugger = Some(debugger);
1932 Ok(())
1925 Ok(())
1933 }
1926 }
1934
1927
@@ -4281,13 +4274,15 @@ fn suspend(_cx: &mut Context) {
4281}
4274}
4282
4275
4283// DAP
4276// DAP
4284−fn toggle_breakpoint(cx: &mut Context) {
4277+fn dap_toggle_breakpoint(cx: &mut Context) {
4278+ use helix_lsp::block_on;
4279+
4285 let (view, doc) = current!(cx.editor);
4280 let (view, doc) = current!(cx.editor);
4286 let text = doc.text().slice(..);
4281 let text = doc.text().slice(..);
4287 let pos = doc.selection(view.id).primary().cursor(text);
4282 let pos = doc.selection(view.id).primary().cursor(text);
4288
4283
4289 let breakpoint = helix_dap::SourceBreakpoint {
4284 let breakpoint = helix_dap::SourceBreakpoint {
4290− line: text.char_to_line(pos),
4285+ line: text.char_to_line(pos) + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
4291 ..Default::default()
4286 ..Default::default()
4292 };
4287 };
4293
4288
@@ -4304,11 +4299,30 @@ fn toggle_breakpoint(cx: &mut Context) {
4304 // we shouldn't really allow editing while debug is running though
4299 // we shouldn't really allow editing while debug is running though
4305
4300
4306 if let Some(debugger) = &mut cx.editor.debugger {
4301 if let Some(debugger) = &mut cx.editor.debugger {
4307− let breakpoints = debugger.breakpoints.entry(path).or_default();
4302+ let breakpoints = debugger.breakpoints.entry(path.clone()).or_default();
4308 if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
4303 if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
4309 breakpoints.remove(pos);
4304 breakpoints.remove(pos);
4310 } else {
4305 } else {
4311 breakpoints.push(breakpoint);
4306 breakpoints.push(breakpoint);
4312 }
4307 }
4308+
4309+ let breakpoints = breakpoints.clone();
4310+
4311+ let request = debugger.set_breakpoints(path, breakpoints);
4312+ let _ = block_on(request).unwrap();
4313+ }
4314+}
4315+
4316+fn dap_launch(cx: &mut Context) {
4317+ use helix_lsp::block_on;
4318+ use serde_json::to_value;
4319+
4320+ if let Some(debugger) = &mut cx.editor.debugger {
4321+ let mut args = HashMap::new();
4322+ args.insert("mode", "debug");
4323+ args.insert("program", "main.go");
4324+
4325+ let request = debugger.launch(to_value(args).unwrap());
4326+ let _ = block_on(request).unwrap();
4313 }
4327 }
4314}
4328}
helix-term/src/keymap.rs+2−1
@@ -486,7 +486,8 @@ impl Default for Keymaps {
486 "a" => code_action,
486 "a" => code_action,
487 "'" => last_picker,
487 "'" => last_picker,
488 "d" => { "Debug"
488 "d" => { "Debug"
489− "b" => toggle_breakpoint,
489+ "b" => dap_toggle_breakpoint,
490+ "r" => dap_launch,
490 },
491 },
491 "w" => { "Window"
492 "w" => { "Window"
492 "C-w" | "w" => rotate_view,
493 "C-w" | "w" => rotate_view,