@@ -5,7 +5,6 @@ use std::{
55 fs,
66 path:: { Path , PathBuf } ,
77} ;
8- use wax:: { Glob , WalkBehavior } ;
98
109use 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} ;
1817use miette:: { miette, IntoDiagnostic , Result } ;
19- use nu_path :: canonicalize_with ;
18+ use nu_glob :: { glob , Paths } ;
2019use nu_protocol:: { engine:: StateWorkingSet , Span } ;
2120use 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 ! ( "\n Current file is not in any workspace" ) ) ?;
157- let scripts = Self :: find_nu_scripts_in_folder ( & current_workspace_folder. uri )
158- . ok_or_else ( || miette ! ( "\n Failed 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