Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vscode): skip util contains none color define #1769

Merged
merged 4 commits into from Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vscode/src/annotation.ts
Expand Up @@ -97,7 +97,7 @@ export async function registerAnnotations(

const result = await ctx.uno.generate(code, { id, preflights: false, minify: true })

const colorsMap = getColorsMap(ctx.uno, result)
const colorsMap = await getColorsMap(ctx.uno, result)
const colorRanges: DecorationOptions[] = []
const _colorPositionsCache = new Map<string, string>() // cache for avoid duplicated color ranges

Expand Down
11 changes: 10 additions & 1 deletion packages/vscode/src/utils.ts
Expand Up @@ -59,11 +59,14 @@ export function body2ColorValue(body: string, theme: Theme) {
const matchedAttributifyRE = /(?<=^\[.+~=").*(?="\]$)/
const matchedValuelessAttributifyRE = /(?<=^\[).+(?==""\]$)/
const _colorsMapCache = new Map<string, string>()
export function getColorsMap(uno: UnoGenerator, result: GenerateResult) {
export async function getColorsMap(uno: UnoGenerator, result: GenerateResult) {
const theme = uno.config.theme as Theme
const colorsMap = new Map<string, string>()

for (const i of result.matched) {
if (!(await isColorUtility(uno, i)))
continue

const matchedValueless = i.match(matchedValuelessAttributifyRE)?.[0]
const colorKey = matchedValueless ?? i.replace('~="', '="')

Expand Down Expand Up @@ -97,3 +100,9 @@ export function isSubdir(parent: string, child: string) {
const relative = path.relative(parent, child)
return relative && !relative.startsWith('..') && !path.isAbsolute(relative)
}

async function isColorUtility(uno: UnoGenerator, utilName: string) {
const css = (await getPrettiedCSS(uno, utilName)).css
azaleta marked this conversation as resolved.
Show resolved Hide resolved

return css.includes('color')
}