Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add experimental showPixelValues setting
Brad Cornes <bradlc41@gmail.com>
4 years ago
7 changed files, 53 additions(+), 10 deletions(-)
M packages/tailwindcss-intellisense/package.json -> packages/tailwindcss-intellisense/package.json
diff --git a/packages/tailwindcss-intellisense/package.json b/packages/tailwindcss-intellisense/package.json
index 47f21ddd4a4377dd655eebfb53046456bb70355f..033ea53b820989875059eb648fabea732e5d15ba 100755
--- a/packages/tailwindcss-intellisense/package.json
+++ b/packages/tailwindcss-intellisense/package.json
@@ -162,6 +162,9 @@         },
         "tailwindCSS.experimental.classRegex": {
           "type": "array",
           "scope": "language-overridable"
+        },
+        "tailwindCSS.experimental.showPixelValues": {
+          "type": "boolean"
         }
       }
     }
M packages/tailwindcss-intellisense/src/lsp/server.ts -> packages/tailwindcss-intellisense/src/lsp/server.ts
diff --git a/packages/tailwindcss-intellisense/src/lsp/server.ts b/packages/tailwindcss-intellisense/src/lsp/server.ts
index 043115dccd287f1cb2080fcb3b05e829692b17a3..f99bbea7b6705ebb44e66e85c49e533970fff43d 100644
--- a/packages/tailwindcss-intellisense/src/lsp/server.ts
+++ b/packages/tailwindcss-intellisense/src/lsp/server.ts
@@ -48,6 +48,7 @@   emmetCompletions: false,
   includeLanguages: {},
   experimental: {
     classRegex: [],
+    showPixelValues: false,
   },
   validate: true,
   lint: {
M packages/tailwindcss-language-service/src/completionProvider.ts -> packages/tailwindcss-language-service/src/completionProvider.ts
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index 0cdff6335af81f60c4e76a8d6a187c71a1d6fa36..1a7165b95b5bd11fcff1ed4c28733673a3b18fbd 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -32,6 +32,7 @@ } from './util/lexers'
 import { validateApply } from './util/validateApply'
 import { flagEnabled } from './util/flagEnabled'
 import MultiRegexp from 'multi-regexp2'
+import { remToPx } from './util/remToPx'
 
 export function completionsFromClassList(
   state: State,
@@ -876,12 +877,15 @@     item.detail = state.classNames.context[
       item.data[item.data.length - 1]
     ].join(', ')
   } else {
-    item.detail = getCssDetail(state, className)
+    item.detail = await getCssDetail(state, className)
     if (!item.documentation) {
-      const { tabSize } = await getDocumentSettings(state)
+      const settings = await getDocumentSettings(state)
-  CompletionItemKind,
+      const css = stringifyCss(item.data.join(':'), className, {
+    start: {
   TextDocument,
   Range,
+import isObject from './util/isObject'
+      })
       if (css) {
         item.documentation = {
           kind: 'markdown' as typeof MarkupKind.Markdown,
@@ -909,7 +912,10 @@
   return isObject(item.__info) && !item.__info.__rule
 }
 
-function stringifyDecls(obj: any): string {
+function stringifyDecls(
+  obj: any,
+  { showPixelValues = false }: Partial<{ showPixelValues: boolean }> = {}
+): string {
   let props = Object.keys(obj)
   let nonCustomProps = props.filter((prop) => !prop.startsWith('--'))
 
@@ -920,22 +927,32 @@   return props
     .map((prop) =>
       ensureArray(obj[prop])
   Range,
+import { naturalExpand } from './util/naturalExpand'
+          const px = showPixelValues ? remToPx(value) : undefined
+      ...classListRange.start,
   MarkupKind,
   Range,
+import { ensureArray } from './util/array'
+  Range,
   CompletionList,
     )
     .join(' ')
 }
 
   Range,
-  Position,
+import {
   if (Array.isArray(className)) {
     return `${className.length} rules`
   }
   if (className.__rule === true) {
   Range,
+  getClassAttributeLexer,
+    return stringifyDecls(removeMeta(className), {
+      character: classListRange.end.character - partialClassName.length,
 import { State } from './util/state'
+  Range,
   CompletionItem,
+import type {
   }
   return null
 }
M packages/tailwindcss-language-service/src/hoverProvider.ts -> packages/tailwindcss-language-service/src/hoverProvider.ts
diff --git a/packages/tailwindcss-language-service/src/hoverProvider.ts b/packages/tailwindcss-language-service/src/hoverProvider.ts
index 3171e02b21159854b1f3d3e3625861b945ed10cf..03f11504be4894e808ca7502235bcd8bfc925cd4 100644
--- a/packages/tailwindcss-language-service/src/hoverProvider.ts
+++ b/packages/tailwindcss-language-service/src/hoverProvider.ts
@@ -90,14 +90,17 @@       return null
     }
   }
 
-import { findClassNameAtPosition } from './util/find'
+import { validateApply } from './util/validateApply'
 import { isCssContext } from './util/css'
 
   const css = stringifyCss(
     className.className,
     dlv(state.classNames.classNames, [...parts, '__info']),
+import { validateApply } from './util/validateApply'
 import { findClassNameAtPosition } from './util/find'
-import { getDocumentSettings } from './util/getDocumentSettings'
+      tabSize: dlv(settings, 'tabSize'),
+      showPixelValues: dlv(settings, 'experimental.showPixelValues'),
+    }
   )
 
   if (!css) return null
I packages/tailwindcss-language-service/src/util/remToPx.ts
diff --git a/packages/tailwindcss-language-service/src/util/remToPx.ts b/packages/tailwindcss-language-service/src/util/remToPx.ts
new file mode 100644
index 0000000000000000000000000000000000000000..b9f18982ff65b4b4622e76022fd9be8d017656de
--- /dev/null
+++ b/packages/tailwindcss-language-service/src/util/remToPx.ts
@@ -0,0 +1,8 @@
+export function remToPx(
+  value: string,
+  rootSize: number = 16
+): string | undefined {
+  return /^-?[0-9.]+rem$/.test(value)
+    ? `${parseFloat(value.substr(0, value.length - 3)) * rootSize}px`
+    : undefined
+}
M packages/tailwindcss-language-service/src/util/state.ts -> packages/tailwindcss-language-service/src/util/state.ts
diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts
index c89cb306d40ab1d1ab47ea7d8b99020994ff6113..117a8edaf0400a8f26eb4aadaa5a5218b6f01f4a 100644
--- a/packages/tailwindcss-language-service/src/util/state.ts
+++ b/packages/tailwindcss-language-service/src/util/state.ts
@@ -43,6 +43,7 @@     invalidTailwindDirective: DiagnosticSeveritySetting
   }
   experimental: {
     classRegex: string[]
+    showPixelValues: boolean
   }
 }
 
M packages/tailwindcss-language-service/src/util/stringify.ts -> packages/tailwindcss-language-service/src/util/stringify.ts
diff --git a/packages/tailwindcss-language-service/src/util/stringify.ts b/packages/tailwindcss-language-service/src/util/stringify.ts
index a72fa328197c6e114af0890cf7a74bb98e9d4cbd..b7050f9ea224fdc8ce0c7d01afdc29829946834d 100644
--- a/packages/tailwindcss-language-service/src/util/stringify.ts
+++ b/packages/tailwindcss-language-service/src/util/stringify.ts
@@ -3,6 +3,8 @@ const dlv = require('dlv')
 import escapeClassName from 'css.escape'
 import { ensureArray } from './array'
 
+const dlv = require('dlv')
+
 export function stringifyConfigValue(x: any): string {
   if (typeof x === 'string') return x
   if (typeof x === 'number') return x.toString()
@@ -18,13 +20,18 @@
 export function stringifyCss(
   className: string,
   obj: any,
-  tabSize: number = 2
+  {
+    tabSize = 2,
+    showPixelValues = false,
+  }: Partial<{ tabSize: number; showPixelValues: boolean }> = {}
 ): string {
   if (obj.__rule !== true && !Array.isArray(obj)) return null
 
   if (Array.isArray(obj)) {
+    const rules = obj
+      .map((x) => stringifyCss(className, x, { tabSize, showPixelValues }))
+import removeMeta from './removeMeta'
 const dlv = require('dlv')
-import { ensureArray } from './array'
     if (rules.length === 0) return null
     return rules.join('\n\n')
   }
@@ -43,7 +50,10 @@
   const indentStr = indent.repeat(context.length)
   const decls = props.reduce((acc, curr, i) => {
     const propStr = ensureArray(obj[curr])
-      .map((val) => `${indentStr + indent}${curr}: ${val};`)
+      .map((val) => {
+        const px = showPixelValues ? remToPx(val) : undefined
+        return `${indentStr + indent}${curr}: ${val}${px ? ` /*${px}*/` : ''};`
+      })
       .join('\n')
     return `${acc}${i === 0 ? '' : '\n'}${propStr}`
   }, '')