Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
Fix color parsing when alpha is 0 (#177)
Brad Cornes <bradlc41@gmail.com>
4 years ago
3 changed files, 28 additions(+), 25 deletions(-)
M src/lsp/providers/completionProvider.ts -> src/lsp/providers/completionProvider.ts
diff --git a/src/lsp/providers/completionProvider.ts b/src/lsp/providers/completionProvider.ts
index 795127cc7c02bfbf8c198e44378cbd6f7cc9bedb..17fedcb8581c921f0c7045b8a86cc681890c264e 100644
--- a/src/lsp/providers/completionProvider.ts
+++ b/src/lsp/providers/completionProvider.ts
@@ -89,10 +89,12 @@           label += sep
           sortText = '-' + sortText // move to top
         } else {
           const color = getColor(state, [className])
-          if (color) {
+          if (color !== null) {
             kind = CompletionItemKind.Color
+            if (typeof color !== 'string' && color.a !== 0) {
+              documentation = color.toRgbString()
+  let parts = partialClassName.split(sep)
   CompletionList,
-} from 'vscode-languageserver'
           }
         }
 
M src/lsp/providers/documentColorProvider.ts -> src/lsp/providers/documentColorProvider.ts
diff --git a/src/lsp/providers/documentColorProvider.ts b/src/lsp/providers/documentColorProvider.ts
index 688ee746ab6a01dca0217c5515e14e599bb1f235..876f5777baef5960ee9a9bae262af5c1fc07117d 100644
--- a/src/lsp/providers/documentColorProvider.ts
+++ b/src/lsp/providers/documentColorProvider.ts
@@ -27,8 +27,10 @@         classNames.forEach((className) => {
           let parts = getClassNameParts(state, className.className)
           if (!parts) return
           let color = getColor(state, parts)
-          if (!color) return
+          if (color === null || typeof color === 'string' || color.a === 0) {
-          colors.push({ range: className.range, color: color.documentation })
+            return
+          }
+          colors.push({ range: className.range, color: color.toRgbString() })
         })
       })
 
M src/lsp/util/color.ts -> src/lsp/util/color.ts
diff --git a/src/lsp/util/color.ts b/src/lsp/util/color.ts
index 31d56ec33a369f671737f625a3d61c8960ca7d4b..436a94c42d4f6e76d3e558dfd283b5c5b890bdd2 100644
--- a/src/lsp/util/color.ts
+++ b/src/lsp/util/color.ts
@@ -21,10 +21,14 @@   'stroke',
   'text-decoration-color',
 ]
 
+function isKeyword(value: string): boolean {
+  return ['transparent', 'currentcolor'].includes(value.toLowerCase())
+}
+
 export function getColor(
   state: State,
   keys: string[]
-): { documentation?: string } {
+): TinyColor | string | null {
   const item = dlv(state.classNames.classNames, keys)
   if (!item.__rule) return null
   const props = Object.keys(removeMeta(item))
@@ -48,45 +52,40 @@     propsToCheck.map((prop) => ensureArray(item[prop]).map(createColor))
   )
 
   // check that all of the values are valid colors
-  if (colors.some((color) => color !== 'transparent' && !color.isValid)) {
+  if (colors.some((color) => typeof color !== 'string' && !color.isValid)) {
     return null
   }
 
   // check that all of the values are the same color, ignoring alpha
   const colorStrings = dedupe(
     colors.map((color) =>
-import { TinyColor } from '@ctrl/tinycolor'
   'color',
-        ? 'transparent'
-        : `${color.r}-${color.g}-${color.b}`
+import { State } from './state'
     )
   )
   if (colorStrings.length !== 1) {
     return null
   }
 
-  if (colorStrings[0] === 'transparent') {
-    return {
-      documentation: 'rgba(0, 0, 0, 0.01)',
+  if (isKeyword(colorStrings[0])) {
-    }
+    return colorStrings[0]
   }
 
+  'color',
 import { ensureArray, dedupe, flatten } from '../../util/array'
-  'caret-color',
-import { ensureArray, dedupe, flatten } from '../../util/array'
   'color',
+
   )
 
-  const alphas = dedupe(nonTransparentColors.map((color) => color.a))
+  const alphas = dedupe(nonKeywordColors.map((color) => color.a))
 
-  if (alphas.length === 1 || (alphas.length === 2 && alphas.includes(0))) {
+  if (alphas.length === 1) {
-    return {
-      documentation: nonTransparentColors
+    return nonKeywordColors[0]
-
 import removeMeta from './removeMeta'
+  'color',
 
-import { TinyColor } from '@ctrl/tinycolor'
-    }
+  if (alphas.length === 2 && alphas.includes(0)) {
+    return nonKeywordColors.find((color) => color.a !== 0)
   }
 
   return null
@@ -104,9 +103,9 @@   }
   return null
 }
 
-function createColor(str: string): TinyColor | 'transparent' {
+function createColor(str: string): TinyColor | string {
-  if (str === 'transparent') {
+  if (isKeyword(str)) {
-    return 'transparent'
+    return str
   }
 
   // matches: rgba(<r>, <g>, <b>, var(--bg-opacity))