mirror of
https://github.com/helix-editor/helix.git
synced 2024-09-20 08:05:10 +03:00
normalize LSP workspaces (#6517)
This commit is contained in:
parent
38b9bdf871
commit
bfe8d267fe
@ -4,7 +4,7 @@
|
|||||||
Call, Error, OffsetEncoding, Result,
|
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 helix_loader::{self, VERSION_AND_GIT_HASH};
|
||||||
use lsp::{
|
use lsp::{
|
||||||
notification::DidChangeWorkspaceFolders, DidChangeWorkspaceFoldersParams, OneOf,
|
notification::DidChangeWorkspaceFolders, DidChangeWorkspaceFoldersParams, OneOf,
|
||||||
@ -66,6 +66,7 @@ pub fn try_add_doc(
|
|||||||
may_support_workspace: bool,
|
may_support_workspace: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let (workspace, workspace_is_cwd) = find_workspace();
|
let (workspace, workspace_is_cwd) = find_workspace();
|
||||||
|
let workspace = path::get_normalized_path(&workspace);
|
||||||
let root = find_lsp_workspace(
|
let root = find_lsp_workspace(
|
||||||
doc_path
|
doc_path
|
||||||
.and_then(|x| x.parent().and_then(|x| x.to_str()))
|
.and_then(|x| x.parent().and_then(|x| x.to_str()))
|
||||||
@ -201,6 +202,7 @@ pub fn start(
|
|||||||
let (server_rx, server_tx, initialize_notify) =
|
let (server_rx, server_tx, initialize_notify) =
|
||||||
Transport::start(reader, writer, stderr, id);
|
Transport::start(reader, writer, stderr, id);
|
||||||
let (workspace, workspace_is_cwd) = find_workspace();
|
let (workspace, workspace_is_cwd) = find_workspace();
|
||||||
|
let workspace = path::get_normalized_path(&workspace);
|
||||||
let root = find_lsp_workspace(
|
let root = find_lsp_workspace(
|
||||||
doc_path
|
doc_path
|
||||||
.and_then(|x| x.parent().and_then(|x| x.to_str()))
|
.and_then(|x| x.parent().and_then(|x| x.to_str()))
|
||||||
|
@ -10,7 +10,10 @@
|
|||||||
pub use lsp_types as lsp;
|
pub use lsp_types as lsp;
|
||||||
|
|
||||||
use futures_util::stream::select_all::SelectAll;
|
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 tokio::sync::mpsc::UnboundedReceiver;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
@ -888,12 +891,13 @@ pub fn find_lsp_workspace(
|
|||||||
workspace_is_cwd: bool,
|
workspace_is_cwd: bool,
|
||||||
) -> Option<PathBuf> {
|
) -> Option<PathBuf> {
|
||||||
let file = std::path::Path::new(file);
|
let file = std::path::Path::new(file);
|
||||||
let file = if file.is_absolute() {
|
let mut file = if file.is_absolute() {
|
||||||
file.to_path_buf()
|
file.to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
let current_dir = std::env::current_dir().expect("unable to determine current directory");
|
let current_dir = std::env::current_dir().expect("unable to determine current directory");
|
||||||
current_dir.join(file)
|
current_dir.join(file)
|
||||||
};
|
};
|
||||||
|
file = path::get_normalized_path(&file);
|
||||||
|
|
||||||
if !file.starts_with(workspace) {
|
if !file.starts_with(workspace) {
|
||||||
return None;
|
return None;
|
||||||
@ -910,7 +914,7 @@ pub fn find_lsp_workspace(
|
|||||||
|
|
||||||
if root_dirs
|
if root_dirs
|
||||||
.iter()
|
.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
|
// if the worskapce is the cwd do not search any higher for workspaces
|
||||||
// but specify
|
// but specify
|
||||||
|
Loading…
Reference in New Issue
Block a user