Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add .vue @apply support (#4)
Brad Cornes <bradlc41@gmail.com>
6 years ago
1 changed files, 92 additions(+), 34 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
diff --git a/src/extension.ts b/src/extension.ts
index fd552df0330b3610650c27f8cfbc485a0fb6f18f..59d0b2938c501c6cab4b1d255e6aff7f63943e99 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -15,7 +15,6 @@   'jade',
   'razor',
   'php',
   'blade',
-  'vue',
   'twig',
   'markdown',
   'erb',
@@ -97,14 +96,25 @@ }
 
 export function deactivate() {}
 
-function createCompletionItemProvider(
+function createCompletionItemProvider({
   items,
-  languages: string[],
-  regex: RegExp,
-  triggerCharacters: string[],
+  languages,
+  regex,
+  triggerCharacters,
   config,
-  prefix = ''
-): vscode.Disposable {
+  prefix = '',
+  enable = () => true,
+  emmet = false
+}: {
+  items?
+  languages?: string[]
+  regex?: RegExp
+  triggerCharacters?: string[]
+  config?
+  prefix?: string
+  enable?: (text: string) => boolean
+  emmet?: boolean
+} = {}): vscode.Disposable {
   return vscode.languages.registerCompletionItemProvider(
     languages,
     {
@@ -116,21 +126,28 @@         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)
 
-        let matches = text.match(regex)
+        if (!enable(text)) return []
+
+        let lines = text.split(/[\n\r]/)
+
+        let matches = lines
+          .slice(-5)
+          .join('\n')
+          .match(regex)
 
         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 lineText = text.split('\n').pop()
-          matches = lineText.match(/\.([^()#>*^ \[\]=$@{}]*)$/i)
+          let currentLine = lines[lines.length - 1]
+          matches = currentLine.match(/\.([^()#>*^ \[\]=$@{}]*)$/i)
           let parts = matches[matches.length - 1].split('.')
           str = parts[parts.length - 1]
         }
@@ -326,34 +343,75 @@
     this._providers = []
 
     this._providers.push(
-      createCompletionItemProvider(
-        this._items,
-        JS_TYPES,
-        /\btw`([^`]*)$/,
-        ['`', ' ', separator],
-        tailwind.config
-      )
+      createCompletionItemProvider({
+        items: this._items,
+        languages: JS_TYPES,
+        regex: /\btw`([^`]*)$/,
+        triggerCharacters: ['`', ' ', separator],
+        config: tailwind.config
+      })
     )
 
     this._providers.push(
-      createCompletionItemProvider(
-        this._items,
-        CSS_TYPES,
-        /@apply ([^;}]*)$/,
-        ['.', separator],
-        tailwind.config,
-        '.'
-      )
+      createCompletionItemProvider({
+        items: this._items,
+        languages: CSS_TYPES,
+        regex: /@apply ([^;}]*)$/,
+        triggerCharacters: ['.', separator],
+        config: tailwind.config,
+        prefix: '.'
+      })
     )
 
     this._providers.push(
-      createCompletionItemProvider(
-        this._items,
-        HTML_TYPES,
-        /\bclass(Name)?=["']([^"']*)$/, // /\bclass(Name)?=(["'])(?!.*?\2)/
-        ["'", '"', ' ', '.', separator],
-        tailwind.config
-      )
+      createCompletionItemProvider({
+        items: this._items,
+        languages: HTML_TYPES,
+        regex: /\bclass(Name)?=["']([^"']*)$/, // /\bclass(Name)?=(["'])(?!.*?\2)/
+        triggerCharacters: ["'", '"', ' ', '.', separator],
+        config: tailwind.config,
+        emmet: true
+      })
+    )
+
+    // Vue.js
+    this._providers.push(
+      createCompletionItemProvider({
+        items: this._items,
+        languages: ['vue'],
+        regex: /\bclass(Name)?=["']([^"']*)$/,
+        enable: text => {
+          if (
+            (text.indexOf('<template') !== -1 &&
+              text.indexOf('</template>') === -1) ||
+            (text.indexOf('<script') !== -1 && text.indexOf('</script>') === -1)
+          ) {
+            return true
+          }
+          return false
+        },
+        triggerCharacters: ["'", '"', ' ', '.', separator],
+        config: tailwind.config,
+        emmet: true
+      })
+    )
+    this._providers.push(
+      createCompletionItemProvider({
+        items: this._items,
+        languages: ['vue'],
+        regex: /@apply ([^;}]*)$/,
+        triggerCharacters: ['.', separator],
+        config: tailwind.config,
+        enable: text => {
+          if (
+            text.indexOf('<style') !== -1 &&
+            text.indexOf('</style>') === -1
+          ) {
+            return true
+          }
+          return false
+        }
+      })
     )
 
     this._providers.push(