@@ -521,25 +521,49 @@ export default class Analyzer {
521
521
}
522
522
523
523
// Private methods
524
- private getReachableUris ( { uri : fromUri } : { uri ?: string } = { } ) : string [ ] {
525
- if ( ! fromUri || this . includeAllWorkspaceSymbols ) {
524
+
525
+ /**
526
+ * Returns all reachable URIs from the given URI based on sourced commands
527
+ * If no URI is given, all URIs from the background analysis are returned.
528
+ * If the includeAllWorkspaceSymbols flag is set, all URIs from the background analysis are also included.
529
+ */
530
+ private getReachableUris ( { fromUri } : { fromUri ?: string } = { } ) : string [ ] {
531
+ if ( ! fromUri ) {
526
532
return Object . keys ( this . uriToAnalyzedDocument )
527
533
}
528
534
529
- const uris = [ fromUri , ...Array . from ( this . findAllSourcedUris ( { uri : fromUri } ) ) ]
535
+ const urisBasedOnSourcing = [
536
+ fromUri ,
537
+ ...Array . from ( this . findAllSourcedUris ( { uri : fromUri } ) ) ,
538
+ ]
539
+
540
+ if ( this . includeAllWorkspaceSymbols ) {
541
+ return Array . from (
542
+ new Set ( [ ...urisBasedOnSourcing , ...Object . keys ( this . uriToAnalyzedDocument ) ] ) ,
543
+ )
544
+ } else {
545
+ return urisBasedOnSourcing
546
+ }
547
+ }
548
+
549
+ private getAnalyzedReachableUris ( { fromUri } : { fromUri ?: string } = { } ) : string [ ] {
550
+ return this . ensureUrisAreAnalyzed ( this . getReachableUris ( { fromUri } ) )
551
+ }
530
552
553
+ private ensureUrisAreAnalyzed ( uris : string [ ] ) : string [ ] {
531
554
return uris . filter ( ( uri ) => {
532
555
if ( ! this . uriToAnalyzedDocument [ uri ] ) {
533
556
// Either the background analysis didn't run or the file is outside
534
557
// the workspace. Let us try to analyze the file.
535
558
try {
559
+ logger . debug ( `Analyzing file not covered by background analysis ${ uri } ...` )
536
560
const fileContent = fs . readFileSync ( new URL ( uri ) , 'utf8' )
537
561
this . analyze ( {
538
562
document : TextDocument . create ( uri , 'shell' , 1 , fileContent ) ,
539
563
uri,
540
564
} )
541
565
} catch ( err ) {
542
- logger . warn ( `Error while analyzing sourced file ${ uri } : ${ err } ` )
566
+ logger . warn ( `Error while analyzing file ${ uri } : ${ err } ` )
543
567
return false
544
568
}
545
569
}
@@ -559,7 +583,7 @@ export default class Analyzer {
559
583
uri : fromUri ,
560
584
position,
561
585
} : { uri ?: string ; position ?: LSP . Position } = { } ) : LSP . SymbolInformation [ ] {
562
- return this . getReachableUris ( { uri : fromUri } ) . reduce ( ( symbols , uri ) => {
586
+ return this . getAnalyzedReachableUris ( { fromUri } ) . reduce ( ( symbols , uri ) => {
563
587
const analyzedDocument = this . uriToAnalyzedDocument [ uri ]
564
588
565
589
if ( analyzedDocument ) {
0 commit comments