From a368ee89c8d72c1e919f6b8559f03e95c813c882 Mon Sep 17 00:00:00 2001 From: MinusGix Date: Fri, 22 Jul 2022 11:55:58 -0500 Subject: [PATCH] Set the current directory when starting the LSP --- lapce-proxy/src/lsp.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lapce-proxy/src/lsp.rs b/lapce-proxy/src/lsp.rs index 7f10807d..e4d99f58 100644 --- a/lapce-proxy/src/lsp.rs +++ b/lapce-proxy/src/lsp.rs @@ -3,7 +3,7 @@ use std::{ collections::HashMap, io::{BufRead, BufReader, BufWriter, Write}, - path::Path, + path::{Path, PathBuf}, process::{self, Child, ChildStderr, ChildStdout, Command, Stdio}, sync::{ atomic::{AtomicBool, Ordering}, @@ -800,7 +800,8 @@ pub fn new( dispatcher: Dispatcher, ) -> Arc { //TODO: better handling of binary args in plugin - let mut process = Self::process(exec_path, args.clone()); + let workspace = dispatcher.workspace.lock().clone(); + let mut process = Self::process(workspace, exec_path, args.clone()); let writer = Box::new(BufWriter::new(process.stdin.take().unwrap())); let stdout = process.stdout.take().unwrap(); let stderr = process.stderr.take().unwrap(); @@ -875,8 +876,15 @@ fn handle_stderr(&self, stderr: ChildStderr, language_id: String) { }); } - fn process(exec_path: &str, args: Vec) -> Child { + fn process( + workspace: Option, + exec_path: &str, + args: Vec, + ) -> Child { let mut process = Command::new(exec_path); + if let Some(workspace) = workspace { + process.current_dir(&workspace); + } process.args(args); @@ -892,7 +900,11 @@ fn process(exec_path: &str, args: Vec) -> Child { fn reload(&self) { //TODO: avoid clone using a &[String] ? - let mut process = Self::process(&self.exec_path, self.args.clone()); + let mut process = Self::process( + self.dispatcher.workspace.lock().clone(), + &self.exec_path, + self.args.clone(), + ); let writer = Box::new(BufWriter::new(process.stdin.take().unwrap())); let stdout = process.stdout.take().unwrap();