Skip to content

Commit 7c9bc1c

Browse files
committed
Find workspace from document path
1 parent 86a8ea5 commit 7c9bc1c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

helix-lsp/src/client.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl Client {
4949
root_markers: &[String],
5050
id: usize,
5151
req_timeout: u64,
52+
doc_path: Option<&std::path::PathBuf>,
5253
) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
5354
// Resolve path to the binary
5455
let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
@@ -72,7 +73,10 @@ impl Client {
7273
let (server_rx, server_tx, initialize_notify) =
7374
Transport::start(reader, writer, stderr, id);
7475

75-
let root_path = find_root(None, root_markers);
76+
let root_path = find_root(
77+
doc_path.and_then(|x| x.parent().and_then(|x| x.to_str())),
78+
root_markers,
79+
);
7680

7781
let root_uri = root_path
7882
.clone()

helix-lsp/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ impl Registry {
320320
.map(|(_, client)| client.as_ref())
321321
}
322322

323-
pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Client>> {
323+
pub fn get(
324+
&mut self,
325+
language_config: &LanguageConfiguration,
326+
doc_path: Option<&std::path::PathBuf>,
327+
) -> Result<Arc<Client>> {
324328
let config = match &language_config.language_server {
325329
Some(config) => config,
326330
None => return Err(Error::LspNotDefined),
@@ -338,6 +342,7 @@ impl Registry {
338342
&language_config.roots,
339343
id,
340344
config.timeout,
345+
doc_path,
341346
)?;
342347
self.incoming.push(UnboundedReceiverStream::new(incoming));
343348
let client = Arc::new(client);

helix-view/src/editor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ impl Editor {
808808

809809
// try to find a language server based on the language name
810810
let language_server = doc.language.as_ref().and_then(|language| {
811-
ls.get(language)
811+
ls.get(language, doc.path())
812812
.map_err(|e| {
813813
log::error!(
814814
"Failed to initialize the LSP for `{}` {{ {} }}",

0 commit comments

Comments
 (0)