102102 * param {Editor} editor
103103 * A non-null editor object for the active window.
104104 *
105- * param {String } implicitChar
105+ * param {string } implicitChar
106106 * Either null, if the hinting request was explicit, or a single character
107107 * that represents the last insertion and that indicates an implicit
108108 * hinting request.
109109 *
110- * return {Boolean }
110+ * return {boolean }
111111 * Determines whether the current provider is able to provide hints for
112112 * the given editor context and, in case implicitChar is non- null,
113113 * whether it is appropriate to do so.
164164 * assume that the document will not be changed outside of the editor
165165 * during a session.
166166 *
167- * param {String } implicitChar
167+ * param {string } implicitChar
168168 * Either null, if the request to update the hint list was a result of
169169 * navigation, or a single character that represents the last insertion.
170170 *
171- * return {(Object + jQuery.Deferred)<
172- * hints: Array<(String + jQuery.Obj) >,
173- * match: String ,
174- * selectInitial: Boolean> }
171+ * return {jQuery.Deferred|{
172+ * hints: Array.<string|jQueryObject >,
173+ * match: string ,
174+ * selectInitial: boolean} }
175175 *
176176 * Null if the provider wishes to end the hinting session. Otherwise, a
177177 * response object, possibly deferred, that provides 1. a sorted array
182182 * by default in the hint list window. If match is non-null, then the
183183 * hints should be strings.
184184 *
185- * TODO - NOT YET IMPLEMENTED: If the match is null, the manager will not
185+ * If the match is null, the manager will not
186186 * attempt to emphasize any parts of the hints when rendering the hint
187187 * list; instead the provider may return strings or jQuery objects for
188188 * which emphasis is self-contained. For example, the strings may contain
204204 * explicit hinting request, which may result in a new hinting session
205205 * being opened with some provider, but not necessarily the current one.
206206 *
207- * param {String } hint
207+ * param {string } hint
208208 * The hint to be inserted into the editor context for the current session.
209209 *
210- * return {Boolean }
210+ * return {boolean }
211211 * Indicates whether the manager should follow hint insertion with an
212212 * explicit hint request.
213213 */
@@ -232,7 +232,7 @@ define(function (require, exports, module) {
232232 keyDownEditor = null ;
233233
234234 /**
235- * Comparator to sort providers based on their priority
235+ * Comparator to sort providers from high to low priority
236236 */
237237 function _providerSort ( a , b ) {
238238 return b . priority - a . priority ;
@@ -242,74 +242,54 @@ define(function (require, exports, module) {
242242 * The method by which a CodeHintProvider registers its willingness to
243243 * providing hints for editors in a given language.
244244 *
245- * @param {CodeHintProvider } provider
245+ * @param {! CodeHintProvider } provider
246246 * The hint provider to be registered, described below.
247247 *
248- * @param {Array[(string|Object<name: string>)] } languageIDs
248+ * @param {! Array.< string>} languageIds
249249 * The set of language ids for which the provider is capable of
250250 * providing hints. If the special language id name "all" is included then
251- * the provider may be called upon to provide hints for any language.
251+ * the provider may be called for any language.
252252 *
253- * @param {Integer } priority
254- * A non-negative number used to break ties among hint providers for a
255- * particular language. Providers that register with a higher priority
256- * will have the opportunity to provide hints at a given language before
257- * those with a lower priority. Brackets default providers have
258- * priority zero.
253+ * @param {?number } priority
254+ * Used to break ties among hint providers for a particular language.
255+ * Providers with a higher number will be asked for hints before those
256+ * with a lower priority value. Defaults to zero.
259257 */
260- function registerHintProvider ( providerInfo , languageIDs , priority ) {
258+ function registerHintProvider ( providerInfo , languageIds , priority ) {
261259 var providerObj = { provider : providerInfo ,
262260 priority : priority || 0 } ;
263-
264- if ( languageIDs ) {
265- var languageIdNames = [ ] , registerForAllLanguages = false ;
266- var i , currentLanguageID ;
267- for ( i = 0 ; i < languageIDs . length ; i ++ ) {
268- currentLanguageID = languageIDs [ i ] ;
269- if ( currentLanguageID ) {
270- if ( currentLanguageID === "all" ) {
271- registerForAllLanguages = true ;
272- break ;
273- } else {
274- languageIdNames . push ( currentLanguageID ) ;
275- }
261+
262+ if ( languageIds . indexOf ( "all" ) !== - 1 ) {
263+ // Ignore anything else in languageIds and just register for every language. This includes
264+ // the special "all" language since its key is in the hintProviders map from the beginning.
265+ var languageId ;
266+ for ( languageId in hintProviders ) {
267+ if ( hintProviders . hasOwnProperty ( languageId ) ) {
268+ hintProviders [ languageId ] . push ( providerObj ) ;
269+ hintProviders [ languageId ] . sort ( _providerSort ) ;
276270 }
277271 }
278-
279- if ( registerForAllLanguages ) {
280- // if we're registering in all, then we ignore the languageIdNames array
281- // so that we avoid registering a provider twice
282- var languageId ;
283- for ( languageId in hintProviders ) {
284- if ( hintProviders . hasOwnProperty ( languageId ) ) {
285- hintProviders [ languageId ] . push ( providerObj ) ;
286- hintProviders [ languageId ] . sort ( _providerSort ) ;
287- }
272+ } else {
273+ languageIds . forEach ( function ( languageId ) {
274+ if ( ! hintProviders [ languageId ] ) {
275+ // Initialize provider list with any existing all-language providers
276+ hintProviders [ languageId ] = Array . prototype . concat ( hintProviders . all ) ;
288277 }
289- } else {
290- languageIdNames . forEach ( function ( languageId ) {
291- if ( languageId ) {
292- if ( ! hintProviders [ languageId ] ) {
293- // initialize a new language id with all providers
294- hintProviders [ languageId ] = Array . prototype . concat ( hintProviders . all ) ;
295- }
296- hintProviders [ languageId ] . push ( providerObj ) ;
297- hintProviders [ languageId ] . sort ( _providerSort ) ;
298- }
299- } ) ;
300- }
278+ hintProviders [ languageId ] . push ( providerObj ) ;
279+ hintProviders [ languageId ] . sort ( _providerSort ) ;
280+ } ) ;
301281 }
302282 }
303283
304284 /**
305285 * Return the array of hint providers for the given language id.
306286 * This gets called (potentially) on every keypress. So, it should be fast.
307287 *
308- * @param {( string|Object<name: string>) } languageID
309- * @return {Array.<{provider: Object, languageIDs: Array.<string> , priority: number}> }
288+ * @param {! string} languageId
289+ * @return {? Array.<{provider: Object, priority: number}> }
310290 */
311- function _getProvidersForLanguageID ( languageID ) {
312- return hintProviders [ languageID ] || hintProviders . all ;
291+ function _getProvidersForLanguageId ( languageId ) {
292+ return hintProviders [ languageId ] || hintProviders . all ;
313293 }
314294
315295 /**
@@ -395,7 +375,7 @@ define(function (require, exports, module) {
395375 function _beginSession ( editor ) {
396376 // Find a suitable provider, if any
397377 var language = editor . getLanguageForSelection ( ) ,
398- enabledProviders = _getProvidersForLanguageID ( language . getId ( ) ) ;
378+ enabledProviders = _getProvidersForLanguageId ( language . getId ( ) ) ;
399379
400380 enabledProviders . some ( function ( item , index ) {
401381 if ( item . provider . hasHints ( editor , lastChar ) ) {
0 commit comments