tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
replace `experimental.showPixelValues` setting with `showPixelEquivalents` and enable by default (#200)
7 changed files, 50 additions(+), 18 deletions(-)
diff --git a/packages/tailwindcss-intellisense/package.json b/packages/tailwindcss-intellisense/package.json
index 5e916bc2836c0d64724b01b0fa4130f7290693cc..bf408ed1a95f50e3c0f494aeb4b5604ee1b92be2 100755
--- a/packages/tailwindcss-intellisense/package.json
+++ b/packages/tailwindcss-intellisense/package.json
@@ -163,8 +163,15 @@ "tailwindCSS.experimental.classRegex": {
"type": "array",
"scope": "language-overridable"
},
- "tailwindCSS.experimental.showPixelValues": {
- "type": "boolean"
+ "tailwindCSS.showPixelEquivalents": {
+ "type": "boolean",
+ "default": true,
+ "markdownDescription": "Show `px` equivalents for `rem` CSS values."
+ },
+ "tailwindCSS.rootFontSize": {
+ "type": "number",
+ "default": 16,
+ "markdownDescription": "Root font size in pixels. Used to convert `rem` CSS values to their `px` equivalents. See `#tailwindCSS.showPixelEquivalents#`."
}
}
}
diff --git a/packages/tailwindcss-intellisense/src/lsp/server.ts b/packages/tailwindcss-intellisense/src/lsp/server.ts
index f99bbea7b6705ebb44e66e85c49e533970fff43d..9e5243c34eed9a82c62f775038473dba056227fc 100644
--- a/packages/tailwindcss-intellisense/src/lsp/server.ts
+++ b/packages/tailwindcss-intellisense/src/lsp/server.ts
@@ -48,8 +48,9 @@ emmetCompletions: false,
includeLanguages: {},
experimental: {
classRegex: [],
- showPixelValues: false,
},
+ showPixelEquivalents: true,
+ rootFontSize: 16,
validate: true,
lint: {
cssConflict: 'warning',
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index f7655a0caf7c528dbcc183ab7c17299d2afc5c92..77963b53531d34b9b4c72d01390143001c8b0339 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -900,8 +900,9 @@ item.detail = await getCssDetail(state, className)
if (!item.documentation) {
const settings = await getDocumentSettings(state)
const css = stringifyCss(item.data.join(':'), className, {
- tabSize: dlv(settings, 'tabSize'),
- showPixelValues: dlv(settings, 'experimental.showPixelValues'),
+ tabSize: dlv(settings, 'tabSize', 2),
+ showPixelEquivalents: dlv(settings, 'showPixelEquivalents', true),
+ rootFontSize: dlv(settings, 'rootFontSize', 16),
})
if (css) {
item.documentation = {
@@ -932,7 +933,10 @@ }
function stringifyDecls(
obj: any,
- { showPixelValues = false }: Partial<{ showPixelValues: boolean }> = {}
+ {
+ showPixelEquivalents = false,
+ rootFontSize = 16,
+ }: Partial<{ showPixelEquivalents: boolean; rootFontSize: number }> = {}
): string {
let props = Object.keys(obj)
let nonCustomProps = props.filter((prop) => !prop.startsWith('--'))
@@ -945,7 +949,9 @@ return props
.map((prop) =>
ensureArray(obj[prop])
.map((value) => {
- const px = showPixelValues ? remToPx(value) : undefined
+ const px = showPixelEquivalents
+ ? remToPx(value, rootFontSize)
+ : undefined
return `${prop}: ${value}${px ? ` /*${px}*/` : ''};`
})
.join(' ')
@@ -960,7 +966,8 @@ }
if (className.__rule === true) {
const settings = await getDocumentSettings(state)
return stringifyDecls(removeMeta(className), {
- showPixelValues: dlv(settings, 'experimental.showPixelValues', false),
+ showPixelEquivalents: dlv(settings, 'showPixelEquivalents', true),
+ rootFontSize: dlv(settings, 'rootFontSize', 16),
})
}
return null
diff --git a/packages/tailwindcss-language-service/src/hoverProvider.ts b/packages/tailwindcss-language-service/src/hoverProvider.ts
index 92fa34da5f8697c7410c1b58d69bbb681cc9d0d7..8326afb058ba45f667c5768bdee7a672724c2f57 100644
--- a/packages/tailwindcss-language-service/src/hoverProvider.ts
+++ b/packages/tailwindcss-language-service/src/hoverProvider.ts
@@ -96,8 +96,9 @@ const css = stringifyCss(
className.className,
dlv(state.classNames.classNames, [...parts, '__info']),
{
- tabSize: dlv(settings, 'tabSize'),
- showPixelValues: dlv(settings, 'experimental.showPixelValues'),
+ tabSize: dlv(settings, 'tabSize', 2),
+ showPixelEquivalents: dlv(settings, 'showPixelEquivalents', true),
+ rootFontSize: dlv(settings, 'rootFontSize', 16),
}
)
diff --git a/packages/tailwindcss-language-service/src/util/remToPx.ts b/packages/tailwindcss-language-service/src/util/remToPx.ts
index b9f18982ff65b4b4622e76022fd9be8d017656de..445bb60a399208f23b1ff74dd9bf773baf75c0fa 100644
--- a/packages/tailwindcss-language-service/src/util/remToPx.ts
+++ b/packages/tailwindcss-language-service/src/util/remToPx.ts
@@ -2,7 +2,11 @@ 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
+ if (/^-?[0-9.]+rem$/.test(value)) {
+ let number = parseFloat(value.substr(0, value.length - 3))
+ if (!isNaN(number)) {
+ return `${number * rootSize}px`
+ }
+ }
+ return undefined
}
diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts
index 117a8edaf0400a8f26eb4aadaa5a5218b6f01f4a..4835a71077a4e2a7bade9807f859ab458e26ce1c 100644
--- a/packages/tailwindcss-language-service/src/util/state.ts
+++ b/packages/tailwindcss-language-service/src/util/state.ts
@@ -33,6 +33,8 @@ tabSize: number
emmetCompletions: boolean
includeLanguages: Record<string, string>
validate: boolean
+ showPixelEquivalents: boolean
+ rootFontSize: number
lint: {
cssConflict: DiagnosticSeveritySetting
invalidApply: DiagnosticSeveritySetting
@@ -43,7 +45,6 @@ invalidTailwindDirective: DiagnosticSeveritySetting
}
experimental: {
classRegex: string[]
- showPixelValues: boolean
}
}
diff --git a/packages/tailwindcss-language-service/src/util/stringify.ts b/packages/tailwindcss-language-service/src/util/stringify.ts
index b7050f9ea224fdc8ce0c7d01afdc29829946834d..3aebd99b04d222b4c59512d2f996fd279f75bf7f 100644
--- a/packages/tailwindcss-language-service/src/util/stringify.ts
+++ b/packages/tailwindcss-language-service/src/util/stringify.ts
@@ -21,14 +21,25 @@ className: string,
obj: any,
{
tabSize = 2,
- showPixelValues = false,
- }: Partial<{ tabSize: number; showPixelValues: boolean }> = {}
+ showPixelEquivalents = false,
+ rootFontSize = 16,
+ }: Partial<{
+ tabSize: number
+ showPixelEquivalents: boolean
+ rootFontSize: number
+ }> = {}
): string {
if (obj.__rule !== true && !Array.isArray(obj)) return null
if (Array.isArray(obj)) {
const rules = obj
- .map((x) => stringifyCss(className, x, { tabSize, showPixelValues }))
+ .map((x) =>
+ stringifyCss(className, x, {
+ tabSize,
+ showPixelEquivalents,
+ rootFontSize,
+ })
+ )
.filter(Boolean)
if (rules.length === 0) return null
return rules.join('\n\n')
@@ -49,7 +60,7 @@ const indentStr = indent.repeat(context.length)
const decls = props.reduce((acc, curr, i) => {
const propStr = ensureArray(obj[curr])
.map((val) => {
- const px = showPixelValues ? remToPx(val) : undefined
+ const px = showPixelEquivalents ? remToPx(val, rootFontSize) : undefined
return `${indentStr + indent}${curr}: ${val}${px ? ` /*${px}*/` : ''};`
})
.join('\n')