@@ -149,6 +149,63 @@ define(function (require, exports, module) {
149149 console . debug ( "Hints" , _ . pluck ( hints , "label" ) ) ;
150150 }
151151
152+ var _infered = true ;
153+
154+ function getInferHelper ( type ) {
155+ return function ( element , index , array ) {
156+ if ( element === type && _infered ) {
157+ _infered = true ;
158+ } else {
159+ _infered = false ;
160+ }
161+ } ;
162+ }
163+
164+ function inferArrayTypeClass ( typeExpr ) {
165+ var type = "type-array" ;
166+ var types = typeExpr . split ( '[' ) [ 1 ] . split ( ']' ) [ 0 ] . split ( ',' ) ;
167+
168+ _infered = true ;
169+
170+ types . every ( getInferHelper ( 'string' ) ) ;
171+ if ( _infered ) {
172+ type = 'type-string-array' ;
173+ } else {
174+ _infered = true ;
175+ types . every ( getInferHelper ( 'number' ) ) ;
176+ if ( _infered ) {
177+ type = 'type-num-array' ;
178+ } else {
179+ _infered = true ;
180+ types . every ( getInferHelper ( 'Object' ) ) ;
181+ if ( _infered ) {
182+ type = 'type-object-array' ;
183+ }
184+ }
185+ }
186+ return type ;
187+ }
188+
189+ function getRenderTypeClass ( type ) {
190+ var typeClass = 'type-undetermined' ;
191+ if ( type ) {
192+ if ( type . indexOf ( 'Object' ) === 0 ) {
193+ typeClass = 'type-object' ;
194+ } else if ( type . indexOf ( '[' ) === 0 ) {
195+ typeClass = inferArrayTypeClass ( type ) ;
196+ } else if ( type . indexOf ( 'fn' ) === 0 ) {
197+ typeClass = 'type-function' ;
198+ } else if ( type . indexOf ( 'string' ) === 0 ) {
199+ typeClass = "type-string" ;
200+ } else if ( type . indexOf ( 'number' ) === 0 ) {
201+ typeClass = 'type-number' ;
202+ } else if ( type . indexOf ( 'bool' ) === 0 ) {
203+ typeClass = 'type-boolean' ;
204+ }
205+ }
206+ return typeClass ;
207+ }
208+
152209 /*
153210 * Returns a formatted list of hints with the query substring
154211 * highlighted.
@@ -165,7 +222,8 @@ define(function (require, exports, module) {
165222 function formatHints ( hints , query ) {
166223 return hints . map ( function ( token ) {
167224 var $hintObj = $ ( "<span>" ) . addClass ( "brackets-js-hints" ) ;
168-
225+ ( $hintObj ) . addClass ( getRenderTypeClass ( token . type ) ) ;
226+ //$('<span>' + getRenderType(token.type) + '</span>').appendTo($hintObj).addClass("brackets-js-hints-type");
169227 // level indicates either variable scope or property confidence
170228 if ( ! type . property && ! token . builtin && token . depth !== undefined ) {
171229 switch ( token . depth ) {
@@ -211,9 +269,37 @@ define(function (require, exports, module) {
211269 } else {
212270 $hintObj . text ( token . value ) ;
213271 }
214-
272+
215273 $hintObj . data ( "token" , token ) ;
216274
275+ function _appendLink ( ) {
276+ if ( token . url ) {
277+ $ ( '<a></a>' ) . appendTo ( $hintObj ) . addClass ( "jshint-link" ) . attr ( 'href' , token . url ) . on ( "click" , function ( event ) {
278+ event . stopImmediatePropagation ( ) ;
279+ event . stopPropagation ( ) ;
280+ } ) ;
281+ }
282+ }
283+
284+ if ( token . type ) {
285+ if ( token . type . length > 40 ) {
286+ _appendLink ( ) ;
287+ $ ( '<span>' + token . type . split ( '->' ) . join ( ':' ) . toString ( ) . trim ( ) + '</span>' ) . appendTo ( $hintObj ) . addClass ( "jshint-description" ) ;
288+ } else {
289+ $ ( '<span>' + token . type . split ( '->' ) . join ( ':' ) . toString ( ) . trim ( ) + '</span>' ) . appendTo ( $hintObj ) . addClass ( "brackets-js-hints-type-details" ) ;
290+ _appendLink ( ) ;
291+ }
292+ } else {
293+ if ( token . keyword ) {
294+ $ ( '<span>keyword</span>' ) . appendTo ( $hintObj ) . addClass ( "brackets-js-hints-type-details" ) . addClass ( "keyword" ) ;
295+ }
296+ }
297+
298+ if ( token . doc ) {
299+ $hintObj . attr ( 'title' , token . doc ) ;
300+ $ ( '<span></span>' ) . text ( token . doc . trim ( ) ) . appendTo ( $hintObj ) . addClass ( "jshint-jsdoc" ) ;
301+ }
302+
217303 return $hintObj ;
218304 } ) ;
219305 }
@@ -234,7 +320,7 @@ define(function (require, exports, module) {
234320 handleWideResults : hints . handleWideResults
235321 } ;
236322 }
237-
323+
238324 /**
239325 * @constructor
240326 */
0 commit comments