mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 19:03:30 +04:00
dap: Get rid of excessive cloning
This commit is contained in:
parent
fd9b826f2c
commit
9baddc825d
@ -42,25 +42,19 @@ pub struct Client {
|
|||||||
impl Client {
|
impl Client {
|
||||||
// Spawn a process and communicate with it by either TCP or stdio
|
// Spawn a process and communicate with it by either TCP or stdio
|
||||||
pub async fn process(
|
pub async fn process(
|
||||||
transport: String,
|
transport: &str,
|
||||||
command: String,
|
command: &str,
|
||||||
args: Vec<String>,
|
args: Vec<&str>,
|
||||||
port_arg: Option<String>,
|
port_arg: Option<&str>,
|
||||||
id: usize,
|
id: usize,
|
||||||
) -> Result<(Self, UnboundedReceiver<Payload>)> {
|
) -> Result<(Self, UnboundedReceiver<Payload>)> {
|
||||||
if command.is_empty() {
|
if command.is_empty() {
|
||||||
return Result::Err(Error::Other(anyhow!("Command not provided")));
|
return Result::Err(Error::Other(anyhow!("Command not provided")));
|
||||||
}
|
}
|
||||||
if transport == "tcp" && port_arg.is_some() {
|
if transport == "tcp" && port_arg.is_some() {
|
||||||
Self::tcp_process(
|
Self::tcp_process(command, args, port_arg.unwrap(), id).await
|
||||||
&command,
|
|
||||||
args.iter().map(|s| s.as_str()).collect(),
|
|
||||||
&port_arg.unwrap(),
|
|
||||||
id,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
} else if transport == "stdio" {
|
} else if transport == "stdio" {
|
||||||
Self::stdio(&command, args.iter().map(|s| s.as_str()).collect(), id)
|
Self::stdio(command, args, id)
|
||||||
} else {
|
} else {
|
||||||
Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport)))
|
Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport)))
|
||||||
}
|
}
|
||||||
|
@ -170,11 +170,11 @@ pub fn dap_start_impl(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let config = editor
|
let language_config = editor.syn_loader.language_config_for_file_name(&path);
|
||||||
.syn_loader
|
let config = match language_config
|
||||||
.language_config_for_file_name(&path)
|
.as_deref()
|
||||||
.and_then(|x| x.debugger.clone());
|
.and_then(|config| config.debugger.as_ref())
|
||||||
let config = match config {
|
{
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => {
|
None => {
|
||||||
editor.set_error(
|
editor.set_error(
|
||||||
@ -187,10 +187,10 @@ pub fn dap_start_impl(
|
|||||||
let result = match socket {
|
let result = match socket {
|
||||||
Some(socket) => block_on(Client::tcp(socket, 0)),
|
Some(socket) => block_on(Client::tcp(socket, 0)),
|
||||||
None => block_on(Client::process(
|
None => block_on(Client::process(
|
||||||
config.transport.clone(),
|
&config.transport,
|
||||||
config.command.clone(),
|
&config.command,
|
||||||
config.args.clone(),
|
config.args.iter().map(|arg| arg.as_str()).collect(),
|
||||||
config.port_arg.clone(),
|
config.port_arg.as_deref(),
|
||||||
0,
|
0,
|
||||||
)),
|
)),
|
||||||
};
|
};
|
||||||
@ -209,7 +209,7 @@ pub fn dap_start_impl(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugger.quirks = config.quirks;
|
debugger.quirks = config.quirks.clone();
|
||||||
|
|
||||||
let start_config = match name {
|
let start_config = match name {
|
||||||
Some(name) => config.templates.iter().find(|t| t.name == 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 (_, doc) = current!(cx.editor);
|
||||||
let path = match doc.path() {
|
let path = match doc.path() {
|
||||||
Some(path) => path.to_path_buf(),
|
Some(path) => path,
|
||||||
None => {
|
None => {
|
||||||
cx.editor
|
cx.editor
|
||||||
.set_error("Can't start debug: document has no path".to_string());
|
.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
|
let language_config = cx.editor.syn_loader.language_config_for_file_name(path);
|
||||||
.editor
|
let config = match language_config
|
||||||
.syn_loader
|
.as_deref()
|
||||||
.language_config_for_file_name(&path)
|
.and_then(|config| config.debugger.as_ref())
|
||||||
.and_then(|x| x.debugger.clone());
|
{
|
||||||
let config = match config {
|
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => {
|
None => {
|
||||||
cx.editor.set_error(
|
cx.editor.set_error(
|
||||||
@ -321,7 +320,7 @@ pub fn dap_launch(cx: &mut Context) {
|
|||||||
|
|
||||||
cx.push_layer(Box::new(Picker::new(
|
cx.push_layer(Box::new(Picker::new(
|
||||||
true,
|
true,
|
||||||
config.templates,
|
config.templates.clone(),
|
||||||
|template| template.name.as_str().into(),
|
|template| template.name.as_str().into(),
|
||||||
|cx, template, _action| {
|
|cx, template, _action| {
|
||||||
let completions = template.completion.clone();
|
let completions = template.completion.clone();
|
||||||
|
Loading…
Reference in New Issue
Block a user