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

fix(vscode): respect unocss.root #1169

merged 5 commits into from Jun 30, 2022

Conversation

holazz
Copy link
Contributor

@holazz holazz commented Jun 26, 2022

After v0.40.0, configuring unocss.root does not work, decorations and tooltips are displayed in all files.

close #1183

@holazz holazz requested a review from antfu as a code owner June 26, 2022 06:26
@netlify
Copy link

netlify bot commented Jun 26, 2022

Deploy Preview for unocss ready!

Name Link
🔨 Latest commit 6945507
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/62bd135e44451700085881c7
😎 Deploy Preview https://deploy-preview-1169--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@antfu
Copy link
Member

antfu commented Jun 26, 2022

/cc @QiroNT

@TrickyPi
Copy link
Contributor

TrickyPi commented Jun 27, 2022

I guess bug in here

const contextLoader = new ContextLoader(cwd)
await contextLoader.ready
const status = window.createStatusBarItem(StatusBarAlignment.Right, 200)
status.text = 'UnoCSS'
registerAutoComplete(contextLoader, ext)
registerAnnotations(cwd, contextLoader, status, ext)

Although the project does not contain any unocss config files, the registerAutoComplete and registerAnnotations functions are called, and the ContextLoader creates the default context.

@holazz
Copy link
Contributor Author

holazz commented Jun 28, 2022

Hi, @TrickyPi thanks for your comment. I updated a commit. The extension shouldn't be activated when the config file is not found under unocss.root, right?

This is my first PR on unocss and my changes may be ill-considered. Hope someone more experienced can fix it if I'm in the wrong direction.

@holazz holazz changed the title fix(vscode): display annotations only in files under the path of unocss.root fix(vscode): respect unocss.root Jun 28, 2022
Copy link
Contributor

@TrickyPi TrickyPi left a comment

Choose a reason for hiding this comment

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

These are my ideas.

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.

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.

@@ -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)

@TrickyPi
Copy link
Contributor

The extension shouldn't be activated when the config file is not found under unocss.root, right?

Yes

@antfu antfu enabled auto-merge (squash) June 30, 2022 03:08
@antfu antfu merged commit 307417e into unocss:main Jun 30, 2022
@holazz holazz deleted the fix/vscode branch June 30, 2022 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[vscode-intelisence] incorrectly detects typescript class as CSS
3 participants