@@ -31,57 +31,57 @@ impl CommandCompletion {
3131
3232 let paths = working_set. permanent_state . get_env_var_insensitive ( "path" ) ;
3333
34- if let Some ( ( _, paths) ) = paths {
35- if let Ok ( paths) = paths. as_list ( ) {
36- for path in paths {
37- let path = path. coerce_str ( ) . unwrap_or_default ( ) ;
34+ if let Some ( ( _, paths) ) = paths
35+ && let Ok ( paths) = paths. as_list ( )
36+ {
37+ for path in paths {
38+ let path = path. coerce_str ( ) . unwrap_or_default ( ) ;
3839
39- if let Ok ( mut contents) = std:: fs:: read_dir ( path. as_ref ( ) ) {
40- while let Some ( Ok ( item) ) = contents. next ( ) {
41- if working_set
42- . permanent_state
43- . config
44- . completions
45- . external
46- . max_results
47- <= suggs. len ( ) as i64
48- {
49- break ;
50- }
51- let Ok ( name) = item. file_name ( ) . into_string ( ) else {
52- continue ;
53- } ;
54- let value = if matched_internal ( & name) {
55- format ! ( "^{name}" )
56- } else {
57- name. clone ( )
58- } ;
59- if suggs. contains_key ( & value) {
60- continue ;
61- }
62- // TODO: check name matching before a relative heavy IO involved
63- // `is_executable` for performance consideration, should avoid
64- // duplicated `match_aux` call for matched items in the future
65- if matcher. matches ( & name) && is_executable:: is_executable ( item. path ( ) ) {
66- // If there's an internal command with the same name, adds ^cmd to the
67- // matcher so that both the internal and external command are included
68- matcher. add ( & name, value. clone ( ) ) ;
69- suggs. insert (
70- value. clone ( ) ,
71- SemanticSuggestion {
72- suggestion : Suggestion {
73- value,
74- span : sugg_span,
75- append_whitespace : true ,
76- ..Default :: default ( )
77- } ,
78- kind : Some ( SuggestionKind :: Command (
79- CommandType :: External ,
80- None ,
81- ) ) ,
40+ if let Ok ( mut contents) = std:: fs:: read_dir ( path. as_ref ( ) ) {
41+ while let Some ( Ok ( item) ) = contents. next ( ) {
42+ if working_set
43+ . permanent_state
44+ . config
45+ . completions
46+ . external
47+ . max_results
48+ <= suggs. len ( ) as i64
49+ {
50+ break ;
51+ }
52+ let Ok ( name) = item. file_name ( ) . into_string ( ) else {
53+ continue ;
54+ } ;
55+ let value = if matched_internal ( & name) {
56+ format ! ( "^{name}" )
57+ } else {
58+ name. clone ( )
59+ } ;
60+ if suggs. contains_key ( & value) {
61+ continue ;
62+ }
63+ // TODO: check name matching before a relative heavy IO involved
64+ // `is_executable` for performance consideration, should avoid
65+ // duplicated `match_aux` call for matched items in the future
66+ if matcher. matches ( & name) && is_executable:: is_executable ( item. path ( ) ) {
67+ // If there's an internal command with the same name, adds ^cmd to the
68+ // matcher so that both the internal and external command are included
69+ matcher. add ( & name, value. clone ( ) ) ;
70+ suggs. insert (
71+ value. clone ( ) ,
72+ SemanticSuggestion {
73+ suggestion : Suggestion {
74+ value,
75+ span : sugg_span,
76+ append_whitespace : true ,
77+ ..Default :: default ( )
8278 } ,
83- ) ;
84- }
79+ kind : Some ( SuggestionKind :: Command (
80+ CommandType :: External ,
81+ None ,
82+ ) ) ,
83+ } ,
84+ ) ;
8585 }
8686 }
8787 }
0 commit comments