on master help sign in
normalize LSP workspaces (#6517)
bfe8d26Pascal Kuthe
helix-lsp/src/client.rs+3−1
@@ -4,7 +4,7 @@ use crate::{
4 Call, Error, OffsetEncoding, Result,
4 Call, Error, OffsetEncoding, Result,
5};
5};
6
6
7−use helix_core::{find_workspace, ChangeSet, Rope};
7+use helix_core::{find_workspace, path, ChangeSet, Rope};
8use helix_loader::{self, VERSION_AND_GIT_HASH};
8use helix_loader::{self, VERSION_AND_GIT_HASH};
9use lsp::{
9use lsp::{
10 notification::DidChangeWorkspaceFolders, DidChangeWorkspaceFoldersParams, OneOf,
10 notification::DidChangeWorkspaceFolders, DidChangeWorkspaceFoldersParams, OneOf,
@@ -66,6 +66,7 @@ impl Client {
66 may_support_workspace: bool,
66 may_support_workspace: bool,
67 ) -> bool {
67 ) -> bool {
68 let (workspace, workspace_is_cwd) = find_workspace();
68 let (workspace, workspace_is_cwd) = find_workspace();
69+ let workspace = path::get_normalized_path(&workspace);
69 let root = find_lsp_workspace(
70 let root = find_lsp_workspace(
70 doc_path
71 doc_path
71 .and_then(|x| x.parent().and_then(|x| x.to_str()))
72 .and_then(|x| x.parent().and_then(|x| x.to_str()))
@@ -201,6 +202,7 @@ impl Client {
201 let (server_rx, server_tx, initialize_notify) =
202 let (server_rx, server_tx, initialize_notify) =
202 Transport::start(reader, writer, stderr, id);
203 Transport::start(reader, writer, stderr, id);
203 let (workspace, workspace_is_cwd) = find_workspace();
204 let (workspace, workspace_is_cwd) = find_workspace();
205+ let workspace = path::get_normalized_path(&workspace);
204 let root = find_lsp_workspace(
206 let root = find_lsp_workspace(
205 doc_path
207 doc_path
206 .and_then(|x| x.parent().and_then(|x| x.to_str()))
208 .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};
10pub use lsp_types as lsp;
10pub use lsp_types as lsp;
11
11
12use futures_util::stream::select_all::SelectAll;
12use futures_util::stream::select_all::SelectAll;
13+use helix_core::{
14+ path,
13−use helix_core::syntax::{LanguageConfiguration, LanguageServerConfiguration};
15+ syntax::{LanguageConfiguration, LanguageServerConfiguration},
16+};
14use tokio::sync::mpsc::UnboundedReceiver;
17use tokio::sync::mpsc::UnboundedReceiver;
15
18
16use std::{
19use std::{
@@ -888,12 +891,13 @@ pub fn find_lsp_workspace(
888 workspace_is_cwd: bool,
891 workspace_is_cwd: bool,
889) -> Option<PathBuf> {
892) -> Option<PathBuf> {
890 let file = std::path::Path::new(file);
893 let file = std::path::Path::new(file);
891− let file = if file.is_absolute() {
894+ let mut file = if file.is_absolute() {
892 file.to_path_buf()
895 file.to_path_buf()
893 } else {
896 } else {
894 let current_dir = std::env::current_dir().expect("unable to determine current directory");
897 let current_dir = std::env::current_dir().expect("unable to determine current directory");
895 current_dir.join(file)
898 current_dir.join(file)
896 };
899 };
900+ file = path::get_normalized_path(&file);
897
901
898 if !file.starts_with(workspace) {
902 if !file.starts_with(workspace) {
899 return None;
903 return None;
@@ -910,7 +914,7 @@ pub fn find_lsp_workspace(
910
914
911 if root_dirs
915 if root_dirs
912 .iter()
916 .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)
914 {
918 {
915 // if the worskapce is the cwd do not search any higher for workspaces
919 // if the worskapce is the cwd do not search any higher for workspaces
916 // but specify
920 // but specify