custom seperator
parent
d0127c15eb
commit
def423a7fe
|
@ -3,7 +3,8 @@
|
||||||
import * as vscode from 'vscode'
|
import * as vscode from 'vscode'
|
||||||
import { dirname } from 'path'
|
import { dirname } from 'path'
|
||||||
const htmlElements = require('./htmlElements.js')
|
const htmlElements = require('./htmlElements.js')
|
||||||
const tailwindClassNames = require('tailwind-class-names')
|
// const tailwindClassNames = require('tailwind-class-names')
|
||||||
|
const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist')
|
||||||
const dlv = require('dlv')
|
const dlv = require('dlv')
|
||||||
const Color = require('color')
|
const Color = require('color')
|
||||||
|
|
||||||
|
@ -172,29 +173,55 @@ function createCompletionItemProvider({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let screens = Object.keys(dlv(config, 'screens', {}))
|
||||||
|
let states = ['hover', 'focus', 'active', 'group-hover']
|
||||||
|
|
||||||
if (typeof str !== 'undefined') {
|
if (typeof str !== 'undefined') {
|
||||||
|
console.log(str)
|
||||||
const pth = str
|
const pth = str
|
||||||
.replace(new RegExp(`${separator}`, 'g'), '.')
|
.replace(
|
||||||
|
new RegExp(
|
||||||
|
`^(${[...screens, ...states].join('|')})${separator}`,
|
||||||
|
'g'
|
||||||
|
),
|
||||||
|
'$1.'
|
||||||
|
)
|
||||||
|
.replace(new RegExp(`\\.(${states.join('|')})${separator}`), '.$1.')
|
||||||
.replace(/\.$/, '')
|
.replace(/\.$/, '')
|
||||||
.replace(/^\./, '')
|
.replace(/^\./, '')
|
||||||
.replace(/\./g, '.children.')
|
.replace(/\./g, '.children.')
|
||||||
|
|
||||||
|
let hasSep = new RegExp(
|
||||||
|
`^(${[...screens, ...states].join('|')})${separator}`
|
||||||
|
).test(str)
|
||||||
|
if (!hasSep && str.endsWith(separator)) {
|
||||||
|
// token.cancel()
|
||||||
|
return getItemsWithRange(
|
||||||
|
items,
|
||||||
|
new vscode.Range(position.translate(0, -str.length), position)
|
||||||
|
)
|
||||||
|
let mobNav = new vscode.CompletionItem(
|
||||||
|
'mob-nav-',
|
||||||
|
vscode.CompletionItemKind.Constant
|
||||||
|
)
|
||||||
|
mobNav.range = new vscode.Range(position.translate(0, -4), position)
|
||||||
|
return [mobNav]
|
||||||
|
}
|
||||||
|
|
||||||
if (pth !== '') {
|
if (pth !== '') {
|
||||||
const itms =
|
const itms =
|
||||||
prefixedItems &&
|
prefixedItems && str.indexOf('.') === 0 && !hasSep
|
||||||
str.indexOf('.') === 0 &&
|
|
||||||
str.indexOf(separator) === -1
|
|
||||||
? dlv(prefixedItems, pth)
|
? dlv(prefixedItems, pth)
|
||||||
: dlv(items, pth)
|
: dlv(items, pth)
|
||||||
if (itms) {
|
if (itms) {
|
||||||
return Object.keys(itms.children).map(x => itms.children[x].item)
|
return getItemsWithRange(itms.children)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str.indexOf(separator) === -1) {
|
if (!hasSep) {
|
||||||
return prefixedItems && str.indexOf('.') === 0
|
return prefixedItems && str.indexOf('.') === 0
|
||||||
? Object.keys(prefixedItems).map(x => prefixedItems[x].item)
|
? getItemsWithRange(prefixedItems)
|
||||||
: Object.keys(items).map(x => items[x].item)
|
: getItemsWithRange(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
@ -207,6 +234,14 @@ function createCompletionItemProvider({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getItemsWithRange(items, range: vscode.Range = undefined) {
|
||||||
|
return Object.keys(items).map(x => {
|
||||||
|
let i = items[x].item
|
||||||
|
i.range = range
|
||||||
|
return i
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function createConfigItemProvider({
|
function createConfigItemProvider({
|
||||||
languages,
|
languages,
|
||||||
items,
|
items,
|
||||||
|
@ -419,7 +454,7 @@ class TailwindIntellisense {
|
||||||
|
|
||||||
const separator = dlv(tailwind.config, 'options.separator', ':')
|
const separator = dlv(tailwind.config, 'options.separator', ':')
|
||||||
|
|
||||||
if (separator !== ':') return
|
// if (separator !== ':') return
|
||||||
|
|
||||||
this._items = createItems(tailwind.classNames, separator, tailwind.config)
|
this._items = createItems(tailwind.classNames, separator, tailwind.config)
|
||||||
this._prefixedItems = createItems(
|
this._prefixedItems = createItems(
|
||||||
|
|
Loading…
Reference in New Issue