Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
improve postcss
Brad Cornes <bradlc41@gmail.com>
6 years ago
1 changed files, 42 additions(+), 9 deletions(-)
src/extension.ts
M src/extension.tssrc/extension.ts
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
diff --git a/src/extension.ts b/src/extension.ts
index ca54c38dc180e8240640ee2a0af5e80d911af0a0..2601445166499b800b0a3b452dfcd5b63d73cde5 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -24,7 +24,7 @@   'ejs',
   'nunjucks',
   'haml'
 ]
-const CSS_TYPES = ['css', 'sass', 'scss', 'less', 'postcss', 'stylus']
+const CSS_TYPES = ['css', 'sass', 'scss', 'less', 'stylus']
 
 export async function activate(context: vscode.ExtensionContext) {
   let tw
@@ -103,15 +103,16 @@ export function deactivate() {}
 
 function createCompletionItemProvider({
   items,
+  prefixedItems,
   languages,
   regex,
   triggerCharacters,
   config,
-  prefix = '',
   enable = () => true,
   emmet = false
 }: {
   items?
+  prefixedItems?
   languages?: string[]
   regex?: RegExp
   triggerCharacters?: string[]
@@ -177,14 +178,21 @@             .replace(/^\./, '')
             .replace(/\./g, '.children.')
 
           if (pth !== '') {
-            const itms = dlv(items, pth)
+            const itms =
+              prefixedItems &&
+              str.indexOf('.') === 0 &&
+              str.indexOf(separator) === -1
+                ? dlv(prefixedItems, pth)
+                : dlv(items, pth)
             if (itms) {
-              return prefixItems(itms.children, str, prefix)
+              return Object.keys(itms.children).map(x => itms.children[x].item)
             }
           }
 
           if (str.indexOf(separator) === -1) {
-            return prefixItems(items, str, prefix)
+            return prefixedItems && str.indexOf('.') === 0
+              ? Object.keys(prefixedItems).map(x => prefixedItems[x].item)
+              : Object.keys(items).map(x => items[x].item)
           }
 
           return []
@@ -282,7 +290,7 @@
   return level
 }
 
-function createItems(classNames, separator, config, parent = '') {
+function createItems(classNames, separator, config, prefix = '', parent = '') {
   let items = {}
   let i = 0
 
@@ -292,6 +300,7 @@       const item = new vscode.CompletionItem(
         key,
         vscode.CompletionItemKind.Constant
       )
+      item.filterText = item.insertText = `${prefix}${key}`
       item.sortText = naturalExpand(i.toString())
       if (key !== 'container' && key !== 'group') {
         if (parent) {
@@ -318,6 +327,7 @@       const item = new vscode.CompletionItem(
         `${key}${separator}`,
         vscode.CompletionItemKind.Constant
       )
+      item.filterText = item.insertText = `${prefix}${key}${separator}`
       item.sortText = naturalExpand(i.toString())
       item.command = { title: '', command: 'editor.action.triggerSuggest' }
       if (key === 'hover' || key === 'focus' || key === 'active') {
@@ -335,7 +345,7 @@         item.sortText = `m${item.sortText}`
       }
       items[key] = {
         item,
-        children: createItems(classNames[key], separator, config, key)
+        children: createItems(classNames[key], separator, config, prefix, key)
       }
       i++
     }
@@ -391,6 +401,7 @@   private _providers: vscode.Disposable[]
   private _disposable: vscode.Disposable
   private _tailwind
   private _items
+  private _prefixedItems
   private _configItems
   private _prefixedConfigItems
 
@@ -409,6 +420,12 @@
     if (separator !== ':') return
 
     this._items = createItems(tailwind.classNames, separator, tailwind.config)
+    this._prefixedItems = createItems(
+      tailwind.classNames,
+      separator,
+      tailwind.config,
+      '.'
+    )
     this._configItems = createConfigItems(tailwind.config)
     this._prefixedConfigItems = createConfigItems(tailwind.config, '.')
 
@@ -427,11 +444,21 @@
     this._providers.push(
       createCompletionItemProvider({
         items: this._items,
+        prefixedItems: this._prefixedItems,
         languages: CSS_TYPES,
         regex: /@apply ([^;}]*)$/,
         triggerCharacters: ['.', separator],
-        config: tailwind.config,
-        prefix: '.'
+        config: tailwind.config
+      })
+    )
+    this._providers.push(
+      createCompletionItemProvider({
+        items: this._items,
+        prefixedItems: this._items,
+        languages: ['postcss'],
+        regex: /@apply ([^;}]*)$/,
+        triggerCharacters: ['.', separator],
+        config: tailwind.config
       })
     )
 
@@ -536,6 +563,12 @@     this._providers.push(
       createConfigItemProvider({
         languages: CSS_TYPES,
         items: this._prefixedConfigItems
+      })
+    )
+    this._providers.push(
+      createConfigItemProvider({
+        languages: ['postcss'],
+        items: this._configItems
       })
     )