diff --git a/packages/vscode/src/annotation.ts b/packages/vscode/src/annotation.ts index d758abb31a..efcee91ea3 100644 --- a/packages/vscode/src/annotation.ts +++ b/packages/vscode/src/annotation.ts @@ -60,9 +60,9 @@ export async function registerAnnotations( return reset() let ctx = await contextLoader.resolveContext(code, id) - if (!ctx && (code.includes(INCLUDE_COMMENT_IDE) || isCssId(id))) + if (!ctx) ctx = await contextLoader.resolveClosestContext(code, id) - else if (!ctx?.filter(code, id)) + else if (!ctx.filter(code, id) && !code.includes(INCLUDE_COMMENT_IDE) && !isCssId(id)) return null const result = await ctx.uno.generate(code, { id, preflights: false, minify: true }) diff --git a/packages/vscode/src/autocomplete.ts b/packages/vscode/src/autocomplete.ts index 71605b2e56..8620b84829 100644 --- a/packages/vscode/src/autocomplete.ts +++ b/packages/vscode/src/autocomplete.ts @@ -71,9 +71,9 @@ export async function registerAutoComplete( return null let ctx = await contextLoader.resolveContext(code, id) - if (!ctx && isCssId(id)) + if (!ctx) ctx = await contextLoader.resolveClosestContext(code, id) - else if (!ctx?.filter(code, id)) + else if (!ctx.filter(code, id) && !isCssId(id)) return null try { diff --git a/packages/vscode/src/contextLoader.ts b/packages/vscode/src/contextLoader.ts index 36d49c327b..1be99263c7 100644 --- a/packages/vscode/src/contextLoader.ts +++ b/packages/vscode/src/contextLoader.ts @@ -8,7 +8,7 @@ import presetUno from '@unocss/preset-uno' import { resolveOptions as resolveNuxtOptions } from '../../nuxt/src/options' import { createNanoEvents } from '../../core/src/utils/events' import { createContext } from './integration' -import { isSubdir } from './utils' +import { isCssId, isSubdir } from './utils' import { log } from './log' export class ContextLoader { @@ -178,7 +178,7 @@ export class ContextLoader { if (!isSubdir(configDir, file)) continue - if (!context.filter(code, file)) + if (!context.filter(code, file) && !isCssId(file)) continue this.fileContextCache.set(file, context) @@ -191,7 +191,7 @@ export class ContextLoader { while (isSubdir(this.cwd, dir)) { if (await this.configExists(dir)) { const context = await this.loadContextInDirectory(dir) - if (context?.filter(code, file)) { + if (context?.filter(code, file) || isCssId(file)) { this.fileContextCache.set(file, context) return context } @@ -220,7 +220,7 @@ export class ContextLoader { if (!isSubdir(configDir, file)) continue - if (!context.filter(code, file)) + if (!context.filter(code, file) && !isCssId(file)) continue this.fileContextCache.set(file, context)