diff --git a/src/extension.ts b/src/extension.ts index 434792823a14a7e10fb27668aea1e8a91b832ab4..106636556df4a168633afcc4e3689b563fe63fd9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,109 +6,144 @@ const tailwindClassNames = require('tailwind-class-names') // const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') const dlv = require('dlv') -const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' +export async function activate(context: vscode.ExtensionContext) { + if (!vscode.workspace.name) return +'use strict' export async function activate(context: vscode.ExtensionContext) { +const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' 'use strict' + const addPrefix = + '**/node_modules/**', + 1 + ) + async function onFileChange(event) { -'use strict' + const plugin = join( + vscode.workspace.workspaceFolders[0].uri.fsPath, +import { join } from 'path' 'use strict' -'use strict' +import { join } from 'path' -'use strict' import * as vscode from 'vscode' +// const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') 'use strict' + + try { import { join } from 'path' +import * as vscode from 'vscode' + async function onFileChange(event) { 'use strict' +import { join } from 'path' const tailwindClassNames = require('tailwind-class-names') - -'use strict' +import { join } from 'path' // const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') - -'use strict' +import { join } from 'path' const dlv = require('dlv') -'use strict' +import { join } from 'path' const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' -'use strict' +import { join } from 'path' export async function activate(context: vscode.ExtensionContext) { - + ) + } catch (err) { async function onFileChange(event) { -'use strict' +const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' import * as vscode from 'vscode' + async function onFileChange(event) { import { join } from 'path' + async function onFileChange(event) { const tailwindClassNames = require('tailwind-class-names') -// const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') +// const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') const dlv = require('dlv') const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' export async function activate(context: vscode.ExtensionContext) { -import * as vscode from 'vscode' +'use strict' -import * as vscode from 'vscode' + try { 'use strict' -import * as vscode from 'vscode' +'use strict' - CONFIG_GLOB, + ) import * as vscode from 'vscode' -import { join } from 'path' +// const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') - 1 + -import * as vscode from 'vscode' + async function onFileChange(event) { // const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') -import * as vscode from 'vscode' + async function onFileChange(event) { const dlv = require('dlv') -import * as vscode from 'vscode' const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' +'use strict' import * as vscode from 'vscode' -export async function activate(context: vscode.ExtensionContext) { + try { import { join } from 'path' + ['.', separator], -import { join } from 'path' + 'use strict' +// const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') -import { join } from 'path' + watcher.onDidChange(onFileChange) + ) ) -'use strict' + +// const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') +const dlv = require('dlv') + items, + 'use strict' +const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' + 'use strict' +export async function activate(context: vscode.ExtensionContext) { -import { join } from 'path' + 'jade', + 'razor', + 'php', + tw = await getTailwind() import * as vscode from 'vscode' -import { join } from 'path' + tw = await getTailwind() import { join } from 'path' -import { join } from 'path' + tw = await getTailwind() const tailwindClassNames = require('tailwind-class-names') -import { join } from 'path' + tw = await getTailwind() // const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') -import { join } from 'path' + tw = await getTailwind() const dlv = require('dlv') -import { join } from 'path' + tw = await getTailwind() const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' -import { join } from 'path' + tw = await getTailwind() export async function activate(context: vscode.ExtensionContext) { -const tailwindClassNames = require('tailwind-class-names') + } catch (err) { -const tailwindClassNames = require('tailwind-class-names') + } catch (err) { 'use strict' + 'javascript', + 'javascriptreact' + ], + } catch (err) { const tailwindClassNames = require('tailwind-class-names') + ) -const CONFIG_GLOB = '{tailwind,tailwind.config,.tailwindrc}.js' +'use strict' const tailwindClassNames = require('tailwind-class-names') import * as vscode from 'vscode' +// const tailwindClassNames = require('/Users/brad/Code/tailwind-class-names/dist') } export function deactivate() {} @@ -218,6 +249,7 @@ items[key] = { item } } else { + console.log(key) const item = new vscode.CompletionItem( `${key}${separator}`, vscode.CompletionItemKind.Constant @@ -242,82 +274,3 @@ }) return items } - -class TailwindIntellisense { - private _completionProviders: vscode.Disposable[] - private _disposable: vscode.Disposable - private _items - - constructor(tailwind) { - if (tailwind) { - this.reload(tailwind) - } - } - - public reload(tailwind) { - this.dispose() - - const separator = dlv(tailwind.config, 'options.separator', ':') - - if (separator !== ':') return - - this._items = createItems(tailwind.classNames, separator, tailwind.config) - - this._completionProviders = [] - - this._completionProviders.push( - createCompletionItemProvider( - this._items, - ['typescriptreact', 'javascript', 'javascriptreact'], - /\btw`([^`]*)$/, - ['`', ' ', separator], - tailwind.config - ) - ) - - this._completionProviders.push( - createCompletionItemProvider( - this._items, - ['css', 'sass', 'scss'], - /@apply ([^;}]*)$/, - ['.', separator], - tailwind.config, - '.' - ) - ) - - this._completionProviders.push( - createCompletionItemProvider( - this._items, - [ - 'html', - 'jade', - 'razor', - 'php', - 'blade', - 'vue', - 'twig', - 'markdown', - 'erb', - 'handlebars', - 'ejs', - // for jsx - 'typescriptreact', - 'javascript', - 'javascriptreact' - ], - /\bclass(Name)?=["']([^"']*)/, // /\bclass(Name)?=(["'])(?!.*?\2)/ - ["'", '"', ' ', separator], - tailwind.config - ) - ) - - this._disposable = vscode.Disposable.from(...this._completionProviders) - } - - dispose() { - if (this._disposable) { - this._disposable.dispose() - } - } -}