@@ -57,7 +57,7 @@ export class TypeSearch {
5757 return new VariableSearchResult ( typeName , EstimationSource . Value , valueAssignment ) ;
5858 }
5959
60- match = new RegExp ( ` ^ *([^(\\ s#"']+)\\(?` ) . exec ( valueAssignment ) ;
60+ match = / ^ * ( [ ^ ( \s # " ' ] + ) \( ? / . exec ( valueAssignment ) ;
6161 if ( ! match ) {
6262 return null ;
6363 }
@@ -73,27 +73,12 @@ export class TypeSearch {
7373 return new VariableSearchResult ( value , EstimationSource . Value , valueAssignment ) ;
7474 }
7575 } else {
76- if ( value . includes ( "." ) ) {
77- let split = value . split ( "." ) ;
78- value = split [ split . length - 1 ] ;
79- }
80- // Find the function definition and check if the return type is hinted
81- const regExp = new RegExp ( `^[ \t]*def ${ value } \\([^)]*\\) *-> *([a-zA-Z_][a-zA-Z0-9_.\\[\\]]+)` , "m" ) ;
82-
83- const hintedCallMatch = regExp . exec ( src ) ;
84-
85- if ( hintedCallMatch && hintedCallMatch . length === 2 ) {
86- return new VariableSearchResult (
87- hintedCallMatch [ 1 ] ,
88- EstimationSource . FunctionDefinition ,
89- valueAssignment
90- ) ;
91- }
76+ return this . searchForHintedFunctionCall ( value , src , valueAssignment ) ;
9277 }
9378 return null ;
9479 }
9580
96- // Searching the import source document is not supported (yet?)
81+ // Searching the import source document is not supported
9782 if ( ! this . isImported ( match [ 1 ] , src . substr ( match . index - match . length ) ) ) {
9883 match = this . variableSearchRegExp ( match [ 1 ] ) . exec ( src ) ;
9984 if ( match ) {
@@ -106,6 +91,30 @@ export class TypeSearch {
10691 return null ;
10792 }
10893
94+ private static searchForHintedFunctionCall (
95+ value : string ,
96+ src : string ,
97+ valueAssignment : string
98+ ) : VariableSearchResult | null {
99+ if ( value . includes ( "." ) ) {
100+ let split = value . split ( "." ) ;
101+ value = split [ split . length - 1 ] ;
102+ }
103+
104+ const regExp = new RegExp ( `^[ \t]*def ${ value } \\([^)]*\\) *-> *([a-zA-Z_][a-zA-Z0-9_.\\[\\]]+)` , "m" ) ;
105+
106+ const hintedCallMatch = regExp . exec ( src ) ;
107+
108+ if ( hintedCallMatch && hintedCallMatch . length === 2 ) {
109+ return new VariableSearchResult (
110+ hintedCallMatch [ 1 ] ,
111+ EstimationSource . FunctionDefinition ,
112+ valueAssignment
113+ ) ;
114+ }
115+ return null ;
116+ }
117+
109118 /**
110119 * Detects the type of a value.
111120 *
@@ -171,7 +180,7 @@ export class TypeSearch {
171180 if ( searchResult . estimationSource === EstimationSource . ClassDefinition ) {
172181 return false ;
173182 }
174- const regExp = new RegExp ( " if +[^ ]+ +else( +[^ ]+) *$" ) ;
183+ const regExp = / i f + [ ^ ] + + e l s e ( + [ ^ ] + ) * $ / ;
175184
176185 let ternaryMatch = regExp . exec ( searchResult . valueAssignment ) ;
177186 while ( ternaryMatch ) {
@@ -232,7 +241,7 @@ export class TypeSearch {
232241 exp += `|from +${ moduleName } +import +${ moduleName } +as +${ value } ` ;
233242 }
234243 exp += ")" ;
235- return new RegExp ( exp , "m" ) . test ( src ) ;
244+ return new RegExp ( exp , "m" ) . test ( src ) ;
236245 }
237246
238247 private static isProbablyAClass ( lineText : string ) : boolean {
0 commit comments