@@ -10,6 +10,7 @@ import { getCSSLanguageService, Stylesheet, ICompletionParticipant } from 'vscod
1010import { LanguageMode , Settings } from './languageModes' ;
1111import { HTMLDocumentRegions , CSS_STYLE_RULE } from './embeddedSupport' ;
1212import { Color } from 'vscode-languageserver-protocol/lib/protocol.colorProvider.proposed' ;
13+ import { extractAbbreviation } from 'vscode-emmet-helper' ;
1314
1415export function getCSSMode ( documentRegions : LanguageModelCache < HTMLDocumentRegions > ) : LanguageMode {
1516 let cssLanguageService = getCSSLanguageService ( ) ;
@@ -27,9 +28,27 @@ export function getCSSMode(documentRegions: LanguageModelCache<HTMLDocumentRegio
2728 let embedded = embeddedCSSDocuments . get ( document ) ;
2829 return cssLanguageService . doValidation ( embedded , cssStylesheets . get ( embedded ) , settings && settings . css ) ;
2930 } ,
30- doComplete ( document : TextDocument , position : Position ) {
31+ doComplete ( document : TextDocument , position : Position , settings : Settings , registeredCompletionParticipants : ICompletionParticipant [ ] ) {
3132 let embedded = embeddedCSSDocuments . get ( document ) ;
32- return cssLanguageService . doComplete ( embedded , position , cssStylesheets . get ( embedded ) ) ;
33+ const stylesheet = cssStylesheets . get ( embedded ) ;
34+
35+ if ( registeredCompletionParticipants ) {
36+ const nonEmmetCompletionParticipants = [ ] ;
37+ // Css Emmet completions in html files are provided no matter where the cursor is inside the embedded css document
38+ // Mimic the same here, until we solve the issue of css language service not able to parse complete embedded documents when there are errors
39+ for ( let i = 0 ; i < registeredCompletionParticipants . length ; i ++ ) {
40+ if ( typeof ( < any > registeredCompletionParticipants [ i ] ) . getId === 'function' && ( < any > registeredCompletionParticipants [ i ] ) . getId ( ) === 'emmet' ) {
41+ const extractedResults = extractAbbreviation ( document , position , { lookAhead : false , syntax : 'css' } ) ;
42+ if ( extractedResults && extractedResults . abbreviation ) {
43+ registeredCompletionParticipants [ i ] . onCssProperty ( { propertyName : extractedResults . abbreviation , range : extractedResults . abbreviationRange } ) ;
44+ }
45+ } else {
46+ nonEmmetCompletionParticipants . push ( registeredCompletionParticipants [ i ] ) ;
47+ }
48+ }
49+ cssLanguageService . setCompletionParticipants ( nonEmmetCompletionParticipants ) ;
50+ }
51+ return cssLanguageService . doComplete ( embedded , position , stylesheet ) ;
3352 } ,
3453 setCompletionParticipants ( registeredCompletionParticipants : ICompletionParticipant [ ] ) {
3554 cssLanguageService . setCompletionParticipants ( registeredCompletionParticipants ) ;
0 commit comments