Skip to content

Commit dd147e1

Browse files
committed
Fix using source information
1 parent e099fe6 commit dd147e1

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

server/src/analyser.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,25 +521,49 @@ export default class Analyzer {
521521
}
522522

523523
// 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) {
526532
return Object.keys(this.uriToAnalyzedDocument)
527533
}
528534

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+
}
530552

553+
private ensureUrisAreAnalyzed(uris: string[]): string[] {
531554
return uris.filter((uri) => {
532555
if (!this.uriToAnalyzedDocument[uri]) {
533556
// Either the background analysis didn't run or the file is outside
534557
// the workspace. Let us try to analyze the file.
535558
try {
559+
logger.debug(`Analyzing file not covered by background analysis ${uri}...`)
536560
const fileContent = fs.readFileSync(new URL(uri), 'utf8')
537561
this.analyze({
538562
document: TextDocument.create(uri, 'shell', 1, fileContent),
539563
uri,
540564
})
541565
} catch (err) {
542-
logger.warn(`Error while analyzing sourced file ${uri}: ${err}`)
566+
logger.warn(`Error while analyzing file ${uri}: ${err}`)
543567
return false
544568
}
545569
}
@@ -559,7 +583,7 @@ export default class Analyzer {
559583
uri: fromUri,
560584
position,
561585
}: { uri?: string; position?: LSP.Position } = {}): LSP.SymbolInformation[] {
562-
return this.getReachableUris({ uri: fromUri }).reduce((symbols, uri) => {
586+
return this.getAnalyzedReachableUris({ fromUri }).reduce((symbols, uri) => {
563587
const analyzedDocument = this.uriToAnalyzedDocument[uri]
564588

565589
if (analyzedDocument) {

0 commit comments

Comments
 (0)