@@ -10,7 +10,7 @@ import ParseEngineGateway from './parse-engine-gateway';
10
10
let notifier : Notifier = new Notifier ( 'html-css-class-completion.cache' ) ;
11
11
let uniqueDefinitions : CssClassDefinition [ ] = [ ] ;
12
12
13
- const completionTriggerChars = [ '"' , '\'' , ' ' ] ;
13
+ const completionTriggerChars = [ '"' , '\'' , ' ' , '.' ] ;
14
14
15
15
let caching : boolean = false ;
16
16
@@ -74,7 +74,7 @@ function cache(): Promise<void> {
74
74
} ) ;
75
75
}
76
76
77
- function provideCompletionItemsGenerator ( languageSelector : string , classMatchRegex : RegExp ) {
77
+ function provideCompletionItemsGenerator ( languageSelector : string , classMatchRegex : RegExp , classPrefix : string = '' ) {
78
78
return vscode . languages . registerCompletionItemProvider ( languageSelector , {
79
79
provideCompletionItems ( document : vscode . TextDocument , position : vscode . Position ) : vscode . CompletionItem [ ] {
80
80
const start : vscode . Position = new vscode . Position ( position . line , 0 ) ;
@@ -92,13 +92,19 @@ function provideCompletionItemsGenerator(languageSelector: string, classMatchReg
92
92
93
93
// Creates a collection of CompletionItem based on the classes already cached
94
94
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 ;
96
102
} ) ;
97
103
98
104
// Removes from the collection the classes already specified on the class attribute
99
105
for ( let i = 0 ; i < classesOnAttribute . length ; i ++ ) {
100
106
for ( let j = 0 ; j < completionItems . length ; j ++ ) {
101
- if ( completionItems [ j ] . label === classesOnAttribute [ i ] ) {
107
+ if ( completionItems [ j ] . insertText === classesOnAttribute [ i ] ) {
102
108
completionItems . splice ( j , 1 ) ;
103
109
}
104
110
}
@@ -135,7 +141,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
135
141
// CSS based extensions
136
142
[ 'css' , 'sass' , 'scss' ] . forEach ( ( extension ) => {
137
143
// 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- ] * $ ) / , '.' ) ) ;
139
145
} ) ;
140
146
141
147
caching = true ;
0 commit comments