@@ -48,37 +48,55 @@ export class DocumentInfoProvider implements vscode.Disposable
4848 public async searchForSpan ( instrumentationInfo : InstrumentationInfo ) : Promise < SpanInfo | undefined > {
4949 const codeFileHint = instrumentationInfo . instrumentationName ;
5050 if ( codeFileHint ) {
51- let codeHintFiles = codeFileHint . split ( ' ' ) ;
52- let head = codeHintFiles [ 0 ] ;
53- let folder = await vscode . workspace . workspaceFolders ?. find ( w => w . name === head ) ;
54- let tail = codeHintFiles ;
5551
56- if ( folder ) {
57- tail = codeHintFiles . slice ( 1 ) ;
58- }
52+ if ( codeFileHint === '__main__' ) {
5953
60- if ( codeHintFiles . length >= 1 ) {
61- const files = await vscode . workspace . findFiles ( `**/${ tail . join ( '/' ) } .*` ) ;
54+ let doc = vscode . window . activeTextEditor ?. document
55+ if ( doc ) {
56+ const docInfo = await this . getDocumentInfo ( doc ) ;
57+ if ( docInfo ) {
58+ let spanInfos = docInfo . spans . filter ( span => span . name === instrumentationInfo . spanName ) ;
59+ return spanInfos . firstOrDefault ( x => x !== undefined ) ;
6260
63- const spansPromises = files . map ( async file => {
64- try {
65- const doc = await vscode . workspace . openTextDocument ( file ) ;
66- const docInfo = await this . getDocumentInfo ( doc ) ;
67- if ( docInfo ) {
68- return docInfo . spans . filter ( span => span . name === instrumentationInfo . spanName ) ;
69- }
70- }
71- catch ( error ) {
72- Logger . warn ( `Searching for span "${ instrumentationInfo . spanName } " skipped ${ file . fsPath } ` , error ) ;
7361 }
74- return [ ] ;
75- } ) ;
7662
77- const spnaInfos = ( await Promise . all ( spansPromises ) ) . flat ( ) ;
78- if ( spnaInfos . length === 1 ) {
79- return spnaInfos [ 0 ] ;
63+ }
64+
65+ }
66+ else {
67+
68+ let codeHintFiles = codeFileHint . split ( ' ' ) ;
69+ let head = codeHintFiles [ 0 ] ;
70+ let folder = await vscode . workspace . workspaceFolders ?. find ( w => w . name === head ) ;
71+ let tail = codeHintFiles ;
72+
73+ if ( folder ) {
74+ tail = codeHintFiles . slice ( 1 ) ;
75+ }
76+
77+ if ( codeHintFiles . length >= 1 ) {
78+ const files = await vscode . workspace . findFiles ( `**/${ tail . join ( '/' ) } .*` ) ;
79+
80+ const spansPromises = files . map ( async file => {
81+ try {
82+ const doc = await vscode . workspace . openTextDocument ( file ) ;
83+ const docInfo = await this . getDocumentInfo ( doc ) ;
84+ if ( docInfo ) {
85+ return docInfo . spans . filter ( span => span . name === instrumentationInfo . spanName ) ;
86+ }
87+ }
88+ catch ( error ) {
89+ Logger . warn ( `Searching for span "${ instrumentationInfo . spanName } " skipped ${ file . fsPath } ` , error ) ;
90+ }
91+ return [ ] ;
92+ } ) ;
93+
94+ const spnaInfos = ( await Promise . all ( spansPromises ) ) . flat ( ) . firstOrDefault ( x => x !== undefined ) ;
95+ return spnaInfos ;
8096 }
8197 }
98+
99+
82100 }
83101 }
84102
0 commit comments