diff options
-rw-r--r-- | helix-core/src/syntax.rs | 36 | ||||
-rw-r--r-- | helix-dap/src/client.rs | 26 | ||||
-rw-r--r-- | helix-dap/src/types.rs | 22 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 8 | ||||
-rw-r--r-- | helix-term/src/ui/editor.rs | 46 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 4 | ||||
-rw-r--r-- | languages.toml | 4 |
7 files changed, 88 insertions, 58 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index a7410203..cabfe083 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -5,7 +5,6 @@ use crate::{ Rope, RopeSlice, Tendril, }; -use helix_dap::DebugAdapterConfig; pub use helix_syntax::get_language; use arc_swap::ArcSwap; @@ -69,6 +68,41 @@ pub struct LanguageServerConfiguration { pub args: Vec<String>, } +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct AdvancedCompletion { + pub name: Option<String>, + pub completion: Option<String>, + pub default: Option<String>, +} + +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case", untagged)] +pub enum DebugConfigCompletion { + Named(String), + Advanced(AdvancedCompletion), +} + +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct DebugTemplate { + pub name: String, + pub request: String, + pub completion: Vec<DebugConfigCompletion>, + pub args: HashMap<String, String>, +} + +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct DebugAdapterConfig { + pub name: String, + pub transport: String, + pub command: String, + pub args: Vec<String>, + pub port_arg: Option<String>, + pub templates: Vec<DebugTemplate>, +} + #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct IndentationConfiguration { diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index ed4f8ed5..889ca89f 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -38,28 +38,24 @@ pub struct Client { impl Client { // Spawn a process and communicate with it by either TCP or stdio pub async fn process( - cfg: DebugAdapterConfig, + transport: String, + command: String, + args: Vec<String>, + port_arg: Option<String>, id: usize, ) -> Result<(Self, UnboundedReceiver<Payload>)> { - if cfg.transport == "tcp" && cfg.port_arg.is_some() { + if transport == "tcp" && port_arg.is_some() { Self::tcp_process( - &cfg.command, - cfg.args.iter().map(|s| s.as_str()).collect(), - &cfg.port_arg.unwrap(), + &command, + args.iter().map(|s| s.as_str()).collect(), + &port_arg.unwrap(), id, ) .await - } else if cfg.transport == "stdio" { - Self::stdio( - &cfg.command, - cfg.args.iter().map(|s| s.as_str()).collect(), - id, - ) + } else if transport == "stdio" { + Self::stdio(&command, args.iter().map(|s| s.as_str()).collect(), id) } else { - Result::Err(Error::Other(anyhow!( - "Incorrect transport {}", - cfg.transport - ))) + Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport))) } } diff --git a/helix-dap/src/types.rs b/helix-dap/src/types.rs index 7207f412..c1781243 100644 --- a/helix-dap/src/types.rs +++ b/helix-dap/src/types.rs @@ -1,26 +1,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; -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 completion: Vec<String>, - pub args: HashMap<String, String>, -} - -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] -#[serde(rename_all = "kebab-case")] -pub struct DebugAdapterConfig { - pub name: String, - pub transport: String, - pub command: String, - pub args: Vec<String>, - pub port_arg: Option<String>, - pub templates: Vec<DebugTemplate>, -} +use std::path::PathBuf; pub trait Request { type Arguments: serde::de::DeserializeOwned + serde::Serialize; diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index af6acb8c..eea73e47 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4528,7 +4528,13 @@ pub fn dap_start_impl( let result = match socket { Some(socket) => block_on(Client::tcp(socket, 0)), - None => block_on(Client::process(config.clone(), 0)), + None => block_on(Client::process( + config.transport.clone(), + config.command.clone(), + config.args.clone(), + config.port_arg.clone(), + 0, + )), }; let (mut debugger, events) = match result { diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 1f20619d..bb183b3a 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -11,7 +11,7 @@ use helix_core::{ coords_at_pos, graphemes::{ensure_grapheme_boundary_next, next_grapheme_boundary, prev_grapheme_boundary}, movement::Direction, - syntax::{self, HighlightEvent}, + syntax::{self, DebugConfigCompletion, HighlightEvent}, unicode::segmentation::UnicodeSegmentation, unicode::width::UnicodeWidthStr, LineEnding, Position, Range, Selection, @@ -710,28 +710,38 @@ impl EditorView { } fn debug_parameter_prompt( - completions: Vec<String>, + completions: Vec<DebugConfigCompletion>, config_name: String, mut params: Vec<String>, ) -> Prompt { let i = params.len(); - let field_type = completions.get(i).map(|x| x.as_str()); + let completion = completions.get(i).unwrap(); + let field_type = if let DebugConfigCompletion::Advanced(cfg) = completion { + cfg.completion.clone().unwrap_or_else(|| "".to_owned()) + } else { + "".to_owned() + }; + let name = match completion { + DebugConfigCompletion::Advanced(cfg) => { + cfg.name.clone().unwrap_or_else(|| field_type.to_owned()) + } + DebugConfigCompletion::Named(name) => name.clone(), + }; + let default_val = match completion { + DebugConfigCompletion::Advanced(cfg) => { + cfg.default.clone().unwrap_or_else(|| "".to_owned()) + } + _ => "".to_owned(), + }; let noop = |_input: &str| Vec::new(); - let completer = match field_type { - Some(field_type) => { - if field_type.starts_with("filename") { - super::completers::filename - } else if field_type.starts_with("directory") { - super::completers::directory - } else { - noop - } - } - None => noop, + let completer = match &field_type[..] { + "filename" => super::completers::filename, + "directory" => super::completers::directory, + _ => noop, }; Prompt::new( - format!("{}: ", field_type.unwrap_or("arg")), + format!("{}: ", name), None, completer, move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| { @@ -739,7 +749,11 @@ impl EditorView { return; } - params.push(input.to_owned()); + let mut value = input.to_owned(); + if value.is_empty() { + value = default_val.clone(); + } + params.push(value); if params.len() < completions.len() { let completions = completions.clone(); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 235974d7..9cfe12ea 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -22,7 +22,7 @@ use anyhow::Error; pub use helix_core::diagnostic::Severity; pub use helix_core::register::Registers; -use helix_core::syntax; +use helix_core::syntax::{self, DebugConfigCompletion}; use helix_core::Position; use serde::Deserialize; @@ -77,7 +77,7 @@ pub struct Editor { pub debugger: Option<helix_dap::Client>, pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>, pub debug_config_picker: Option<Vec<String>>, - pub debug_config_completions: Option<Vec<Vec<String>>>, + pub debug_config_completions: Option<Vec<Vec<DebugConfigCompletion>>>, pub variables: Option<Vec<String>>, pub variables_page: usize, diff --git a/languages.toml b/languages.toml index 20729b25..6877dd4a 100644 --- a/languages.toml +++ b/languages.toml @@ -173,8 +173,8 @@ args = { mode = "exec", program = "{0}" } [[language.debugger.templates]] name = "test" request = "launch" -completion = [ "directory: tests", "directory: cache output" ] -args = { mode = "test", program = "{0}", output = "{1}" } +completion = [ { name = "tests", completion = "directory", default = "." } ] +args = { mode = "test", program = "{0}" } [[language.debugger.templates]] name = "attach" |