Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions helix-lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ arc-swap = "1"
slotmap.workspace = true
thiserror.workspace = true
sonic-rs.workspace = true
libc = "0.2"
windows-sys = "0.61"
26 changes: 21 additions & 5 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,36 @@ impl Client {
Arc<Notify>,
)> {
// Resolve path to the binary
let cmd = helix_stdx::env::which(cmd)?;
let cmd_binary_path = helix_stdx::env::which(cmd)?;

let process = Command::new(cmd)
let mut command = Command::new(cmd_binary_path);
let mut command_mut = command
.envs(server_environment)
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.current_dir(&root_path)
// make sure the process is reaped on drop
.kill_on_drop(true)
.spawn();
.kill_on_drop(true);

let mut process = process?;
#[cfg(unix)]
unsafe {
command_mut = command_mut.pre_exec(|| match libc::setsid() {
-1 => Err(std::io::Error::last_os_error()),
_ => Ok(()),
});
}

#[cfg(windows)]
{
command_mut = command_mut.creation_flags(
windows_sys::Win32::System::Threading::CREATE_NEW_PROCESS_GROUP
| windows_sys::Win32::System::Threading::DETACHED_PROCESS,
);
}

let mut process = command_mut.spawn()?;

// TODO: do we need bufreader/writer here? or do we use async wrappers on unblock?
let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin"));
Expand Down
Loading