From 9baddc825d57e09e635b653b2c171e104f85c552 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sun, 7 Nov 2021 18:37:42 +0900 Subject: dap: Get rid of excessive cloning --- helix-dap/src/client.rs | 18 ++++++------------ helix-term/src/commands/dap.rs | 35 +++++++++++++++++------------------ 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index 28cc7c90..5e6d8d53 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -42,25 +42,19 @@ pub struct Client { impl Client { // Spawn a process and communicate with it by either TCP or stdio pub async fn process( - transport: String, - command: String, - args: Vec, - port_arg: Option, + transport: &str, + command: &str, + args: Vec<&str>, + port_arg: Option<&str>, id: usize, ) -> Result<(Self, UnboundedReceiver)> { if command.is_empty() { return Result::Err(Error::Other(anyhow!("Command not provided"))); } if transport == "tcp" && port_arg.is_some() { - Self::tcp_process( - &command, - args.iter().map(|s| s.as_str()).collect(), - &port_arg.unwrap(), - id, - ) - .await + Self::tcp_process(command, args, port_arg.unwrap(), id).await } else if transport == "stdio" { - Self::stdio(&command, args.iter().map(|s| s.as_str()).collect(), id) + Self::stdio(command, args, id) } else { Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport))) } diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 7d438a30..d46e38eb 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -170,11 +170,11 @@ pub fn dap_start_impl( } }; - let config = editor - .syn_loader - .language_config_for_file_name(&path) - .and_then(|x| x.debugger.clone()); - let config = match config { + let language_config = editor.syn_loader.language_config_for_file_name(&path); + let config = match language_config + .as_deref() + .and_then(|config| config.debugger.as_ref()) + { Some(c) => c, None => { editor.set_error( @@ -187,10 +187,10 @@ pub fn dap_start_impl( let result = match socket { Some(socket) => block_on(Client::tcp(socket, 0)), None => block_on(Client::process( - config.transport.clone(), - config.command.clone(), - config.args.clone(), - config.port_arg.clone(), + &config.transport, + &config.command, + config.args.iter().map(|arg| arg.as_str()).collect(), + config.port_arg.as_deref(), 0, )), }; @@ -209,7 +209,7 @@ pub fn dap_start_impl( return; } - debugger.quirks = config.quirks; + debugger.quirks = config.quirks.clone(); let start_config = match name { Some(name) => config.templates.iter().find(|t| t.name == name), @@ -296,7 +296,7 @@ pub fn dap_launch(cx: &mut Context) { let (_, doc) = current!(cx.editor); let path = match doc.path() { - Some(path) => path.to_path_buf(), + Some(path) => path, None => { cx.editor .set_error("Can't start debug: document has no path".to_string()); @@ -304,12 +304,11 @@ pub fn dap_launch(cx: &mut Context) { } }; - let config = cx - .editor - .syn_loader - .language_config_for_file_name(&path) - .and_then(|x| x.debugger.clone()); - let config = match config { + let language_config = cx.editor.syn_loader.language_config_for_file_name(path); + let config = match language_config + .as_deref() + .and_then(|config| config.debugger.as_ref()) + { Some(c) => c, None => { cx.editor.set_error( @@ -321,7 +320,7 @@ pub fn dap_launch(cx: &mut Context) { cx.push_layer(Box::new(Picker::new( true, - config.templates, + config.templates.clone(), |template| template.name.as_str().into(), |cx, template, _action| { let completions = template.completion.clone(); -- cgit v1.2.3-70-g09d2