我不得不放弃列表/占位符的方式,将建议单独存储:
body: 'color: $1;',
values: ['initial', 'inherit'],
然后,将此命令分配给原始建议(
cssPropertyProvider
):
snippetCompletion.command = {
command: 'editor.action.triggerSuggest',
title: '',
}
并添加一个单独的完成提供者来涵盖这一点:
const cssValueProvider = languages.registerCompletionItemProvider('mjml', {
provideCompletionItems(document, position) {
const snippetCompletions: ProviderResult<CompletionItem[] | CompletionList> = []
cssProperties.forEach((prop) => {
const formattedBody = prop.body.split('$1').join('')
// Ensure the line includes the relevant CSS property
if (!document.lineAt(position).text.includes(formattedBody)) return
prop.values.forEach((val) => {
const snippetCompletion = new CompletionItem(val)
// Sets the suggestion icon to the little orange thing
snippetCompletion.kind = 11 // 11 = Value
// Ensure tab-stops ($1) are handled
snippetCompletion.insertText = new SnippetString(val)
snippetCompletions.push(snippetCompletion)
})
})
return snippetCompletions
},
})
此外,仅针对我的特定用例,我必须添加一个签入
cssPropertyProvider
这防止了属性建议显示在值建议之上:
const cssPropertyProvider = languages.registerCompletionItemProvider('mjml', {
provideCompletionItems(document, position) {
const { text: lineText } = document.lineAt(position)
const lastLineChar = lineText[position.character]
if (lastLineChar === ';') return
...
结果: