dap: Get rid of excessive cloning
This commit is contained in:
parent
fd9b826f2c
commit
9baddc825d
2 changed files with 23 additions and 30 deletions
|
@ -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<String>,
|
||||
port_arg: Option<String>,
|
||||
transport: &str,
|
||||
command: &str,
|
||||
args: Vec<&str>,
|
||||
port_arg: Option<&str>,
|
||||
id: usize,
|
||||
) -> Result<(Self, UnboundedReceiver<Payload>)> {
|
||||
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)))
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue