on master help sign in
normalize LSP workspaces (#6517)
commitbfe8d267fec4964c6981ae38d9e4f46cdebb61b7 authorPascal Kuthe <pascal.kuthe@semimod.de> dateMon 3 Apr 2023, 03:56 (4 years ago) parent38b9bdf
2 files changed+10−4
helix-lsp/src/client.rs+3−1 helix-lsp/src/lib.rs+7−3
helix-lsp/src/client.rs+3−1
@@ -4,7 +4,7 @@ use crate::{
44 Call, Error, OffsetEncoding, Result,
55};
66
7−use helix_core::{find_workspace, ChangeSet, Rope};
7+use helix_core::{find_workspace, path, ChangeSet, Rope};
88use helix_loader::{self, VERSION_AND_GIT_HASH};
99use lsp::{
1010 notification::DidChangeWorkspaceFolders, DidChangeWorkspaceFoldersParams, OneOf,
@@ -66,6 +66,7 @@ impl Client {
6666 may_support_workspace: bool,
6767 ) -> bool {
6868 let (workspace, workspace_is_cwd) = find_workspace();
69+ let workspace = path::get_normalized_path(&workspace);
6970 let root = find_lsp_workspace(
7071 doc_path
7172 .and_then(|x| x.parent().and_then(|x| x.to_str()))
@@ -201,6 +202,7 @@ impl Client {
201202 let (server_rx, server_tx, initialize_notify) =
202203 Transport::start(reader, writer, stderr, id);
203204 let (workspace, workspace_is_cwd) = find_workspace();
205+ let workspace = path::get_normalized_path(&workspace);
204206 let root = find_lsp_workspace(
205207 doc_path
206208 .and_then(|x| x.parent().and_then(|x| x.to_str()))
helix-lsp/src/lib.rs+7−3
@@ -10,7 +10,10 @@ pub use lsp::{Position, Url};
1010pub use lsp_types as lsp;
1111
1212use futures_util::stream::select_all::SelectAll;
13−use helix_core::syntax::{LanguageConfiguration, LanguageServerConfiguration};
13+use helix_core::{
14+ path,
15+ syntax::{LanguageConfiguration, LanguageServerConfiguration},
16+};
1417use tokio::sync::mpsc::UnboundedReceiver;
1518
1619use std::{
@@ -888,12 +891,13 @@ pub fn find_lsp_workspace(
888891 workspace_is_cwd: bool,
889892) -> Option<PathBuf> {
890893 let file = std::path::Path::new(file);
891− let file = if file.is_absolute() {
894+ let mut file = if file.is_absolute() {
892895 file.to_path_buf()
893896 } else {
894897 let current_dir = std::env::current_dir().expect("unable to determine current directory");
895898 current_dir.join(file)
896899 };
900+ file = path::get_normalized_path(&file);
897901
898902 if !file.starts_with(workspace) {
899903 return None;
@@ -910,7 +914,7 @@ pub fn find_lsp_workspace(
910914
911915 if root_dirs
912916 .iter()
913− .any(|root_dir| root_dir == ancestor.strip_prefix(workspace).unwrap())
917+ .any(|root_dir| path::get_normalized_path(&workspace.join(root_dir)) == ancestor)
914918 {
915919 // if the worskapce is the cwd do not search any higher for workspaces
916920 // but specify