tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
diff --git a/src/extension.ts b/src/extension.ts
index ca54c38dc180e8240640ee2a0af5e80d911af0a0..2601445166499b800b0a3b452dfcd5b63d73cde5 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -24,7 +24,7 @@ 'ejs',
'nunjucks',
'haml'
]
-const CSS_TYPES = ['css', 'sass', 'scss', 'less', 'postcss', 'stylus']
+const CSS_TYPES = ['css', 'sass', 'scss', 'less', 'stylus']
export async function activate(context: vscode.ExtensionContext) {
let tw
@@ -103,15 +103,16 @@ export function deactivate() {}
function createCompletionItemProvider({
items,
+ prefixedItems,
languages,
regex,
triggerCharacters,
config,
- prefix = '',
enable = () => true,
emmet = false
}: {
items?
+ prefixedItems?
languages?: string[]
regex?: RegExp
triggerCharacters?: string[]
@@ -177,14 +178,21 @@ .replace(/^\./, '')
.replace(/\./g, '.children.')
if (pth !== '') {
- const itms = dlv(items, pth)
+ const itms =
+ prefixedItems &&
+ str.indexOf('.') === 0 &&
+ str.indexOf(separator) === -1
+ ? dlv(prefixedItems, pth)
+ : dlv(items, pth)
if (itms) {
- return prefixItems(itms.children, str, prefix)
+ return Object.keys(itms.children).map(x => itms.children[x].item)
}
}
if (str.indexOf(separator) === -1) {
- return prefixItems(items, str, prefix)
+ return prefixedItems && str.indexOf('.') === 0
+ ? Object.keys(prefixedItems).map(x => prefixedItems[x].item)
+ : Object.keys(items).map(x => items[x].item)
}
return []
@@ -282,7 +290,7 @@
return level
}
-function createItems(classNames, separator, config, parent = '') {
+function createItems(classNames, separator, config, prefix = '', parent = '') {
let items = {}
let i = 0
@@ -292,6 +300,7 @@ const item = new vscode.CompletionItem(
key,
vscode.CompletionItemKind.Constant
)
+ item.filterText = item.insertText = `${prefix}${key}`
item.sortText = naturalExpand(i.toString())
if (key !== 'container' && key !== 'group') {
if (parent) {
@@ -318,6 +327,7 @@ const item = new vscode.CompletionItem(
`${key}${separator}`,
vscode.CompletionItemKind.Constant
)
+ item.filterText = item.insertText = `${prefix}${key}${separator}`
item.sortText = naturalExpand(i.toString())
item.command = { title: '', command: 'editor.action.triggerSuggest' }
if (key === 'hover' || key === 'focus' || key === 'active') {
@@ -335,7 +345,7 @@ item.sortText = `m${item.sortText}`
}
items[key] = {
item,
- children: createItems(classNames[key], separator, config, key)
+ children: createItems(classNames[key], separator, config, prefix, key)
}
i++
}
@@ -391,6 +401,7 @@ private _providers: vscode.Disposable[]
private _disposable: vscode.Disposable
private _tailwind
private _items
+ private _prefixedItems
private _configItems
private _prefixedConfigItems
@@ -409,6 +420,12 @@
if (separator !== ':') return
this._items = createItems(tailwind.classNames, separator, tailwind.config)
+ this._prefixedItems = createItems(
+ tailwind.classNames,
+ separator,
+ tailwind.config,
+ '.'
+ )
this._configItems = createConfigItems(tailwind.config)
this._prefixedConfigItems = createConfigItems(tailwind.config, '.')
@@ -427,11 +444,21 @@
this._providers.push(
createCompletionItemProvider({
items: this._items,
+ prefixedItems: this._prefixedItems,
languages: CSS_TYPES,
regex: /@apply ([^;}]*)$/,
triggerCharacters: ['.', separator],
- config: tailwind.config,
- prefix: '.'
+ config: tailwind.config
+ })
+ )
+ this._providers.push(
+ createCompletionItemProvider({
+ items: this._items,
+ prefixedItems: this._items,
+ languages: ['postcss'],
+ regex: /@apply ([^;}]*)$/,
+ triggerCharacters: ['.', separator],
+ config: tailwind.config
})
)
@@ -536,6 +563,12 @@ this._providers.push(
createConfigItemProvider({
languages: CSS_TYPES,
items: this._prefixedConfigItems
+ })
+ )
+ this._providers.push(
+ createConfigItemProvider({
+ languages: ['postcss'],
+ items: this._configItems
})
)