on master help sign in
dap: Get rid of excessive cloning
9baddc8Blaž Hrastnik
helix-dap/src/client.rs+6−12
@@ -42,25 +42,19 @@ pub struct Client {
42impl Client {
42impl Client {
43 // Spawn a process and communicate with it by either TCP or stdio
43 // Spawn a process and communicate with it by either TCP or stdio
44 pub async fn process(
44 pub async fn process(
45− transport: String,
45+ transport: &str,
46− command: String,
46+ command: &str,
47− args: Vec<String>,
47+ args: Vec<&str>,
48− port_arg: Option<String>,
48+ port_arg: Option<&str>,
49 id: usize,
49 id: usize,
50 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
50 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
51 if command.is_empty() {
51 if command.is_empty() {
52 return Result::Err(Error::Other(anyhow!("Command not provided")));
52 return Result::Err(Error::Other(anyhow!("Command not provided")));
53 }
53 }
54 if transport == "tcp" && port_arg.is_some() {
54 if transport == "tcp" && port_arg.is_some() {
55− Self::tcp_process(
55+ Self::tcp_process(command, args, port_arg.unwrap(), id).await
56− &command,
57− args.iter().map(|s| s.as_str()).collect(),
58− &port_arg.unwrap(),
59− id,
60− )
61− .await
62 } else if transport == "stdio" {
56 } else if transport == "stdio" {
63− Self::stdio(&command, args.iter().map(|s| s.as_str()).collect(), id)
57+ Self::stdio(command, args, id)
64 } else {
58 } else {
65 Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport)))
59 Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport)))
66 }
60 }
helix-term/src/commands/dap.rs+17−18
@@ -170,11 +170,11 @@ pub fn dap_start_impl(
170 }
170 }
171 };
171 };
172
172
173− let config = editor
174− .syn_loader
175− .language_config_for_file_name(&path)
173+ let language_config = editor.syn_loader.language_config_for_file_name(&path);
176− .and_then(|x| x.debugger.clone());
177− let config = match config {
174+ let config = match language_config
175+ .as_deref()
176+ .and_then(|config| config.debugger.as_ref())
177+ {
178 Some(c) => c,
178 Some(c) => c,
179 None => {
179 None => {
180 editor.set_error(
180 editor.set_error(
@@ -187,10 +187,10 @@ pub fn dap_start_impl(
187 let result = match socket {
187 let result = match socket {
188 Some(socket) => block_on(Client::tcp(socket, 0)),
188 Some(socket) => block_on(Client::tcp(socket, 0)),
189 None => block_on(Client::process(
189 None => block_on(Client::process(
190− config.transport.clone(),
190+ &config.transport,
191− config.command.clone(),
191+ &config.command,
192− config.args.clone(),
192+ config.args.iter().map(|arg| arg.as_str()).collect(),
193− config.port_arg.clone(),
193+ config.port_arg.as_deref(),
194 0,
194 0,
195 )),
195 )),
196 };
196 };
@@ -209,7 +209,7 @@ pub fn dap_start_impl(
209 return;
209 return;
210 }
210 }
211
211
212− debugger.quirks = config.quirks;
212+ debugger.quirks = config.quirks.clone();
213
213
214 let start_config = match name {
214 let start_config = match name {
215 Some(name) => config.templates.iter().find(|t| t.name == name),
215 Some(name) => config.templates.iter().find(|t| t.name == name),
@@ -296,7 +296,7 @@ pub fn dap_launch(cx: &mut Context) {
296
296
297 let (_, doc) = current!(cx.editor);
297 let (_, doc) = current!(cx.editor);
298 let path = match doc.path() {
298 let path = match doc.path() {
299− Some(path) => path.to_path_buf(),
299+ Some(path) => path,
300 None => {
300 None => {
301 cx.editor
301 cx.editor
302 .set_error("Can't start debug: document has no path".to_string());
302 .set_error("Can't start debug: document has no path".to_string());
@@ -304,12 +304,11 @@ pub fn dap_launch(cx: &mut Context) {
304 }
304 }
305 };
305 };
306
306
307− let config = cx
308− .editor
309− .syn_loader
310− .language_config_for_file_name(&path)
307+ let language_config = cx.editor.syn_loader.language_config_for_file_name(path);
308+ let config = match language_config
309+ .as_deref()
311− .and_then(|x| x.debugger.clone());
310+ .and_then(|config| config.debugger.as_ref())
312− let config = match config {
311+ {
313 Some(c) => c,
312 Some(c) => c,
314 None => {
313 None => {
315 cx.editor.set_error(
314 cx.editor.set_error(
@@ -321,7 +320,7 @@ pub fn dap_launch(cx: &mut Context) {
321
320
322 cx.push_layer(Box::new(Picker::new(
321 cx.push_layer(Box::new(Picker::new(
323 true,
322 true,
324− config.templates,
323+ config.templates.clone(),
325 |template| template.name.as_str().into(),
324 |template| template.name.as_str().into(),
326 |cx, template, _action| {
325 |cx, template, _action| {
327 let completions = template.completion.clone();
326 let completions = template.completion.clone();