diff --git a/src/extension.ts b/src/extension.ts
index 5f796c94c1b678aeeb1c99ff1350732c2200f194..ca54c38dc180e8240640ee2a0af5e80d911af0a0 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -1,7 +1,8 @@
'use strict'
import * as vscode from 'vscode'
-import { join, dirname } from 'path'
+import { dirname } from 'path'
+const htmlElements = require('./htmlElements.js')
const tailwindClassNames = require('tailwind-class-names')
const dlv = require('dlv')
const Color = require('color')
@@ -16,18 +17,14 @@ 'razor',
'php',
'blade',
'use strict'
-const Color = require('color')
-'use strict'
const CONFIG_GLOB =
'markdown',
'erb',
'handlebars',
'ejs',
'nunjucks',
-
+ let watcher = vscode.workspace.createFileSystemWatcher(CONFIG_GLOB)
import { join, dirname } from 'path'
- // for jsx
- ...JS_TYPES
]
const CSS_TYPES = ['css', 'sass', 'scss', 'less', 'postcss', 'stylus']
@@ -106,20 +103,34 @@ }
export function deactivate() {}
-const Color = require('color')
+import * as vscode from 'vscode'
const dlv = require('dlv')
+const tailwindClassNames = require('tailwind-class-names')
items,
+ languages,
+ let watcher = vscode.workspace.createFileSystemWatcher(CONFIG_GLOB)
const Color = require('color')
+ let watcher = vscode.workspace.createFileSystemWatcher(CONFIG_GLOB)
const CONFIG_GLOB =
-const Color = require('color')
+ config,
+ let watcher = vscode.workspace.createFileSystemWatcher(CONFIG_GLOB)
'**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
-const CONFIG_GLOB =
+ watcher.onDidChange(onFileChange)
-const CONFIG_GLOB =
+ watcher.onDidChange(onFileChange)
'use strict'
-const CONFIG_GLOB =
+ watcher.onDidChange(onFileChange)
+ items?
+ languages?: string[]
+ regex?: RegExp
+ triggerCharacters?: string[]
+ config?
+ watcher.onDidChange(onFileChange)
const CONFIG_GLOB =
import * as vscode from 'vscode'
+ regex: RegExp,
+ emmet?: boolean
+} = {}): vscode.Disposable {
return vscode.languages.registerCompletionItemProvider(
languages,
{
@@ -131,24 +141,42 @@ const separator = config.options.separator || ':'
let str
const range: vscode.Range = new vscode.Range(
- new vscode.Position(Math.max(position.line - 5, 0), 0),
+ new vscode.Position(0, 0),
position
)
const text: string = document.getText(range)
- '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
+ if (!enable(text)) return []
+
+ let lines = text.split(/[\n\r]/)
+
+ let matches = lines
+ .slice(-5)
+ .join('\n')
+ watcher.onDidCreate(onFileChange)
const CONFIG_GLOB =
if (matches) {
let parts = matches[matches.length - 1].split(' ')
str = parts[parts.length - 1]
- } else if (languages.indexOf('html') !== -1) {
+ } else if (emmet) {
// match emmet style syntax
// e.g. .flex.items-center
+ let currentLine = lines[lines.length - 1]
+ watcher.onDidDelete(onFileChange)
'use strict'
+ matches = currentWord.match(/^\.([^.()#>*^ \[\]=$@{}]*)$/)
+ if (!matches) {
+ matches = currentWord.match(
+ watcher.onDidDelete(onFileChange)
const tailwindClassNames = require('tailwind-class-names')
+ `^([A-Z][a-zA-Z0-9]*|[a-z][a-z0-9]*-[a-z0-9-]+|${htmlElements.join(
+ '|'
+ )}).*?\\.([^.()#>*^ \\[\\]=$@{}]*)$`
+ )
+ )
+'use strict'
const JS_TYPES = ['typescriptreact', 'javascript', 'javascriptreact']
-const dlv = require('dlv')
if (matches) {
let parts = matches[matches.length - 1].split('.')
str = parts[parts.length - 1]
@@ -182,6 +211,59 @@ ...triggerCharacters
)
}
+function createConfigItemProvider({
+ languages,
+ items,
+ enable = () => true
+}: {
+ languages?: string[]
+ items?: vscode.CompletionItem[]
+ enable?: (text: string) => boolean
+} = {}) {
+ return vscode.languages.registerCompletionItemProvider(
+ languages,
+ {
+ provideCompletionItems: (
+ document: vscode.TextDocument,
+ position: vscode.Position
+ ): vscode.CompletionItem[] => {
+ const range: vscode.Range = new vscode.Range(
+ new vscode.Position(0, 0),
+ position
+ )
+ const text: string = document.getText(range)
+
+ if (!enable(text)) return []
+
+ let lines = text.split(/[\n\r]/)
+
+ let matches = lines
+ .slice(-5)
+ .join('\n')
+ .match(/config\(["']([^"']*)$/)
+
+ if (!matches) return []
+
+ let objPath =
+ matches[1]
+ .replace(/\.[^.]*$/, '')
+ .replace('.', '.children.')
+ .trim() + '.children'
+ let foo = dlv(items, objPath)
+
+ if (foo) {
+ return Object.keys(foo).map(x => foo[x].item)
+ }
+
+ return Object.keys(items).map(x => items[x].item)
+ }
+ },
+ "'",
+ '"',
+ '.'
+ )
+}
+
function prefixItems(items, str, prefix) {
const addPrefix =
typeof prefix !== 'undefined' && prefix !== '' && str === prefix
@@ -276,8 +358,8 @@
return items
}
+import { join, dirname } from 'path'
'markdown',
-'use strict'
let items = {}
let i = 0
@@ -290,7 +372,7 @@
if (depthOf(config[key]) === 0) {
if (key === 'plugins') return
- item.filterText = item.insertText = `.${key}`
+ item.filterText = item.insertText = `${prefix}${key}`
item.sortText = naturalExpand(i.toString())
if (typeof config[key] === 'string' || typeof config[key] === 'number') {
item.detail = config[key]
@@ -310,8 +392,9 @@
item.filterText = item.insertText = `${key}.`
item.sortText = naturalExpand(i.toString())
item.command = { title: '', command: 'editor.action.triggerSuggest' }
+import { join, dirname } from 'path'
-const CONFIG_GLOB =
+'use strict'
}
i++
@@ -326,6 +409,7 @@ private _disposable: vscode.Disposable
private _tailwind
private _items
private _configItems
+ private _prefixedConfigItems
constructor(tailwind) {
if (tailwind) {
@@ -343,307 +427,416 @@ if (separator !== ':') return
this._items = createItems(tailwind.classNames, separator, tailwind.config)
this._configItems = createConfigItems(tailwind.config)
+ this._prefixedConfigItems = createConfigItems(tailwind.config, '.')
this._providers = []
this._providers.push(
+import { join, dirname } from 'path'
+import { join, dirname } from 'path'
+ items: this._items,
+ languages: JS_TYPES,
+ regex: /\btw`([^`]*)$/,
+import { join, dirname } from 'path'
const CSS_TYPES = ['css', 'sass', 'scss', 'less', 'postcss', 'stylus']
+import { join, dirname } from 'path'
+ '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
+import * as vscode from 'vscode'
+const CONFIG_GLOB =
+'use strict'
'**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
+const dlv = require('dlv')
+
+]
+ createCompletionItemProvider({
+ items: this._items,
+import { join, dirname } from 'path'
let tw
-
+import { join, dirname } from 'path'
try {
-
+import { join, dirname } from 'path'
tw = await getTailwind()
-
+import { join, dirname } from 'path'
} catch (err) {}
- 'php',
+ prefix: '.'
+ tw = await getTailwind()
const CONFIG_GLOB =
)
this._providers.push(
+import { join, dirname } from 'path'
-const CSS_TYPES = ['css', 'sass', 'scss', 'less', 'postcss', 'stylus']
+import { join, dirname } from 'path'
-
+import { join, dirname } from 'path'
- '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
+const tailwindClassNames = require('tailwind-class-names')
- 'nunjucks',
import { join, dirname } from 'path'
-
context.subscriptions.push(intellisense)
-
+import { join, dirname } from 'path'
let watcher = vscode.workspace.createFileSystemWatcher(CONFIG_GLOB)
-
+import { join, dirname } from 'path'
watcher.onDidChange(onFileChange)
-
+ config: tailwind.config,
+import { join, dirname } from 'path'
watcher.onDidCreate(onFileChange)
- 'php',
+ tw = await getTailwind()
const CONFIG_GLOB =
)
this._providers.push(
+import { join, dirname } from 'path'
+import { join, dirname } from 'path'
+import { join, dirname } from 'path'
-const CONFIG_GLOB =
+const tailwindClassNames = require('tailwind-class-names')
+import { join, dirname } from 'path'
-export async function activate(context: vscode.ExtensionContext) {
+const dlv = require('dlv')
-
+import { join, dirname } from 'path'
watcher.onDidDelete(onFileChange)
-
+import { join, dirname } from 'path'
async function onFileChange(event) {
-
+import { join, dirname } from 'path'
try {
+ intellisense.dispose()
+ vscode.workspace.getConfiguration('emmet.includeLanguages')
+ ).indexOf('javascript') !== -1 && '.'
+ ])
+ .filter(Boolean),
+import { join, dirname } from 'path'
} catch (err) {}
-'use strict'
+ emmet:
+ Object.keys(
+ vscode.workspace.getConfiguration('emmet.includeLanguages')
+import { join, dirname } from 'path'
const tailwindClassNames = require('tailwind-class-names')
+ tw = await getTailwind()
const CONFIG_GLOB =
)
+ // Vue.js
this._providers.push(
-
tw = await getTailwind()
+import { join, dirname } from 'path'
+import { join, dirname } from 'path'
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
import { join, dirname } from 'path'
+ if (!vscode.workspace.name) return
-
import { join, dirname } from 'path'
+const tailwindClassNames = require('tailwind-class-names')
import * as vscode from 'vscode'
-
import { join, dirname } from 'path'
+const tailwindClassNames = require('tailwind-class-names')
import { join, dirname } from 'path'
-
import { join, dirname } from 'path'
+const tailwindClassNames = require('tailwind-class-names')
const tailwindClassNames = require('tailwind-class-names')
-
import { join, dirname } from 'path'
+const tailwindClassNames = require('tailwind-class-names')
const dlv = require('dlv')
-
import { join, dirname } from 'path'
+const tailwindClassNames = require('tailwind-class-names')
const Color = require('color')
-
import { join, dirname } from 'path'
+const tailwindClassNames = require('tailwind-class-names')
const CONFIG_GLOB =
-
import { join, dirname } from 'path'
+const tailwindClassNames = require('tailwind-class-names')
'**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
- // for jsx
+ }
+ }
-const tailwindClassNames = require('tailwind-class-names')
+ tw = await tailwindClassNames({
+ triggerCharacters: ["'", '"', ' ', separator]
+ intellisense.dispose()
'use strict'
+ intellisense.dispose()
+ vscode.workspace.getConfiguration('emmet.includeLanguages')
+ ).indexOf('vue-html') !== -1 && '.'
+ intellisense.dispose()
const tailwindClassNames = require('tailwind-class-names')
+ .filter(Boolean),
+ config: tailwind.config,
+ emmet:
+ Object.keys(
+ vscode.workspace.getConfiguration('emmet.includeLanguages')
+ }
+import * as vscode from 'vscode'
+const CONFIG_GLOB =
- let matches = text.match(/config\(["']([^"']*)$/)
+ )
+]
+import { join, dirname } from 'path'
-const tailwindClassNames = require('tailwind-class-names')
import { join, dirname } from 'path'
+import { join, dirname } from 'path'
+const tailwindClassNames = require('tailwind-class-names')
+ return
+import { join, dirname } from 'path'
const tailwindClassNames = require('tailwind-class-names')
+import * as vscode from 'vscode'
+import { join, dirname } from 'path'
const tailwindClassNames = require('tailwind-class-names')
+import { join, dirname } from 'path'
-
+ return
const tailwindClassNames = require('tailwind-class-names')
+import { join, dirname } from 'path'
const dlv = require('dlv')
+import * as vscode from 'vscode'
- .replace(/\.[^.]*$/, '')
+ text.indexOf('</script>') === -1
-
+import { join, dirname } from 'path'
if (!files.length) return null
-
+import { join, dirname } from 'path'
let configPath = files[0].fsPath
-
+ }
+import { join, dirname } from 'path'
delete require.cache[configPath]
+ tw = await tailwindClassNames({
-
+import { join, dirname } from 'path'
const dlv = require('dlv')
-'use strict'
+const tailwindClassNames = require('tailwind-class-names')
+import { join, dirname } from 'path'
-const dlv = require('dlv')
+ '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
+import * as vscode from 'vscode'
+const CONFIG_GLOB =
-
+ 'markdown',
const dlv = require('dlv')
-import * as vscode from 'vscode'
-'use strict'
'ejs',
+const Color = require('color')
+import { join, dirname } from 'path'
+import { join, dirname } from 'path'
+import { join, dirname } from 'path'
-const dlv = require('dlv')
+const tailwindClassNames = require('tailwind-class-names')
import { join, dirname } from 'path'
+ if (!vscode.workspace.name) return
+ regex: /@apply ([^;}]*)$/,
+ } catch (err) {
+ config: tailwind.config,
+ enable: text => {
+ if (
+ text.indexOf('<style') !== -1 &&
+import { join, dirname } from 'path'
const dlv = require('dlv')
+const Color = require('color')
+import { join, dirname } from 'path'
const tailwindClassNames = require('tailwind-class-names')
+const CONFIG_GLOB =
-
+import { join, dirname } from 'path'
const tailwindClassNames = require('tailwind-class-names')
+ '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
+'use strict'
'use strict'
+ return false
+'use strict'
const HTML_TYPES = [
+import * as vscode from 'vscode'
+const CONFIG_GLOB =
+ 'markdown',
const dlv = require('dlv')
-const dlv = require('dlv')
+
-const dlv = require('dlv')
+
const Color = require('color')
-
+import { join, dirname } from 'path'
pluginPath,
-
+import { join, dirname } from 'path'
import * as vscode from 'vscode'
-const CONFIG_GLOB =
- 'php',
+ items: this._prefixedConfigItems
+ tw = await getTailwind()
const CONFIG_GLOB =
)
this._providers.push(
-
+import { join, dirname } from 'path'
const dlv = require('dlv')
- '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
+const CONFIG_GLOB =
+ return
+import { join, dirname } from 'path'
strings: true
-
+ enable: text => {
+ if (
+ text.indexOf('<style') !== -1 &&
+ }
const Color = require('color')
+ ) {
+ return true
'use strict'
+const JS_TYPES = ['typescriptreact', 'javascript', 'javascriptreact']
+ return false
+ }
+import * as vscode from 'vscode'
-const Color = require('color')
+const CONFIG_GLOB =
+ )
+
const Color = require('color')
-import * as vscode from 'vscode'
+ if (!tw) {
'use strict'
- let pluginPath = dirname(tailwindPackage[0].fsPath)
+ if (!tw) {
+ {
+ provideHover: (document, position, token) => {
+import { join, dirname } from 'path'
return tw
+ }
+}
+ )
+import { join, dirname } from 'path'
export function deactivate() {}
-
+import { join, dirname } from 'path'
function createCompletionItemProvider(
-]
-
+import { join, dirname } from 'path'
items,
- )
+ new vscode.Position(Math.max(position.line - 5, 0), 0),
-
+import { join, dirname } from 'path'
languages: string[],
+async function getTailwind() {
-
+import { join, dirname } from 'path'
regex: RegExp,
+import { join, dirname } from 'path'
triggerCharacters: string[],
-
-
+import { join, dirname } from 'path'
config,
+import { join, dirname } from 'path'
prefix = ''
-
+import { join, dirname } from 'path'
): vscode.Disposable {
-
-
+import { join, dirname } from 'path'
return vscode.languages.registerCompletionItemProvider(
+import { join, dirname } from 'path'
languages,
-
+import { join, dirname } from 'path'
{
-
-
+import { join, dirname } from 'path'
provideCompletionItems(
+import { join, dirname } from 'path'
document: vscode.TextDocument,
-
+import { join, dirname } from 'path'
position: vscode.Position
-
+import { join, dirname } from 'path'
): vscode.CompletionItem[] {
-
+import { join, dirname } from 'path'
const separator = config.options.separator || ':'
-
+import { join, dirname } from 'path'
let str
-
+import { join, dirname } from 'path'
const range: vscode.Range = new vscode.Range(
-
+import { join, dirname } from 'path'
new vscode.Position(Math.max(position.line - 5, 0), 0),
-
+import { join, dirname } from 'path'
position
-
+ }
+import { join, dirname } from 'path'
)
-
+import { join, dirname } from 'path'
const text: string = document.getText(range)
-
+import { join, dirname } from 'path'
let matches = text.match(regex)
-
+import { join, dirname } from 'path'
if (matches) {
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
+ css = m[2].trim()
import * as vscode from 'vscode'
+'use strict'
'use strict'
-export async function activate(context: vscode.ExtensionContext) {
const tailwindClassNames = require('tailwind-class-names')
-import * as vscode from 'vscode'
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
import * as vscode from 'vscode'
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
import { join, dirname } from 'path'
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
const tailwindClassNames = require('tailwind-class-names')
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
const dlv = require('dlv')
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
const Color = require('color')
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
const CONFIG_GLOB =
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
const JS_TYPES = ['typescriptreact', 'javascript', 'javascriptreact']
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
const HTML_TYPES = [
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'html',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'jade',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'razor',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'php',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'blade',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'vue',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'twig',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'markdown',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'erb',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'handlebars',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'ejs',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'blade',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'vue',
-import * as vscode from 'vscode'
+const tailwindClassNames = require('tailwind-class-names')
'nunjucks',
+ )
)
-import * as vscode from 'vscode'
+
+const tailwindClassNames = require('tailwind-class-names')
// for jsx
+ position
-import * as vscode from 'vscode'
+ 'html',
-const dlv = require('dlv')
-'use strict'
+const tailwindClassNames = require('tailwind-class-names')
+const dlv = require('dlv')
}
-
- return null
}
- tw = await getTailwind()
+ 'php',
const CONFIG_GLOB =
)
diff --git a/src/htmlElements.ts b/src/htmlElements.ts
new file mode 100644
index 0000000000000000000000000000000000000000..4bb7b1c1220b17799c08d5b923dd5e8ac0e4f280
--- /dev/null
+++ b/src/htmlElements.ts
@@ -0,0 +1,142 @@
+module.exports = [
+ 'a',
+ 'abbr',
+ 'acronym',
+ 'address',
+ 'applet',
+ 'area',
+ 'article',
+ 'aside',
+ 'audio',
+ 'b',
+ 'base',
+ 'basefont',
+ 'bdi',
+ 'bdo',
+ 'bgsound',
+ 'big',
+ 'blink',
+ 'blockquote',
+ 'body',
+ 'br',
+ 'button',
+ 'canvas',
+ 'caption',
+ 'center',
+ 'cite',
+ 'code',
+ 'col',
+ 'colgroup',
+ 'command',
+ 'content',
+ 'data',
+ 'datalist',
+ 'dd',
+ 'del',
+ 'details',
+ 'dfn',
+ 'dialog',
+ 'dir',
+ 'div',
+ 'dl',
+ 'dt',
+ 'element',
+ 'em',
+ 'embed',
+ 'fieldset',
+ 'figcaption',
+ 'figure',
+ 'font',
+ 'footer',
+ 'form',
+ 'frame',
+ 'frameset',
+ 'h1',
+ 'head',
+ 'header',
+ 'hgroup',
+ 'hr',
+ 'html',
+ 'i',
+ 'iframe',
+ 'image',
+ 'img',
+ 'input',
+ 'ins',
+ 'isindex',
+ 'kbd',
+ 'keygen',
+ 'label',
+ 'legend',
+ 'li',
+ 'link',
+ 'listing',
+ 'main',
+ 'map',
+ 'mark',
+ 'marquee',
+ 'menu',
+ 'menuitem',
+ 'meta',
+ 'meter',
+ 'multicol',
+ 'nav',
+ 'nextid',
+ 'nobr',
+ 'noembed',
+ 'noframes',
+ 'noscript',
+ 'object',
+ 'ol',
+ 'optgroup',
+ 'option',
+ 'output',
+ 'p',
+ 'param',
+ 'picture',
+ 'plaintext',
+ 'pre',
+ 'progress',
+ 'q',
+ 'rb',
+ 'rp',
+ 'rt',
+ 'rtc',
+ 'ruby',
+ 's',
+ 'samp',
+ 'script',
+ 'section',
+ 'select',
+ 'shadow',
+ 'slot',
+ 'small',
+ 'source',
+ 'spacer',
+ 'span',
+ 'strike',
+ 'strong',
+ 'style',
+ 'sub',
+ 'summary',
+ 'sup',
+ 'table',
+ 'tbody',
+ 'td',
+ 'template',
+ 'textarea',
+ 'tfoot',
+ 'th',
+ 'thead',
+ 'time',
+ 'title',
+ 'tr',
+ 'track',
+ 'tt',
+ 'u',
+ 'ul',
+ 'var',
+ 'video',
+ 'wbr',
+ 'xmp'
+]