@@ -46,14 +46,15 @@ define(function (require, exports, module) {
46
46
Session = require ( "Session" ) ,
47
47
Acorn = require ( "thirdparty/acorn/acorn" ) ;
48
48
49
- var session = null , // object that encapsulates the current session state
50
- cachedCursor = null , // last cursor of the current hinting session
51
- cachedHints = null , // sorted hints for the current hinting session
52
- cachedType = null , // describes the lookup type and the object context
53
- cachedToken = null , // the token used in the current hinting session
54
- matcher = null , // string matcher for hints
55
- jsHintsEnabled = true , // preference setting to enable/disable the hint session
56
- noHintsOnDot = false , // preference setting to prevent hints on dot
49
+ var session = null , // object that encapsulates the current session state
50
+ cachedCursor = null , // last cursor of the current hinting session
51
+ cachedHints = null , // sorted hints for the current hinting session
52
+ cachedType = null , // describes the lookup type and the object context
53
+ cachedToken = null , // the token used in the current hinting session
54
+ matcher = null , // string matcher for hints
55
+ jsHintsEnabled = true , // preference setting to enable/disable the hint session
56
+ hintDetailsEnabled = true , // preference setting to enable/disable hint type details
57
+ noHintsOnDot = false , // preference setting to prevent hints on dot
57
58
ignoreChange ; // can ignore next "change" event if true;
58
59
59
60
// Languages that support inline JavaScript
@@ -78,6 +79,11 @@ define(function (require, exports, module) {
78
79
PreferencesManager . definePreference ( "codehint.JSHints" , "boolean" , true , {
79
80
description : Strings . DESCRIPTION_JS_HINTS
80
81
} ) ;
82
+
83
+ // This preference controls whether detailed type metadata will be desplayed within hint list. Deafults to true.
84
+ PreferencesManager . definePreference ( "jscodehints.typedetails" , "boolean" , true , {
85
+ description : Strings . DESCRIPTION_JS_HINTS_TYPE_DETAILS
86
+ } ) ;
81
87
82
88
/**
83
89
* Check whether any of code hints preferences for JS Code Hints is disabled
@@ -100,6 +106,10 @@ define(function (require, exports, module) {
100
106
noHintsOnDot = ! ! PreferencesManager . get ( "jscodehints.noHintsOnDot" ) ;
101
107
} ) ;
102
108
109
+ PreferencesManager . on ( "change" , "jscodehints.typedetails" , function ( ) {
110
+ hintDetailsEnabled = PreferencesManager . get ( "jscodehints.typedetails" ) ;
111
+ } ) ;
112
+
103
113
/**
104
114
* Sets the configuration, generally for testing/debugging use.
105
115
* Configuration keys are merged into the current configuration.
@@ -149,62 +159,42 @@ define(function (require, exports, module) {
149
159
console . debug ( "Hints" , _ . pluck ( hints , "label" ) ) ;
150
160
}
151
161
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 ;
162
+ function formatTypeDataForToken ( $hintObj , token ) {
169
163
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' ;
164
+ if ( ! hintDetailsEnabled ) {
165
+ return ;
166
+ }
167
+
168
+ $hintObj . addClass ( 'brackets-js-hints-with-type-details' ) ;
169
+
170
+ ( function _appendLink ( ) {
171
+ if ( token . url ) {
172
+ $ ( '<a></a>' ) . appendTo ( $hintObj ) . addClass ( "jshint-link" ) . attr ( 'href' , token . url ) . on ( "click" , function ( event ) {
173
+ event . stopImmediatePropagation ( ) ;
174
+ event . stopPropagation ( ) ;
175
+ } ) ;
176
+ }
177
+ } ( ) ) ;
178
+
179
+ if ( token . type ) {
180
+ if ( token . type . trim ( ) !== '?' ) {
181
+ if ( token . type . length < 30 ) {
182
+ $ ( '<span>' + token . type . split ( '->' ) . join ( ':' ) . toString ( ) . trim ( ) + '</span>' ) . appendTo ( $hintObj ) . addClass ( "brackets-js-hints-type-details" ) ;
183
183
}
184
+ $ ( '<span>' + token . type . split ( '->' ) . join ( ':' ) . toString ( ) . trim ( ) + '</span>' ) . appendTo ( $hintObj ) . addClass ( "jshint-description" ) ;
184
185
}
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' ;
186
+ } else {
187
+ if ( token . keyword ) {
188
+ $ ( '<span>keyword</span>' ) . appendTo ( $hintObj ) . addClass ( "brackets-js-hints-keyword" ) ;
204
189
}
205
190
}
206
- return typeClass ;
191
+
192
+ if ( token . doc ) {
193
+ $hintObj . attr ( 'title' , token . doc ) ;
194
+ $ ( '<span></span>' ) . text ( token . doc . trim ( ) ) . appendTo ( $hintObj ) . addClass ( "jshint-jsdoc" ) ;
195
+ }
207
196
}
197
+
208
198
209
199
/*
210
200
* Returns a formatted list of hints with the query substring
@@ -222,8 +212,7 @@ define(function (require, exports, module) {
222
212
function formatHints ( hints , query ) {
223
213
return hints . map ( function ( token ) {
224
214
var $hintObj = $ ( "<span>" ) . addClass ( "brackets-js-hints" ) ;
225
- ( $hintObj ) . addClass ( getRenderTypeClass ( token . type ) ) ;
226
- //$('<span>' + getRenderType(token.type) + '</span>').appendTo($hintObj).addClass("brackets-js-hints-type");
215
+
227
216
// level indicates either variable scope or property confidence
228
217
if ( ! type . property && ! token . builtin && token . depth !== undefined ) {
229
218
switch ( token . depth ) {
@@ -272,33 +261,7 @@ define(function (require, exports, module) {
272
261
273
262
$hintObj . data ( "token" , token ) ;
274
263
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
- }
264
+ formatTypeDataForToken ( $hintObj , token ) ;
302
265
303
266
return $hintObj ;
304
267
} ) ;
0 commit comments