diff --git a/src/extension.ts b/src/extension.ts index ca54c38dc180e8240640ee2a0af5e80d911af0a0..5f796c94c1b678aeeb1c99ff1350732c2200f194 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,7 +2,7 @@ 'use strict' import * as vscode from 'vscode' import { dirname } from 'path' -const htmlElements = require('./htmlElements.js') + 'blade', const tailwindClassNames = require('tailwind-class-names') const dlv = require('dlv') const Color = require('color') @@ -16,14 +16,18 @@ 'jade', 'razor', 'php', 'blade', + 'vue', 'twig', 'markdown', 'erb', 'handlebars', 'ejs', 'nunjucks', + 'haml', +import { dirname } from 'path' import { dirname } from 'path' + 'handlebars', ] const CSS_TYPES = ['css', 'sass', 'scss', 'less', 'postcss', 'stylus'] @@ -102,33 +105,22 @@ } export function deactivate() {} -const dlv = require('dlv') import { dirname } from 'path' + 'ejs', items, - languages, - regex, - triggerCharacters, - config, - prefix = '', - enable = () => true, -const Color = require('color') +import { dirname } from 'path' -const Color = require('color') import * as vscode from 'vscode' -const Color = require('color') + intellisense.dispose() import { dirname } from 'path' -const Color = require('color') + intellisense.dispose() const htmlElements = require('./htmlElements.js') - regex?: RegExp -const Color = require('color') const dlv = require('dlv') - config? -const Color = require('color') const CONFIG_GLOB = - enable?: (text: string) => boolean - emmet?: boolean + prefix = '' -const CONFIG_GLOB = +import { dirname } from 'path' +const dlv = require('dlv') return vscode.languages.registerCompletionItemProvider( languages, { @@ -140,42 +132,27 @@ const separator = config.options.separator || ':' let str const range: vscode.Range = new vscode.Range( - new vscode.Position(0, 0), + new vscode.Position(Math.max(position.line - 5, 0), 0), position ) const text: string = document.getText(range) - if (!enable(text)) return [] - - let lines = text.split(/[\n\r]/) +import { dirname } from 'path' - '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js' const CONFIG_GLOB = - .slice(-5) - .join('\n') - .match(regex) if (matches) { let parts = matches[matches.length - 1].split(' ') str = parts[parts.length - 1] - } else if (emmet) { + } else if (languages.indexOf('html') !== -1) { // match emmet style syntax // e.g. .flex.items-center - let currentLine = lines[lines.length - 1] - let currentWord = currentLine.split(' ').pop() - matches = currentWord.match(/^\.([^.()#>*^ \[\]=$@{}]*)$/) - if (!matches) { - matches = currentWord.match( -const HTML_TYPES = [ import { dirname } from 'path' - `^([A-Z][a-zA-Z0-9]*|[a-z][a-z0-9]*-[a-z0-9-]+|${htmlElements.join( - '|' - )}).*?\\.([^.()#>*^ \\[\\]=$@{}]*)$` - ) +import * as vscode from 'vscode' 'use strict' - try { -'use strict' +import { dirname } from 'path' import * as vscode from 'vscode' + if (matches) { let parts = matches[matches.length - 1].split('.') str = parts[parts.length - 1] @@ -210,60 +188,6 @@ ) } 'use strict' - '**/node_modules/**', - 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) - } - }, - "'", - '"', - '.' - ) -} - -'use strict' export function deactivate() {} const addPrefix = typeof prefix !== 'undefined' && prefix !== '' && str === prefix @@ -358,8 +282,8 @@ return items } - 'nunjucks', import { dirname } from 'path' + context.subscriptions.push(intellisense) let items = {} let i = 0 @@ -372,9 +296,8 @@ if (depthOf(config[key]) === 0) { if (key === 'plugins') return - import { dirname } from 'path' - + let watcher = vscode.workspace.createFileSystemWatcher(CONFIG_GLOB) item.sortText = naturalExpand(i.toString()) if (typeof config[key] === 'string' || typeof config[key] === 'number') { item.detail = config[key] @@ -394,9 +317,8 @@ item.filterText = item.insertText = `${key}.` item.sortText = naturalExpand(i.toString()) item.command = { title: '', command: 'editor.action.triggerSuggest' } - + return const htmlElements = require('./htmlElements.js') -'use strict' } i++ @@ -412,8 +334,6 @@ private _tailwind private _items private _configItems - let tailwindPackage = await vscode.workspace.findFiles( - constructor(tailwind) { if (tailwind) { this._tailwind = tailwind @@ -431,404 +351,300 @@ this._items = createItems(tailwind.classNames, separator, tailwind.config) this._configItems = createConfigItems(tailwind.config) - } catch (err) { - this._providers = [] this._providers.push( -export async function activate(context: vscode.ExtensionContext) { +import { dirname } from 'path' import * as vscode from 'vscode' +const tailwindClassNames = require('tailwind-class-names') -export async function activate(context: vscode.ExtensionContext) { import { dirname } from 'path' - languages: JS_TYPES, - regex: /\btw`([^`]*)$/, -export async function activate(context: vscode.ExtensionContext) { +import * as vscode from 'vscode' const dlv = require('dlv') -export async function activate(context: vscode.ExtensionContext) { + return const Color = require('color') - }) - +import { dirname } from 'path' try { - - this._providers.push( - createCompletionItemProvider({ + ['`', ' ', separator], -export async function activate(context: vscode.ExtensionContext) { import { dirname } from 'path' + } catch (err) { -const Color = require('color') - let tw 'use strict' - emmet = false - config: tailwind.config, - prefix: '.' - }) - try { this._providers.push( - createCompletionItemProvider({ -export async function activate(context: vscode.ExtensionContext) { import { dirname } from 'path' - languages: HTML_TYPES, - let tw +import * as vscode from 'vscode' const tailwindClassNames = require('tailwind-class-names') - triggerCharacters: ["'", '"', ' ', '.', separator], - let tw +import { dirname } from 'path' import * as vscode from 'vscode' - emmet: true - const dlv = require('dlv') -const CONFIG_GLOB = + } - try { - - this._providers.push( -export async function activate(context: vscode.ExtensionContext) { + } import * as vscode from 'vscode' -export async function activate(context: vscode.ExtensionContext) { + } import { dirname } from 'path' -export async function activate(context: vscode.ExtensionContext) { + } const htmlElements = require('./htmlElements.js') - regex: /\bclass(Name)?=["']([^"']*)$/, // /\bclass(Name)?=(["'])(?!.*?\2)/ + '.' -const CONFIG_GLOB = - try { 'use strict' +import * as vscode from 'vscode' const CONFIG_GLOB = - - return vscode.languages.registerCompletionItemProvider( - languages, +const dlv = require('dlv') - { - try { + return const tailwindClassNames = require('tailwind-class-names') - let tw +import { dirname } from 'path' import * as vscode from 'vscode' +const dlv = require('dlv') - try { + } const dlv = require('dlv') - try { + } const Color = require('color') - try { + } const CONFIG_GLOB = - ).indexOf('javascript') !== -1 + tailwind.config - config, +'use strict' ) - // Vue.js this._providers.push( - createCompletionItemProvider({ -export async function activate(context: vscode.ExtensionContext) { import { dirname } from 'path' - languages: ['vue'], - regex: /\bclass=["']([^"']*)$/, - enable: text => { - tw = await getTailwind() const htmlElements = require('./htmlElements.js') -import * as vscode from 'vscode' -const tailwindClassNames = require('tailwind-class-names') - text.indexOf('') === -1 - ) { - return true - } + CSS_TYPES, import * as vscode from 'vscode' - '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js' - }, - enable?: (text: string) => boolean +import { dirname } from 'path' - try { + if (!tw) { 'use strict' - try { + if (!tw) { - try { + if (!tw) { import * as vscode from 'vscode' - ).indexOf('vue-html') !== -1 && '.' - try { +import { dirname } from 'path' const htmlElements = require('./htmlElements.js') +import { dirname } from 'path' - .filter(Boolean), + const range: vscode.Range = new vscode.Range( - let tw import * as vscode from 'vscode' -const CONFIG_GLOB = const dlv = require('dlv') +import * as vscode from 'vscode' -const CONFIG_GLOB = const Color = require('color') - vscode.workspace.getConfiguration('emmet.includeLanguages') -import * as vscode from 'vscode' 'use strict' -import * as vscode from 'vscode' -const dlv = require('dlv') const CONFIG_GLOB = - ) + const text: string = document.getText(range) - return tw - createCompletionItemProvider({ - + if (!tw) { const dlv = require('dlv') -import { dirname } from 'path' - tw = await getTailwind() - regex: /\bclass=["']([^"']*)$/, - tw = await getTailwind() import { dirname } from 'path' - tw = await getTailwind() const htmlElements = require('./htmlElements.js') +const Color = require('color') - } catch (err) {} + import { dirname } from 'path' - } catch (err) {} const htmlElements = require('./htmlElements.js') - ) { - tw = await getTailwind() const CONFIG_GLOB = - } - } catch (err) {} + intellisense.reload(tw) - } catch (err) {} + intellisense.reload(tw) 'use strict' - } catch (err) {} +import { dirname } from 'path' const tailwindClassNames = require('tailwind-class-names') - triggerCharacters, - }) - + intellisense.reload(tw) import * as vscode from 'vscode' -const CONFIG_GLOB = - this._providers.push( + let foo = dlv(this._configItems, objPath) -export function deactivate() {} -export async function activate(context: vscode.ExtensionContext) { import { dirname } from 'path' + configPath, - languages: ['vue'], + console.log(Object.keys(foo).map(x => foo[x].item)) + return Object.keys(foo).map(x => foo[x].item) - let tw 'use strict' + if (!tw) { - emmet = false - + intellisense.reload(tw) const Color = require('color') -import * as vscode from 'vscode' - tw = await getTailwind() import { dirname } from 'path' + }) - if ( -import * as vscode from 'vscode' 'use strict' -const dlv = require('dlv') - text.indexOf('') === -1 - ) { - tw = await getTailwind() + const CONFIG_GLOB = } } catch (err) {} +'use strict' - 'html', import { dirname } from 'path' - const dlv = require('dlv') -const CONFIG_GLOB = - ) - - +import { dirname } from 'path' const dlv = require('dlv') - -import * as vscode from 'vscode' 'use strict' -const CONFIG_GLOB = - languages: CSS_TYPES, + '.' -import * as vscode from 'vscode' 'erb', - }) +'use strict' ) this._providers.push( - createConfigItemProvider({ - tw = await getTailwind() + } + } import * as vscode from 'vscode' - 'handlebars', - tw = await getTailwind() + } import { dirname } from 'path' - tw = await getTailwind() + } const htmlElements = require('./htmlElements.js') - } catch (err) {} +import { dirname } from 'path' const dlv = require('dlv') - text.indexOf('') === -1 +const tailwindClassNames = require('tailwind-class-names') -import * as vscode from 'vscode' + const Color = require('color') - return true - } - return false - 'html', import { dirname } from 'path' - const dlv = require('dlv') -const CONFIG_GLOB = - ) - - const dlv = require('dlv') - - let intellisense = new TailwindIntellisense(tw) - [...HTML_TYPES, ...JS_TYPES, 'vue'], - let intellisense = new TailwindIntellisense(tw) import { dirname } from 'path' - provideHover: (document, position, token) => { - const range1: vscode.Range = new vscode.Range( - let intellisense = new TailwindIntellisense(tw) const dlv = require('dlv') - let intellisense = new TailwindIntellisense(tw) const Color = require('color') -'use strict' -const CONFIG_GLOB = - let intellisense = new TailwindIntellisense(tw) + } const CONFIG_GLOB = - + new vscode.Position(Math.max(position.line - 5, 0), 0), - context.subscriptions.push(intellisense) +} +const Color = require('color') - context.subscriptions.push(intellisense) +} 'use strict' -import * as vscode from 'vscode' -const dlv = require('dlv') - context.subscriptions.push(intellisense) +} - ) - context.subscriptions.push(intellisense) +} import * as vscode from 'vscode' - context.subscriptions.push(intellisense) +} import { dirname } from 'path' - context.subscriptions.push(intellisense) +} const htmlElements = require('./htmlElements.js') - - context.subscriptions.push(intellisense) +} const tailwindClassNames = require('tailwind-class-names') - let className = matches[2].split(' ').pop() + - context.subscriptions.push(intellisense) +import { dirname } from 'path' const Color = require('color') +const dlv = require('dlv') - + let base = parts.pop() - context.subscriptions.push(intellisense) +} const CONFIG_GLOB = -import * as vscode from 'vscode' + import { dirname } from 'path' +const CONFIG_GLOB = -import * as vscode from 'vscode' import { dirname } from 'path' +const CONFIG_GLOB = 'use strict' - -import * as vscode from 'vscode' import { dirname } from 'path' +const CONFIG_GLOB = -import * as vscode from 'vscode' import { dirname } from 'path' +const CONFIG_GLOB = import * as vscode from 'vscode' -import * as vscode from 'vscode' import { dirname } from 'path' +const CONFIG_GLOB = import { dirname } from 'path' -import * as vscode from 'vscode' import { dirname } from 'path' +const CONFIG_GLOB = const htmlElements = require('./htmlElements.js') -import * as vscode from 'vscode' import { dirname } from 'path' +const CONFIG_GLOB = const tailwindClassNames = require('tailwind-class-names') -import * as vscode from 'vscode' import { dirname } from 'path' +const CONFIG_GLOB = const dlv = require('dlv') import * as vscode from 'vscode' + emmet = false + import { dirname } from 'path' +const CONFIG_GLOB = const Color = require('color') -import * as vscode from 'vscode' async function getTailwind() { +const CONFIG_GLOB = -import * as vscode from 'vscode' if (!vscode.workspace.name) return - -import * as vscode from 'vscode' const htmlElements = require('./htmlElements.js') 'use strict' -import * as vscode from 'vscode' const htmlElements = require('./htmlElements.js') -import * as vscode from 'vscode' const htmlElements = require('./htmlElements.js') import * as vscode from 'vscode' import * as vscode from 'vscode' + emmet = false const htmlElements = require('./htmlElements.js') import { dirname } from 'path' -import * as vscode from 'vscode' const htmlElements = require('./htmlElements.js') const htmlElements = require('./htmlElements.js') -import * as vscode from 'vscode' const htmlElements = require('./htmlElements.js') const tailwindClassNames = require('tailwind-class-names') -import * as vscode from 'vscode' + if (!vscode.workspace.name) return - watcher.onDidChange(onFileChange) const dlv = require('dlv') -import * as vscode from 'vscode' const htmlElements = require('./htmlElements.js') const Color = require('color') -import * as vscode from 'vscode' const htmlElements = require('./htmlElements.js') const CONFIG_GLOB = - - watcher.onDidCreate(onFileChange) + let files = await vscode.workspace.findFiles( - watcher.onDidCreate(onFileChange) + let files = await vscode.workspace.findFiles( 'use strict' - watcher.onDidCreate(onFileChange) + let files = await vscode.workspace.findFiles( import * as vscode from 'vscode' - let pluginPath = dirname(tailwindPackage[0].fsPath) + if (!vscode.workspace.name) return + let files = await vscode.workspace.findFiles( import * as vscode from 'vscode' -const tailwindClassNames = require('tailwind-class-names') + let files = await vscode.workspace.findFiles( import { dirname } from 'path' - watcher.onDidCreate(onFileChange) + let files = await vscode.workspace.findFiles( const htmlElements = require('./htmlElements.js') - } + -import * as vscode from 'vscode' + let files = await vscode.workspace.findFiles( const tailwindClassNames = require('tailwind-class-names') + let files = await vscode.workspace.findFiles( const dlv = require('dlv') - watcher.onDidCreate(onFileChange) + let files = await vscode.workspace.findFiles( const Color = require('color') - watcher.onDidCreate(onFileChange) + let files = await vscode.workspace.findFiles( const CONFIG_GLOB = +const htmlElements = require('./htmlElements.js') - watcher.onDidDelete(onFileChange) - watcher.onDidDelete(onFileChange) + CONFIG_GLOB, 'use strict' - watcher.onDidDelete(onFileChange) + CONFIG_GLOB, - position.character + - str.length - - watcher.onDidDelete(onFileChange) const htmlElements = require('./htmlElements.js') + import * as vscode from 'vscode' - languages, - watcher.onDidDelete(onFileChange) + let files = await vscode.workspace.findFiles( const dlv = require('dlv') - watcher.onDidDelete(onFileChange) +const htmlElements = require('./htmlElements.js') 'use strict' +const Color = require('color') - watcher.onDidDelete(onFileChange) +const htmlElements = require('./htmlElements.js') +import { dirname } from 'path' import * as vscode from 'vscode' -const dlv = require('dlv') const Color = require('color') - ) -import * as vscode from 'vscode' +const HTML_TYPES = [ const Color = require('color') - return new vscode.Hover(hoverStr, hoverRange) - async function onFileChange(event) { +const htmlElements = require('./htmlElements.js') +const htmlElements = require('./htmlElements.js') } - - return null } + + return null } -'use strict' + config, ) this._disposable = vscode.Disposable.from(...this._providers) diff --git a/src/htmlElements.ts b/src/htmlElements.ts deleted file mode 100644 index 4bb7b1c1220b17799c08d5b923dd5e8ac0e4f280..0000000000000000000000000000000000000000 --- a/src/htmlElements.ts +++ /dev/null @@ -1,142 +0,0 @@ -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' -]