Skip to content

Commit

Permalink
Find workspace from document path
Browse files Browse the repository at this point in the history
  • Loading branch information
ath3 committed Aug 26, 2022
1 parent 86a8ea5 commit 7c9bc1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Client {
root_markers: &[String],
id: usize,
req_timeout: u64,
doc_path: Option<&std::path::PathBuf>,
) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
// Resolve path to the binary
let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
Expand All @@ -72,7 +73,10 @@ impl Client {
let (server_rx, server_tx, initialize_notify) =
Transport::start(reader, writer, stderr, id);

let root_path = find_root(None, root_markers);
let root_path = find_root(
doc_path.and_then(|x| x.parent().and_then(|x| x.to_str())),
root_markers,
);

let root_uri = root_path
.clone()
Expand Down
7 changes: 6 additions & 1 deletion helix-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ impl Registry {
.map(|(_, client)| client.as_ref())
}

pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Arc<Client>> {
pub fn get(
&mut self,
language_config: &LanguageConfiguration,
doc_path: Option<&std::path::PathBuf>,
) -> Result<Arc<Client>> {
let config = match &language_config.language_server {
Some(config) => config,
None => return Err(Error::LspNotDefined),
Expand All @@ -338,6 +342,7 @@ impl Registry {
&language_config.roots,
id,
config.timeout,
doc_path,
)?;
self.incoming.push(UnboundedReceiverStream::new(incoming));
let client = Arc::new(client);
Expand Down
2 changes: 1 addition & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ impl Editor {

// try to find a language server based on the language name
let language_server = doc.language.as_ref().and_then(|language| {
ls.get(language)
ls.get(language, doc.path())
.map_err(|e| {
log::error!(
"Failed to initialize the LSP for `{}` {{ {} }}",
Expand Down

0 comments on commit 7c9bc1c

Please sign in to comment.