Create new debugger config format
This commit is contained in:
parent
34c6094604
commit
c463142e5e
5 changed files with 44 additions and 47 deletions
|
@ -57,10 +57,7 @@ pub struct LanguageConfiguration {
|
|||
#[serde(skip)]
|
||||
pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub debug_adapter: Option<DebugAdapterConfig>,
|
||||
// TODO: names for those
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub debug_configs: Option<Vec<HashMap<String, serde_json::Value>>>,
|
||||
pub debugger: Option<DebugAdapterConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
|
@ -225,7 +225,9 @@ impl Client {
|
|||
}
|
||||
|
||||
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<()> {
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
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)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
|
@ -10,6 +18,7 @@ pub struct DebugAdapterConfig {
|
|||
pub command: String,
|
||||
pub args: Vec<String>,
|
||||
pub port_arg: Option<String>,
|
||||
pub templates: Vec<DebugTemplate>,
|
||||
}
|
||||
|
||||
pub trait Request {
|
||||
|
|
|
@ -4392,7 +4392,6 @@ fn dap_start(cx: &mut Context) {
|
|||
|
||||
let (_, doc) = current!(cx.editor);
|
||||
|
||||
// TODO config picker
|
||||
let path = match doc.path() {
|
||||
Some(path) => path.to_path_buf(),
|
||||
None => {
|
||||
|
@ -4406,7 +4405,7 @@ fn dap_start(cx: &mut Context) {
|
|||
.editor
|
||||
.syn_loader
|
||||
.language_config_for_file_name(&path)
|
||||
.and_then(|x| x.debug_adapter.clone());
|
||||
.and_then(|x| x.debugger.clone());
|
||||
let config = match config {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
|
@ -4416,30 +4415,26 @@ fn dap_start(cx: &mut Context) {
|
|||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let started = Client::process(config.clone(), 0);
|
||||
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 sessions = doc.language_config().and_then(|x| x.debug_configs.clone());
|
||||
// TODO: picker
|
||||
let start_config = config.templates.get(0).unwrap();
|
||||
let args = to_value(start_config.args.clone()).unwrap();
|
||||
|
||||
let sessions = match sessions {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
cx.editor.set_error(
|
||||
"Can't start debug: no debug sessions available for language".to_string(),
|
||||
);
|
||||
match &start_config.request[..] {
|
||||
"launch" => block_on(debugger.launch(args)).unwrap(),
|
||||
"attach" => block_on(debugger.attach(args)).unwrap(),
|
||||
_ => {
|
||||
cx.editor.set_error("Unsupported request".to_string());
|
||||
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
|
||||
cx.editor.debugger = Some(debugger);
|
||||
let stream = UnboundedReceiverStream::new(events);
|
||||
|
|
|
@ -19,11 +19,6 @@ config = """
|
|||
|
||||
language-server = { command = "rust-analyzer" }
|
||||
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]]
|
||||
name = "toml"
|
||||
|
@ -74,11 +69,6 @@ comment-token = "//"
|
|||
|
||||
language-server = { command = "clangd" }
|
||||
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]]
|
||||
name = "cpp"
|
||||
|
@ -90,11 +80,6 @@ comment-token = "//"
|
|||
|
||||
language-server = { command = "clangd" }
|
||||
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]]
|
||||
name = "go"
|
||||
|
@ -108,19 +93,28 @@ comment-token = "//"
|
|||
language-server = { command = "gopls" }
|
||||
# TODO: gopls needs utf-8 offsets?
|
||||
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]]
|
||||
mode = "debug"
|
||||
program = "main.go"
|
||||
[language.debugger]
|
||||
name = "go"
|
||||
transport = "tcp"
|
||||
command = "dlv"
|
||||
args = ["dap"]
|
||||
port-arg = "-l 127.0.0.1:{}"
|
||||
|
||||
[[language.debug-configs]]
|
||||
mode = "exec"
|
||||
program = "main"
|
||||
[[language.debugger.templates]]
|
||||
name = "source"
|
||||
request = "launch"
|
||||
args = { mode = "debug", program = "main.go" }
|
||||
|
||||
[[language.debug-configs]]
|
||||
mode = "test"
|
||||
program = "."
|
||||
[[language.debugger.templates]]
|
||||
name = "binary"
|
||||
request = "launch"
|
||||
args = { mode = "exec", program = "main" }
|
||||
|
||||
[[language.debugger.templates]]
|
||||
name = "test"
|
||||
request = "launch"
|
||||
args = { mode = "test", program = "." }
|
||||
|
||||
[[language]]
|
||||
name = "javascript"
|
||||
|
|
Loading…
Add table
Reference in a new issue