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): respect unocss.root #1169

Merged
merged 5 commits into from Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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: 3 additions & 1 deletion packages/vscode/src/annotation.ts
Expand Up @@ -53,9 +53,11 @@ export async function registerAnnotations(
if (!doc)
return reset()

const code = doc.getText()
const id = doc.uri.fsPath
if (!id.startsWith(cwd))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's unnecessary.

return reset()

const code = doc.getText()
if (!code)
return reset()

Expand Down
5 changes: 4 additions & 1 deletion packages/vscode/src/autocomplete.ts
Expand Up @@ -36,6 +36,7 @@ class UnoCompletionItem extends CompletionItem {
}

export async function registerAutoComplete(
cwd: string,
contextLoader: ContextLoader,
ext: ExtensionContext,
) {
Expand Down Expand Up @@ -64,9 +65,11 @@ export async function registerAutoComplete(

const provider: CompletionItemProvider<UnoCompletionItem> = {
async provideCompletionItems(doc, position) {
const code = doc.getText()
const id = doc.uri.fsPath
if (!id.startsWith(cwd))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

return null

const code = doc.getText()
if (!code)
return null

Expand Down
7 changes: 6 additions & 1 deletion packages/vscode/src/index.ts
Expand Up @@ -19,12 +19,17 @@ export async function activate(ext: ExtensionContext) {
log.appendLine(`UnoCSS for VS Code v${version} ${process.cwd()}`)

const contextLoader = new ContextLoader(cwd)

const hasConfig = await contextLoader.loadContextInDirectory(cwd)
if (!hasConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The load function in loadContextInDirectory may be called twice, because new ContextLoader calls loadContextInDirectory by default, so it's better to call contextLoader.loadContextInDirectory after contextLoader.ready, and this call will hit the contextsMap cache (the cache value is null)

return

await contextLoader.ready

const status = window.createStatusBarItem(StatusBarAlignment.Right, 200)
status.text = 'UnoCSS'

registerAutoComplete(contextLoader, ext)
registerAutoComplete(cwd, contextLoader, ext)
registerAnnotations(cwd, contextLoader, status, ext)

ext.subscriptions.push(commands.registerCommand('unocss.reload', async () => {
Expand Down