@@ -10,7 +10,7 @@ import ParseEngineGateway from './parse-engine-gateway';
1010let notifier : Notifier = new Notifier ( 'html-css-class-completion.cache' ) ;
1111let uniqueDefinitions : CssClassDefinition [ ] = [ ] ;
1212
13- const completionTriggerChars = [ '"' , '\'' , ' ' ] ;
13+ const completionTriggerChars = [ '"' , '\'' , ' ' , '.' ] ;
1414
1515let caching : boolean = false ;
1616
@@ -74,7 +74,7 @@ function cache(): Promise<void> {
7474 } ) ;
7575}
7676
77- function provideCompletionItemsGenerator ( languageSelector : string , classMatchRegex : RegExp ) {
77+ function provideCompletionItemsGenerator ( languageSelector : string , classMatchRegex : RegExp , classPrefix : string = '' ) {
7878 return vscode . languages . registerCompletionItemProvider ( languageSelector , {
7979 provideCompletionItems ( document : vscode . TextDocument , position : vscode . Position ) : vscode . CompletionItem [ ] {
8080 const start : vscode . Position = new vscode . Position ( position . line , 0 ) ;
@@ -92,13 +92,19 @@ function provideCompletionItemsGenerator(languageSelector: string, classMatchReg
9292
9393 // Creates a collection of CompletionItem based on the classes already cached
9494 let completionItems = uniqueDefinitions . map ( definition => {
95- return new vscode . CompletionItem ( definition . className , vscode . CompletionItemKind . Variable ) ;
95+ const completionItem = new vscode . CompletionItem ( definition . className , vscode . CompletionItemKind . Variable ) ;
96+ const completionClassName = `${ classPrefix } ${ definition . className } ` ;
97+
98+ completionItem . filterText = completionClassName ;
99+ completionItem . insertText = completionClassName ;
100+
101+ return completionItem ;
96102 } ) ;
97103
98104 // Removes from the collection the classes already specified on the class attribute
99105 for ( let i = 0 ; i < classesOnAttribute . length ; i ++ ) {
100106 for ( let j = 0 ; j < completionItems . length ; j ++ ) {
101- if ( completionItems [ j ] . label === classesOnAttribute [ i ] ) {
107+ if ( completionItems [ j ] . insertText === classesOnAttribute [ i ] ) {
102108 completionItems . splice ( j , 1 ) ;
103109 }
104110 }
@@ -135,7 +141,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
135141 // CSS based extensions
136142 [ 'css' , 'sass' , 'scss' ] . forEach ( ( extension ) => {
137143 // Support for Tailwind CSS
138- context . subscriptions . push ( provideCompletionItemsGenerator ( extension , / @ a p p l y ( [ \w - ] * $ ) / ) ) ;
144+ context . subscriptions . push ( provideCompletionItemsGenerator ( extension , / @ a p p l y ( [ \. \ w- ] * $ ) / , '.' ) ) ;
139145 } ) ;
140146
141147 caching = true ;
0 commit comments