@@ -14,6 +14,48 @@ export const check_imported_files_command = (
1414 async ( item : FileItem ) => {
1515 if ( ! item ) return
1616
17+ const is_valid_uri = ( uri_str : string ) : boolean => {
18+ const uri = vscode . Uri . parse ( uri_str )
19+ const file_path = uri . fsPath
20+ const workspace_root =
21+ workspace_provider . get_workspace_root_for_file ( file_path )
22+ if ( ! workspace_root ) return false
23+ const relative_path = path . relative ( workspace_root , file_path )
24+ return (
25+ ! workspace_provider . is_ignored_by_patterns ( file_path ) &&
26+ ! workspace_provider . is_excluded ( relative_path )
27+ )
28+ }
29+
30+ const get_all_files = async ( uri : vscode . Uri ) : Promise < vscode . Uri [ ] > => {
31+ try {
32+ const stat = await vscode . workspace . fs . stat ( uri )
33+ if ( stat . type & vscode . FileType . File ) {
34+ return [ uri ]
35+ } else if ( stat . type & vscode . FileType . Directory ) {
36+ const results : vscode . Uri [ ] = [ ]
37+ const entries = await vscode . workspace . fs . readDirectory ( uri )
38+ for ( const [ name , type ] of entries ) {
39+ const child_uri = vscode . Uri . joinPath ( uri , name )
40+ if ( ! is_valid_uri ( child_uri . toString ( ) ) ) continue
41+ if ( type & vscode . FileType . File ) {
42+ results . push ( child_uri )
43+ } else if ( type & vscode . FileType . Directory ) {
44+ results . push ( ...( await get_all_files ( child_uri ) ) )
45+ }
46+ }
47+ return results
48+ }
49+ } catch { }
50+ return [ ]
51+ }
52+
53+ const starting_uris = await get_all_files ( item . resourceUri )
54+ if ( starting_uris . length === 0 ) {
55+ vscode . window . showInformationMessage ( 'No valid files found to check.' )
56+ return
57+ }
58+
1759 const get_imports_for_uri = async (
1860 document_uri : vscode . Uri
1961 ) : Promise < string [ ] > => {
@@ -90,36 +132,27 @@ export const check_imported_files_command = (
90132
91133 const immediate_uris = new Set < string > ( )
92134 const recursive_uris = new Set < string > ( )
93- const visited_uris = new Set < string > ( [ item . resourceUri . toString ( ) ] )
94-
95- const is_valid_uri = ( uri_str : string ) : boolean => {
96- const uri = vscode . Uri . parse ( uri_str )
97- const file_path = uri . fsPath
98- const workspace_root =
99- workspace_provider . get_workspace_root_for_file ( file_path )
100- if ( ! workspace_root ) return false
101- const relative_path = path . relative ( workspace_root , file_path )
102- return (
103- ! workspace_provider . is_ignored_by_patterns ( file_path ) &&
104- ! workspace_provider . is_excluded ( relative_path )
105- )
106- }
135+ const visited_uris = new Set < string > (
136+ starting_uris . map ( ( u ) => u . toString ( ) )
137+ )
107138
108139 await vscode . window . withProgress (
109140 {
110- location : vscode . ProgressLocation . Window ,
111- title : 'Checking imported files ...'
141+ location : vscode . ProgressLocation . Notification ,
142+ title : 'Processing imports ...'
112143 } ,
113144 async ( ) => {
114- const immediate = await get_imports_for_uri ( item . resourceUri )
115145 const queue : vscode . Uri [ ] = [ ]
116146
117- for ( const uri_str of immediate ) {
118- if ( ! visited_uris . has ( uri_str ) ) {
119- visited_uris . add ( uri_str )
120- if ( is_valid_uri ( uri_str ) ) {
121- immediate_uris . add ( uri_str )
122- queue . push ( vscode . Uri . parse ( uri_str ) )
147+ for ( const start_uri of starting_uris ) {
148+ const immediate = await get_imports_for_uri ( start_uri )
149+ for ( const uri_str of immediate ) {
150+ if ( ! visited_uris . has ( uri_str ) ) {
151+ visited_uris . add ( uri_str )
152+ if ( is_valid_uri ( uri_str ) ) {
153+ immediate_uris . add ( uri_str )
154+ queue . push ( vscode . Uri . parse ( uri_str ) )
155+ }
123156 }
124157 }
125158 }
0 commit comments