@@ -19,6 +19,10 @@ import {
19
19
RelativePattern ,
20
20
ConfigurationScope ,
21
21
WorkspaceConfiguration ,
22
+ CompletionItem ,
23
+ CompletionItemKind ,
24
+ CompletionList ,
25
+ ProviderResult ,
22
26
} from 'vscode'
23
27
import {
24
28
LanguageClient ,
@@ -207,6 +211,45 @@ export async function activate(context: ExtensionContext) {
207
211
{
208
212
documentSelector : [ { language : 'tailwindcss' } ] ,
209
213
outputChannelName : 'Tailwind CSS Language Mode' ,
214
+ middleware : {
215
+ provideCompletionItem ( document , position , context , token , next ) {
216
+ function updateRanges ( item : CompletionItem ) {
217
+ const range = item . range
218
+ if (
219
+ range instanceof Range &&
220
+ range . end . isAfter ( position ) &&
221
+ range . start . isBeforeOrEqual ( position )
222
+ ) {
223
+ item . range = { inserting : new Range ( range . start , position ) , replacing : range }
224
+ }
225
+ }
226
+ function updateLabel ( item : CompletionItem ) {
227
+ if ( item . kind === CompletionItemKind . Color ) {
228
+ item . label = {
229
+ label : item . label as string ,
230
+ description : item . documentation as string ,
231
+ }
232
+ }
233
+ }
234
+ function updateProposals (
235
+ r : CompletionItem [ ] | CompletionList | null | undefined
236
+ ) : CompletionItem [ ] | CompletionList | null | undefined {
237
+ if ( r ) {
238
+ ; ( Array . isArray ( r ) ? r : r . items ) . forEach ( updateRanges )
239
+ ; ( Array . isArray ( r ) ? r : r . items ) . forEach ( updateLabel )
240
+ }
241
+ return r
242
+ }
243
+ const isThenable = < T > ( obj : ProviderResult < T > ) : obj is Thenable < T > =>
244
+ obj && ( < any > obj ) [ 'then' ]
245
+
246
+ const r = next ( document , position , context , token )
247
+ if ( isThenable < CompletionItem [ ] | CompletionList | null | undefined > ( r ) ) {
248
+ return r . then ( updateProposals )
249
+ }
250
+ return updateProposals ( r )
251
+ } ,
252
+ } ,
210
253
}
211
254
)
212
255
context . subscriptions . push ( client . start ( ) )
0 commit comments