on master help sign in
Create new debugger config format
commitc463142e5e43fa83fc5f8f714af72425d18ba216 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateTue 24 Aug 2021, 11:56 (5 years ago) parent34c6094
5 files changed+47−50
helix-core/src/syntax.rs+1−4 helix-dap/src/client.rs+3−1 helix-dap/src/types.rs+10−1 helix-term/src/commands.rs+12−17 languages.toml+21−27
helix-core/src/syntax.rs+1−4
@@ -57,10 +57,7 @@ pub struct LanguageConfiguration {
5757 #[serde(skip)]
5858 pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
5959 #[serde(skip_serializing_if = "Option::is_none")]
60− pub debug_adapter: Option<DebugAdapterConfig>,
61− // TODO: names for those
62− #[serde(skip_serializing_if = "Option::is_none")]
63− pub debug_configs: Option<Vec<HashMap<String, serde_json::Value>>>,
60+ pub debugger: Option<DebugAdapterConfig>,
6461}
6562
6663#[derive(Debug, Serialize, Deserialize)]
helix-dap/src/client.rs+3−1
@@ -225,7 +225,9 @@ impl Client {
225225 }
226226
227227 pub fn capabilities(&self) -> &DebuggerCapabilities {
228− self.caps.as_ref().expect("debugger not yet initialized!")
228+ self.caps
229+ .as_ref()
230+ .expect("debugger not yet initialized!")
229231 }
230232
231233 pub async fn initialize(&mut self, adapter_id: String) -> Result<()> {
helix-dap/src/types.rs+10−1
@@ -1,6 +1,14 @@
11use serde::{Deserialize, Serialize};
22use serde_json::Value;
3−use std::path::PathBuf;
3+use std::{collections::HashMap, path::PathBuf};
4+
5+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
6+#[serde(rename_all = "kebab-case")]
7+pub struct DebugTemplate {
8+ pub name: String,
9+ pub request: String,
10+ pub args: HashMap<String, Value>
11+}
412
513#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
614#[serde(rename_all = "kebab-case")]
@@ -10,6 +18,7 @@ pub struct DebugAdapterConfig {
1018 pub command: String,
1119 pub args: Vec<String>,
1220 pub port_arg: Option<String>,
21+ pub templates: Vec<DebugTemplate>,
1322}
1423
1524pub trait Request {
helix-term/src/commands.rs+12−17
@@ -4392,7 +4392,6 @@ fn dap_start(cx: &mut Context) {
43924392
43934393 let (_, doc) = current!(cx.editor);
43944394
4395− // TODO config picker
43964395 let path = match doc.path() {
43974396 Some(path) => path.to_path_buf(),
43984397 None => {
@@ -4406,7 +4405,7 @@ fn dap_start(cx: &mut Context) {
44064405 .editor
44074406 .syn_loader
44084407 .language_config_for_file_name(&path)
4409− .and_then(|x| x.debug_adapter.clone());
4408+ .and_then(|x| x.debugger.clone());
44104409 let config = match config {
44114410 Some(c) => c,
44124411 None => {
@@ -4416,30 +4415,26 @@ fn dap_start(cx: &mut Context) {
44164415 return;
44174416 }
44184417 };
4418+
44194419 let started = Client::process(config.clone(), 0);
44204420 let (mut debugger, events) = block_on(started).unwrap();
44214421
4422− let request = debugger.initialize(config.name);
4422+ let request = debugger.initialize(config.name.clone());
44234423 let _ = block_on(request).unwrap();
44244424
4425− let sessions = doc.language_config().and_then(|x| x.debug_configs.clone());
4426−
4427− let sessions = match sessions {
4428− Some(c) => c,
4429− None => {
4430− cx.editor.set_error(
4431− "Can't start debug: no debug sessions available for language".to_string(),
4432− );
4425+ // TODO: picker
4426+ let start_config = config.templates.get(0).unwrap();
4427+ let args = to_value(start_config.args.clone()).unwrap();
4428+
4429+ match &start_config.request[..] {
4430+ "launch" => block_on(debugger.launch(args)).unwrap(),
4431+ "attach" => block_on(debugger.attach(args)).unwrap(),
4432+ _ => {
4433+ cx.editor.set_error("Unsupported request".to_string());
44334434 return;
44344435 }
44354436 };
44364437
4437− // TODO: picker
4438− let args = sessions.get(0);
4439−
4440− let request = debugger.launch(to_value(args).unwrap());
4441− let _ = block_on(request).unwrap();
4442−
44434438 // TODO: either await "initialized" or buffer commands until event is received
44444439 cx.editor.debugger = Some(debugger);
44454440 let stream = UnboundedReceiverStream::new(events);
languages.toml+21−27
@@ -19,11 +19,6 @@ config = """
1919
2020language-server = { command = "rust-analyzer" }
2121indent = { tab-width = 4, unit = " " }
22−debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" }
23−
24−[[language.debug-configs]]
25−console = "internalConsole"
26−program = "target/debug/rustdebug"
2722
2823[[language]]
2924name = "toml"
@@ -74,11 +69,6 @@ comment-token = "//"
7469
7570language-server = { command = "clangd" }
7671indent = { tab-width = 2, unit = " " }
77−debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" }
78−
79−[[language.debug-configs]]
80−console = "internalConsole"
81−program = "main"
8272
8373[[language]]
8474name = "cpp"
@@ -90,11 +80,6 @@ comment-token = "//"
9080
9181language-server = { command = "clangd" }
9282indent = { tab-width = 2, unit = " " }
93−debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" }
94−
95−[[language.debug-configs]]
96−console = "internalConsole"
97−program = "main"
9883
9984[[language]]
10085name = "go"
@@ -108,19 +93,28 @@ comment-token = "//"
10893language-server = { command = "gopls" }
10994# TODO: gopls needs utf-8 offsets?
11095indent = { tab-width = 4, unit = "\t" }
111−debug-adapter = { name = "go", transport = "tcp", command = "dlv", args = ["dap"], port-arg = "-l 127.0.0.1:{}" }
11296
113−[[language.debug-configs]]
114−mode = "debug"
115−program = "main.go"
116−
117−[[language.debug-configs]]
118−mode = "exec"
119−program = "main"
120−
121−[[language.debug-configs]]
122−mode = "test"
123−program = "."
97+[language.debugger]
98+name = "go"
99+transport = "tcp"
100+command = "dlv"
101+args = ["dap"]
102+port-arg = "-l 127.0.0.1:{}"
103+
104+[[language.debugger.templates]]
105+name = "source"
106+request = "launch"
107+args = { mode = "debug", program = "main.go" }
108+
109+[[language.debugger.templates]]
110+name = "binary"
111+request = "launch"
112+args = { mode = "exec", program = "main" }
113+
114+[[language.debugger.templates]]
115+name = "test"
116+request = "launch"
117+args = { mode = "test", program = "." }
124118
125119[[language]]
126120name = "javascript"