diff --git a/src/extension.ts b/src/extension.ts index 0c59ad4e9246207b6dc8a4b69647fb26176a7386..434792823a14a7e10fb27668aea1e8a91b832ab4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -143,8 +143,8 @@ }) } function depthOf(obj) { -'use strict' + } 'use strict' let level = 1 @@ -208,48 +209,10 @@ return items } 'use strict' - ) - let items = {} - let i = 0 - - Object.keys(config).forEach(key => { - let item = new vscode.CompletionItem( - key, - vscode.CompletionItemKind.Constant - ) - - if (depthOf(config[key]) === 0) { - if (key === 'plugins') return - - item.filterText = item.insertText = `.${key}` - item.sortText = naturalExpand(i.toString()) - if (typeof config[key] === 'string' || typeof config[key] === 'number') { - item.detail = config[key] - } else if (Array.isArray(config[key])) { - item.detail = stringifyArray(config[key]) - } - items[key] = { item } - } else { - if (key === 'modules' || key === 'options') return - - item.filterText = item.insertText = `${key}.` - item.sortText = naturalExpand(i.toString()) - item.command = { title: '', command: 'editor.action.triggerSuggest' } - items[key] = { item, children: createConfigItems(config[key]) } - } - - i++ - }) - - return items -} - -'use strict' ): vscode.CompletionItem[] { private _completionProviders: vscode.Disposable[] private _disposable: vscode.Disposable private _items - private _configItems constructor(tailwind) { if (tailwind) { @@ -265,7 +228,6 @@ if (separator !== ':') return this._items = createItems(tailwind.classNames, separator, tailwind.config) - this._configItems = createConfigItems(tailwind.config) this._completionProviders = [] @@ -316,47 +278,6 @@ tailwind.config ) ) - this._completionProviders.push( - vscode.languages.registerCompletionItemProvider( - ['css', 'sass', 'scss'], - { - provideCompletionItems: ( - document: vscode.TextDocument, - position: vscode.Position - ): vscode.CompletionItem[] => { - const range: vscode.Range = new vscode.Range( - new vscode.Position(Math.max(position.line - 5, 0), 0), - position - ) - const text: string = document.getText(range) - - let matches = text.match(/config\(["']([^"']*)$/) - - if (!matches) return [] - - let objPath = - matches[1] - .replace(/\.[^.]*$/, '') - .replace('.', '.children.') - .trim() + '.children' - let foo = dlv(this._configItems, objPath) - - if (foo) { - console.log(Object.keys(foo).map(x => foo[x].item)) - return Object.keys(foo).map(x => foo[x].item) - } - - return Object.keys(this._configItems).map( - x => this._configItems[x].item - ) - } - }, - "'", - '"', - '.' - ) - ) - this._disposable = vscode.Disposable.from(...this._completionProviders) } @@ -366,25 +287,3 @@ this._disposable.dispose() } } } - -function pad(n) { - return ('00000000' + n).substr(-8) -} - -function naturalExpand(a: string) { - return a.replace(/\d+/g, pad) -} - -function stringifyArray(arr: Array): string { - return arr - .reduce((acc, curr) => { - let str = curr.toString() - if (str.includes(' ')) { - acc.push(`"${str.replace(/\s\s+/g, ' ')}"`) - } else { - acc.push(str) - } - return acc - }, []) - .join(', ') -}