@@ -4,21 +4,31 @@ import { SymbolInfo } from '../extractors';
44import { Token } from '../tokens' ;
55
66export abstract class SymbolInfoExtractor {
7- extract ( symbol : DocumentSymbol , codeObjectPath : string , name : string , document : vscode . TextDocument , symbolPath : string ) : SymbolInfo | undefined {
7+ extract (
8+ symbol : DocumentSymbol ,
9+ codeObjectPath : string ,
10+ names : string | string [ ] ,
11+ document : vscode . TextDocument ,
12+ symbolPath : string
13+ ) : SymbolInfo [ ] {
814 const range = new vscode . Range (
915 new vscode . Position ( symbol . range . start . line , symbol . range . start . character ) ,
1016 new vscode . Position ( symbol . range . end . line , symbol . range . end . character )
1117 ) ;
12- const id = `${ codeObjectPath } $_$${ name } ` ;
1318
14- return {
15- id,
16- name,
17- codeLocation : codeObjectPath ,
18- displayName : symbolPath ,
19- range,
20- documentUri : document . uri
21- } ;
19+ names = Array . isArray ( names ) ? names : [ names ] ;
20+
21+ return names . map ( name => {
22+ const id = `${ codeObjectPath } $_$${ name } ` ;
23+ return {
24+ id,
25+ name,
26+ codeLocation : codeObjectPath ,
27+ displayName : symbolPath ,
28+ range,
29+ documentUri : document . uri
30+ } ;
31+ } ) ;
2232 }
2333
2434 protected isOfKind ( symbol : DocumentSymbol , kind : number ) : boolean {
@@ -27,28 +37,49 @@ export abstract class SymbolInfoExtractor {
2737}
2838
2939export class MethodSymbolInfoExtractor extends SymbolInfoExtractor {
30- extract ( symbol : DocumentSymbol , codeObjectPath : string , name : string , document : vscode . TextDocument , symbolPath : string ) : SymbolInfo | undefined {
40+ extract (
41+ symbol : DocumentSymbol ,
42+ codeObjectPath : string ,
43+ name : string ,
44+ document : vscode . TextDocument ,
45+ symbolPath : string
46+ ) : SymbolInfo [ ] {
3147 if ( this . isOfKind ( symbol , SymbolKind . Method ) ) {
3248 return super . extract ( symbol , codeObjectPath , name , document , symbolPath ) ;
3349 }
50+ return [ ] ;
3451 }
3552}
3653
3754export class NamedFunctionDeclarationSymbolInfoExtractor extends SymbolInfoExtractor {
38- extract ( symbol : DocumentSymbol , codeObjectPath : string , name : string , document : vscode . TextDocument , symbolPath : string ) : SymbolInfo | undefined {
55+ extract (
56+ symbol : DocumentSymbol ,
57+ codeObjectPath : string ,
58+ name : string ,
59+ document : vscode . TextDocument ,
60+ symbolPath : string
61+ ) : SymbolInfo [ ] {
3962 if ( this . isOfKind ( symbol , SymbolKind . Function ) ) {
4063 const textLine = document . lineAt ( symbol . range . start . line ) ;
4164 const functionMatch = `\\s*function\\s*${ symbol . name } ` ; //should handle only function declaration, and filter out function call like db.getAll()
4265 const match = textLine . text . match ( functionMatch ) ;
4366 if ( match !== undefined && match !== null ) {
44- return super . extract ( symbol , codeObjectPath , name , document , symbolPath ) ;
67+ const names = [ name , `Object.${ name } ` ] ;
68+ return super . extract ( symbol , codeObjectPath , names , document , symbolPath ) ;
4569 }
4670 }
71+ return [ ] ;
4772 }
4873}
4974
5075export class AnonymousExpressRequestHandlerSymbolInfoExtractor extends SymbolInfoExtractor {
51- extract ( symbol : DocumentSymbol , codeObjectPath : string , name : string , document : vscode . TextDocument , symbolPath : string ) : SymbolInfo | undefined {
76+ extract (
77+ symbol : DocumentSymbol ,
78+ codeObjectPath : string ,
79+ name : string ,
80+ document : vscode . TextDocument ,
81+ symbolPath : string
82+ ) : SymbolInfo [ ] {
5283 if ( this . isOfKind ( symbol , SymbolKind . Function ) ) {
5384 const pattern = / .* ( g e t | h e a d | p o s t | p u t | d e l e t e | c o n n e c t | o p t i o n s | t r a c e | p a t c h ) \s * \( \s * [ ' " ` ] ( .* ) [ ' " ` ] \) \s * c a l l b a c k $ / i;
5485 const match = name . match ( pattern ) ;
@@ -58,6 +89,7 @@ export class AnonymousExpressRequestHandlerSymbolInfoExtractor extends SymbolInf
5889 return super . extract ( symbol , codeObjectPath , name , document , symbolPath ) ;
5990 }
6091 }
92+ return [ ] ;
6193 }
6294}
6395
@@ -69,13 +101,20 @@ export class VariableFunctionSymbolInfoExtractor extends SymbolInfoExtractor {
69101 super ( ) ;
70102 }
71103
72- extract ( symbol : DocumentSymbol , codeObjectPath : string , name : string , document : vscode . TextDocument , symbolPath : string ) : SymbolInfo | undefined {
104+ extract (
105+ symbol : DocumentSymbol ,
106+ codeObjectPath : string ,
107+ name : string ,
108+ document : vscode . TextDocument ,
109+ symbolPath : string
110+ ) : SymbolInfo [ ] {
73111 if ( this . isOfKind ( symbol , SymbolKind . Variable ) ) {
74112 const key = this . getKey ( symbol . range . start . line , symbol . range . start . character ) ;
75113 const functionToken = this . functionMap [ key ] ;
76114 if ( functionToken !== undefined ) {
77115 return super . extract ( symbol , codeObjectPath , name , document , symbolPath ) ;
78116 }
79117 }
118+ return [ ] ;
80119 }
81120}
0 commit comments