@@ -40,27 +40,37 @@ export class DbCache {
40
40
return false ;
41
41
}
42
42
43
- static lookupSymbol ( name : string , schema : string , objectFilter : string [ ] ) : LookupResult {
44
- const routine = this . getCachedType ( schema , name , `FUNCTION` ) || this . getCachedType ( schema , name , `PROCEDURE` ) ;
45
- if ( routine ) {
46
- const signatures = this . getCachedSignatures ( schema , name ) ;
47
- return { routine, signatures } as RoutineDetail ;
48
- }
49
-
50
- objectFilter = objectFilter . map ( o => o . toLowerCase ( ) ) ;
51
-
52
- const included = ( name : string ) => {
43
+ static async lookupSymbol ( name : string , schema : string | undefined , objectFilter : string [ ] ) : Promise < LookupResult > {
44
+ const included = ( lookupName : string ) => {
53
45
if ( objectFilter ) {
54
- return objectFilter . includes ( name . toLowerCase ( ) ) ;
46
+ return objectFilter . includes ( lookupName . toLowerCase ( ) ) ;
55
47
}
56
48
return true ;
57
49
}
58
50
59
- // Search objects
60
- for ( const currentSchema of this . schemaObjects . values ( ) ) {
61
- const chosenObject = currentSchema . find ( sqlObject => included ( sqlObject . name ) && sqlObject . name === name && sqlObject . schema === schema ) ;
62
- if ( chosenObject ) {
63
- return chosenObject ;
51
+ if ( schema ) {
52
+ // Looking routine
53
+ const routine = this . getCachedRoutine ( schema , name , `FUNCTION` ) || this . getCachedRoutine ( schema , name , `PROCEDURE` ) ;
54
+ if ( routine ) {
55
+ const signatures = this . getCachedSignatures ( schema , name ) ;
56
+ return { routine, signatures } as RoutineDetail ;
57
+ }
58
+
59
+ objectFilter = objectFilter . map ( o => o . toLowerCase ( ) ) ;
60
+
61
+ // Search objects
62
+ for ( const currentSchema of this . schemaObjects . values ( ) ) {
63
+ const chosenObject = currentSchema . find ( sqlObject => included ( sqlObject . name ) && sqlObject . name === name && sqlObject . schema === schema ) ;
64
+ if ( chosenObject ) {
65
+ return chosenObject ;
66
+ }
67
+ }
68
+
69
+ // Finally, let's do a last lookup
70
+ const lookupRoutine = await this . getRoutine ( schema , name , `FUNCTION` ) || await this . getRoutine ( schema , name , `PROCEDURE` ) ;
71
+ if ( lookupRoutine ) {
72
+ const signatures = await this . getSignaturesFor ( schema , name , lookupRoutine . specificNames ) ;
73
+ return { routine : lookupRoutine , signatures } as RoutineDetail ;
64
74
}
65
75
}
66
76
@@ -111,7 +121,7 @@ export class DbCache {
111
121
return this . schemaObjects . get ( key ) || [ ] ;
112
122
}
113
123
114
- static async getType ( schema : string , name : string , type : CallableType ) {
124
+ static async getRoutine ( schema : string , name : string , type : CallableType ) {
115
125
const key = getKey ( type , schema , name ) ;
116
126
117
127
if ( ! this . routines . has ( key ) || this . shouldReset ( name ) ) {
@@ -127,7 +137,7 @@ export class DbCache {
127
137
return this . routines . get ( key ) || undefined ;
128
138
}
129
139
130
- static getCachedType ( schema : string , name : string , type : CallableType ) {
140
+ static getCachedRoutine ( schema : string , name : string , type : CallableType ) {
131
141
const key = getKey ( type , schema , name ) ;
132
142
return this . routines . get ( key ) || undefined
133
143
}
0 commit comments