Skip to content

Commit eb2b280

Browse files
committed
nu_glob
1 parent b948011 commit eb2b280

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/nu-lsp/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ license = "MIT"
99

1010
[dependencies]
1111
nu-cli = { path = "../nu-cli", version = "0.101.1" }
12+
nu-glob = { path = "../nu-glob", version = "0.101.1" }
1213
nu-parser = { path = "../nu-parser", version = "0.101.1" }
1314
nu-protocol = { path = "../nu-protocol", version = "0.101.1" }
14-
nu-path = { path = "../nu-path", version = "0.101.1" }
1515

1616
crossbeam-channel = { workspace = true }
1717
fuzzy-matcher = { workspace = true }
@@ -27,7 +27,6 @@ wax = { workspace = true }
2727
[dev-dependencies]
2828
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.101.1" }
2929
nu-command = { path = "../nu-command", version = "0.101.1" }
30-
nu-path = { path = "../nu-path", version = "0.101.1" }
3130
nu-test-support = { path = "../nu-test-support", version = "0.101.1" }
3231

3332
assert-json-diff = "2.0"

crates/nu-lsp/src/workspace.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{
55
fs,
66
path::{Path, PathBuf},
77
};
8-
use wax::{Glob, WalkBehavior};
98

109
use crate::{
1110
ast::find_reference_by_id, path_to_uri, span_to_range, uri_to_path, Id, LanguageServer,
@@ -16,7 +15,7 @@ use lsp_types::{
1615
TextDocumentPositionParams, TextEdit, Uri, WorkspaceEdit, WorkspaceFolder,
1716
};
1817
use miette::{miette, IntoDiagnostic, Result};
19-
use nu_path::canonicalize_with;
18+
use nu_glob::{glob, Paths};
2019
use nu_protocol::{engine::StateWorkingSet, Span};
2120
use serde_json::Value;
2221

@@ -154,8 +153,9 @@ impl LanguageServer {
154153
let current_workspace_folder = self
155154
.get_workspace_folder_by_uri(current_uri)
156155
.ok_or_else(|| miette!("\nCurrent file is not in any workspace"))?;
157-
let scripts = Self::find_nu_scripts_in_folder(&current_workspace_folder.uri)
158-
.ok_or_else(|| miette!("\nFailed to find nu scripts in workspace"))?;
156+
let scripts: Vec<PathBuf> = Self::find_nu_scripts_in_folder(&current_workspace_folder.uri)?
157+
.filter_map(|p| p.ok())
158+
.collect();
159159
let len = scripts.len();
160160

161161
self.send_progress_begin(token.clone(), message)?;
@@ -233,28 +233,15 @@ impl LanguageServer {
233233
.cloned()
234234
}
235235

236-
fn find_nu_scripts_in_folder(folder_uri: &Uri) -> Option<Vec<PathBuf>> {
236+
fn find_nu_scripts_in_folder(folder_uri: &Uri) -> Result<Paths> {
237237
println!(" ======================================== ");
238238
let path = uri_to_path(folder_uri);
239239
if !path.is_dir() {
240-
return None;
240+
return Err(miette!("\n workspace folder does not exist."));
241241
}
242242
let pattern = format!("{}/**/*.nu", path.to_string_lossy());
243-
let (prefix, glob) = Glob::new(&pattern).ok()?.partition();
244-
let path = canonicalize_with(&prefix, &path).ok()?;
245-
Some(
246-
glob.walk_with_behavior(
247-
path,
248-
WalkBehavior {
249-
// NOTE: as the progress is not cancellable ATM,
250-
// hard coded the max depth allowed in case it's triggered by accident
251-
depth: 5,
252-
..Default::default()
253-
},
254-
)
255-
.filter_map(|e| Some(e.ok()?.path().to_path_buf()))
256-
.collect(),
257-
)
243+
println!(" ========= {} ========", pattern);
244+
glob(&pattern).into_diagnostic()
258245
}
259246
}
260247

0 commit comments

Comments
 (0)