Skip to content

Commit

Permalink
normalize LSP workspaces (helix-editor#6517)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 0ab4f71 commit 83cb490
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
Call, Error, OffsetEncoding, Result,
};

use helix_core::{find_workspace, ChangeSet, Rope};
use helix_core::{find_workspace, path, ChangeSet, Rope};
use helix_loader::{self, VERSION_AND_GIT_HASH};
use lsp::{
notification::DidChangeWorkspaceFolders, DidChangeWorkspaceFoldersParams, OneOf,
Expand Down Expand Up @@ -66,6 +66,7 @@ impl Client {
may_support_workspace: bool,
) -> bool {
let (workspace, workspace_is_cwd) = find_workspace();
let workspace = path::get_normalized_path(&workspace);
let root = find_lsp_workspace(
doc_path
.and_then(|x| x.parent().and_then(|x| x.to_str()))
Expand Down Expand Up @@ -201,6 +202,7 @@ impl Client {
let (server_rx, server_tx, initialize_notify) =
Transport::start(reader, writer, stderr, id);
let (workspace, workspace_is_cwd) = find_workspace();
let workspace = path::get_normalized_path(&workspace);
let root = find_lsp_workspace(
doc_path
.and_then(|x| x.parent().and_then(|x| x.to_str()))
Expand Down
10 changes: 7 additions & 3 deletions helix-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pub use lsp::{Position, Url};
pub use lsp_types as lsp;

use futures_util::stream::select_all::SelectAll;
use helix_core::syntax::{LanguageConfiguration, LanguageServerConfiguration};
use helix_core::{
path,
syntax::{LanguageConfiguration, LanguageServerConfiguration},
};
use tokio::sync::mpsc::UnboundedReceiver;

use std::{
Expand Down Expand Up @@ -892,12 +895,13 @@ pub fn find_lsp_workspace(
workspace_is_cwd: bool,
) -> Option<PathBuf> {
let file = std::path::Path::new(file);
let file = if file.is_absolute() {
let mut file = if file.is_absolute() {
file.to_path_buf()
} else {
let current_dir = std::env::current_dir().expect("unable to determine current directory");
current_dir.join(file)
};
file = path::get_normalized_path(&file);

if !file.starts_with(workspace) {
return None;
Expand All @@ -914,7 +918,7 @@ pub fn find_lsp_workspace(

if root_dirs
.iter()
.any(|root_dir| root_dir == ancestor.strip_prefix(workspace).unwrap())
.any(|root_dir| path::get_normalized_path(&workspace.join(root_dir)) == ancestor)
{
// if the worskapce is the cwd do not search any higher for workspaces
// but specify
Expand Down

0 comments on commit 83cb490

Please sign in to comment.