@@ -384,40 +384,54 @@ define(function (require, exports, module) {
384384 }
385385
386386 // pushedHints stores all the hints that will be displayed to the user
387- // up until this much is the normal working of css code hints
388387 let pushedHints = formatHints ( result ) ;
389388
390389 // needle gives the current word before cursor, make sure that it exists
391390 // also needle shouldn't contain `-`, because for example if user typed:
392391 // `box-siz` then in that case it is very obvious that user wants to type `box-sizing`
393392 // but emmet expands it `box: siz;`. So we prevent calling emmet when needle has `-`.
394393 if ( needle && ! needle . includes ( '-' ) ) {
395- let expandedAbbr = EXPAND_ABBR ( needle , { syntax : "css" , type : "stylesheet" } ) ;
396- if ( expandedAbbr && isEmmetExpandable ( needle , expandedAbbr ) ) {
397-
398- // if the expandedAbbr doesn't have any numbers, we should split the expandedAbbr to,
399- // get its first word before `:`.
400- // For instance, `m` expands to `margin: ;`. Here the `: ;` is unnecessary.
401- // Also, `bgc` expands to `background-color: #fff;`. Here we don't need the `: #fff;`
402- // as we have cssIntelligence to display hints based on the property
403- if ( ! isEmmetAbbrNumeric ( expandedAbbr ) ) {
404- expandedAbbr = expandedAbbr . split ( ':' ) [ 0 ] ;
405- }
406394
407- if ( pushedHints ) {
395+ // wrapped in try catch block because EXPAND_ABBR might throw error when it gets unexpected
396+ // characters such as `, =, etc
397+ try {
398+ let expandedAbbr = EXPAND_ABBR ( needle , { syntax : "css" , type : "stylesheet" } ) ;
399+ if ( expandedAbbr && isEmmetExpandable ( needle , expandedAbbr ) ) {
400+
401+ // if the expandedAbbr doesn't have any numbers, we should split the expandedAbbr to,
402+ // get its first word before `:`.
403+ // For instance, `m` expands to `margin: ;`. Here the `: ;` is unnecessary.
404+ // Also, `bgc` expands to `background-color: #fff;`. Here we don't need the `: #fff;`
405+ // as we have cssIntelligence to display hints based on the property
406+ if ( ! isEmmetAbbrNumeric ( expandedAbbr ) ) {
407+ expandedAbbr = expandedAbbr . split ( ':' ) [ 0 ] ;
408+ }
409+
410+ // this displays an emmet icon at the side of the hint
411+ // this gives an idea to the user that the hint is coming from Emmet
412+ let $icon = $ ( `<span class="emmet-css-code-hint">Emmet</span>` ) ;
408413
409- // to remove duplicate hints. one comes from emmet and other from default css hints.
410- // we remove the default css hints and push emmet hint at the beginning.
411- for ( let i = 0 ; i < pushedHints . length ; i ++ ) {
412- if ( pushedHints [ i ] [ 0 ] . getAttribute ( 'data-val' ) === expandedAbbr ) {
413- pushedHints . splice ( i , 1 ) ;
414- break ;
414+ const $emmetHintObj = $ ( `<span data-val='${ expandedAbbr } '></span>` ) . addClass ( "brackets-css-hints brackets-hints" ) ;
415+ $emmetHintObj . text ( expandedAbbr ) ;
416+ $emmetHintObj . append ( $icon ) ;
417+
418+ if ( pushedHints ) {
419+
420+ // to remove duplicate hints. one comes from emmet and other from default css hints.
421+ // we remove the default css hints and push emmet hint at the beginning.
422+ for ( let i = 0 ; i < pushedHints . length ; i ++ ) {
423+ if ( pushedHints [ i ] [ 0 ] . getAttribute ( 'data-val' ) === expandedAbbr ) {
424+ pushedHints . splice ( i , 1 ) ;
425+ break ;
426+ }
415427 }
428+ pushedHints . unshift ( $emmetHintObj ) ;
429+ } else {
430+ pushedHints = $emmetHintObj ;
416431 }
417- pushedHints . unshift ( expandedAbbr ) ;
418- } else {
419- pushedHints = expandedAbbr ;
420432 }
433+ } catch ( e ) {
434+ // pass
421435 }
422436 }
423437
0 commit comments