Skip to content

Commit

Permalink
feat: support variant suggest in attributify
Browse files Browse the repository at this point in the history
  • Loading branch information
voorjaar committed May 17, 2021
1 parent 58cd014 commit bac763a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,25 @@ export function registerCompletions(ctx: ExtensionContext, core: Core): Disposab
if (text.match(/(<\w+\s*)[^>]*$/) !== null) {
const key = text.match(/\S+(?=\s*=\s*["']?[^"']*$)/)?.[0];
if (key && key in attrs) {
return attrs[key].map((value, index) => {
const variantsCompletion = getConfig('windicss.enableVariantCompletion') ? core.variantCompletions.map(({ label, documentation }, index) => {
const item = new CompletionItem(label, CompletionItemKind.Module);
item.documentation = documentation;
item.sortText = '2-' + index.toString().padStart(8, '0');
item.command = {
command: 'editor.action.triggerSuggest',
title: label,
};
return item;
}): [];

const valuesCompletion = attrs[key].map((value, index) => {
const item = new CompletionItem(value, CompletionItemKind.Constant);
item.detail = key;
item.sortText = '1-' + index.toString().padStart(8, '0');
return item;
});

return [...variantsCompletion, ...valuesCompletion];
}
if (!key) {
return Object.keys(attrs).map((name, index) => {
Expand Down Expand Up @@ -147,6 +160,7 @@ export function registerCompletions(ctx: ExtensionContext, core: Core): Disposab
},
'"',
'=',
':',
' ',
'\'',
));
Expand Down

0 comments on commit bac763a

Please sign in to comment.