@@ -86,11 +86,26 @@ export const select_imported_files_command = (
8686 ] . includes ( ext )
8787 ) {
8888 if ( / \b ( i m p o r t | e x p o r t | r e q u i r e ) \b / . test ( line ) ) {
89+ in_import_block = true
90+ }
91+
92+ if ( in_import_block ) {
8993 const matches = [ ...line . matchAll ( / [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / g) ]
90- for ( const match of matches ) {
91- positions_to_check . push (
92- new vscode . Position ( i , match . index ! + 1 )
93- )
94+ if ( matches . length > 0 ) {
95+ for ( const match of matches ) {
96+ positions_to_check . push (
97+ new vscode . Position ( i , match . index ! + 1 )
98+ )
99+ }
100+ in_import_block = false
101+ } else if (
102+ ! / \b ( i m p o r t | e x p o r t | r e q u i r e ) \b / . test ( line ) &&
103+ ( / [ ; ] / . test ( line ) ||
104+ / ^ \s * ( c o n s t | l e t | v a r | c l a s s | f u n c t i o n | i n t e r f a c e | t y p e | e n u m ) \b / . test (
105+ line
106+ ) )
107+ ) {
108+ in_import_block = false
94109 }
95110 }
96111 } else if ( ext == '.py' ) {
@@ -306,15 +321,24 @@ export const select_imported_files_command = (
306321 } ,
307322 async ( ) => {
308323 const queue : vscode . Uri [ ] = [ ]
324+ const index_queue : vscode . Uri [ ] = [ ...starting_uris ]
309325
310- for ( const start_uri of starting_uris ) {
311- const immediate = await get_imports_for_uri ( start_uri )
312- for ( const uri_str of immediate ) {
326+ while ( index_queue . length > 0 ) {
327+ const current_uri = index_queue . shift ( ) !
328+ const imports = await get_imports_for_uri ( current_uri )
329+ for ( const uri_str of imports ) {
313330 if ( ! visited_uris . has ( uri_str ) ) {
314331 visited_uris . add ( uri_str )
315332 if ( is_valid_uri ( uri_str ) ) {
316333 immediate_uris . add ( uri_str )
317- queue . push ( vscode . Uri . parse ( uri_str ) )
334+ const parsed_uri = vscode . Uri . parse ( uri_str )
335+ queue . push ( parsed_uri )
336+
337+ if (
338+ path . parse ( parsed_uri . fsPath ) . name . toLowerCase ( ) == 'index'
339+ ) {
340+ index_queue . push ( parsed_uri )
341+ }
318342 }
319343 }
320344 }
0 commit comments