Create new debugger config format

pull/574/head
Dmitry Sharshakov 3 years ago
parent 34c6094604
commit c463142e5e
No known key found for this signature in database
GPG Key ID: 471FD32E15FD8473

@ -57,10 +57,7 @@ pub struct LanguageConfiguration {
#[serde(skip)] #[serde(skip)]
pub(crate) indent_query: OnceCell<Option<IndentQuery>>, pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub debug_adapter: Option<DebugAdapterConfig>, pub debugger: Option<DebugAdapterConfig>,
// TODO: names for those
#[serde(skip_serializing_if = "Option::is_none")]
pub debug_configs: Option<Vec<HashMap<String, serde_json::Value>>>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

@ -225,7 +225,9 @@ impl Client {
} }
pub fn capabilities(&self) -> &DebuggerCapabilities { pub fn capabilities(&self) -> &DebuggerCapabilities {
self.caps.as_ref().expect("debugger not yet initialized!") self.caps
.as_ref()
.expect("debugger not yet initialized!")
} }
pub async fn initialize(&mut self, adapter_id: String) -> Result<()> { pub async fn initialize(&mut self, adapter_id: String) -> Result<()> {

@ -1,6 +1,14 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use std::path::PathBuf; use std::{collections::HashMap, path::PathBuf};
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct DebugTemplate {
pub name: String,
pub request: String,
pub args: HashMap<String, Value>
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
@ -10,6 +18,7 @@ pub struct DebugAdapterConfig {
pub command: String, pub command: String,
pub args: Vec<String>, pub args: Vec<String>,
pub port_arg: Option<String>, pub port_arg: Option<String>,
pub templates: Vec<DebugTemplate>,
} }
pub trait Request { pub trait Request {

@ -4392,7 +4392,6 @@ fn dap_start(cx: &mut Context) {
let (_, doc) = current!(cx.editor); let (_, doc) = current!(cx.editor);
// TODO config picker
let path = match doc.path() { let path = match doc.path() {
Some(path) => path.to_path_buf(), Some(path) => path.to_path_buf(),
None => { None => {
@ -4406,7 +4405,7 @@ fn dap_start(cx: &mut Context) {
.editor .editor
.syn_loader .syn_loader
.language_config_for_file_name(&path) .language_config_for_file_name(&path)
.and_then(|x| x.debug_adapter.clone()); .and_then(|x| x.debugger.clone());
let config = match config { let config = match config {
Some(c) => c, Some(c) => c,
None => { None => {
@ -4416,30 +4415,26 @@ fn dap_start(cx: &mut Context) {
return; return;
} }
}; };
let started = Client::process(config.clone(), 0); let started = Client::process(config.clone(), 0);
let (mut debugger, events) = block_on(started).unwrap(); let (mut debugger, events) = block_on(started).unwrap();
let request = debugger.initialize(config.name); let request = debugger.initialize(config.name.clone());
let _ = block_on(request).unwrap(); let _ = block_on(request).unwrap();
let sessions = doc.language_config().and_then(|x| x.debug_configs.clone()); // TODO: picker
let start_config = config.templates.get(0).unwrap();
let sessions = match sessions { let args = to_value(start_config.args.clone()).unwrap();
Some(c) => c,
None => { match &start_config.request[..] {
cx.editor.set_error( "launch" => block_on(debugger.launch(args)).unwrap(),
"Can't start debug: no debug sessions available for language".to_string(), "attach" => block_on(debugger.attach(args)).unwrap(),
); _ => {
cx.editor.set_error("Unsupported request".to_string());
return; return;
} }
}; };
// TODO: picker
let args = sessions.get(0);
let request = debugger.launch(to_value(args).unwrap());
let _ = block_on(request).unwrap();
// TODO: either await "initialized" or buffer commands until event is received // TODO: either await "initialized" or buffer commands until event is received
cx.editor.debugger = Some(debugger); cx.editor.debugger = Some(debugger);
let stream = UnboundedReceiverStream::new(events); let stream = UnboundedReceiverStream::new(events);

@ -19,11 +19,6 @@ config = """
language-server = { command = "rust-analyzer" } language-server = { command = "rust-analyzer" }
indent = { tab-width = 4, unit = " " } indent = { tab-width = 4, unit = " " }
debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" }
[[language.debug-configs]]
console = "internalConsole"
program = "target/debug/rustdebug"
[[language]] [[language]]
name = "toml" name = "toml"
@ -74,11 +69,6 @@ comment-token = "//"
language-server = { command = "clangd" } language-server = { command = "clangd" }
indent = { tab-width = 2, unit = " " } indent = { tab-width = 2, unit = " " }
debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" }
[[language.debug-configs]]
console = "internalConsole"
program = "main"
[[language]] [[language]]
name = "cpp" name = "cpp"
@ -90,11 +80,6 @@ comment-token = "//"
language-server = { command = "clangd" } language-server = { command = "clangd" }
indent = { tab-width = 2, unit = " " } indent = { tab-width = 2, unit = " " }
debug-adapter = { name = "lldb", transport = "tcp", command = "lldb-vscode", args = [], port-arg = "-p {}" }
[[language.debug-configs]]
console = "internalConsole"
program = "main"
[[language]] [[language]]
name = "go" name = "go"
@ -108,19 +93,28 @@ comment-token = "//"
language-server = { command = "gopls" } language-server = { command = "gopls" }
# TODO: gopls needs utf-8 offsets? # TODO: gopls needs utf-8 offsets?
indent = { tab-width = 4, unit = "\t" } indent = { tab-width = 4, unit = "\t" }
debug-adapter = { name = "go", transport = "tcp", command = "dlv", args = ["dap"], port-arg = "-l 127.0.0.1:{}" }
[[language.debug-configs]] [language.debugger]
mode = "debug" name = "go"
program = "main.go" transport = "tcp"
command = "dlv"
[[language.debug-configs]] args = ["dap"]
mode = "exec" port-arg = "-l 127.0.0.1:{}"
program = "main"
[[language.debugger.templates]]
[[language.debug-configs]] name = "source"
mode = "test" request = "launch"
program = "." args = { mode = "debug", program = "main.go" }
[[language.debugger.templates]]
name = "binary"
request = "launch"
args = { mode = "exec", program = "main" }
[[language.debugger.templates]]
name = "test"
request = "launch"
args = { mode = "test", program = "." }
[[language]] [[language]]
name = "javascript" name = "javascript"

Loading…
Cancel
Save