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): autocomplete for css #1118

Merged
merged 1 commit into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/vscode/src/annotation.ts
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode/src/autocomplete.ts
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions packages/vscode/src/contextLoader.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down