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

Conversation

TrickyPi
Copy link
Contributor

motivation

support prompt of autocomplete and annotation for css file as before.

cc @QiroNT

@TrickyPi TrickyPi requested a review from antfu as a code owner June 19, 2022 12:51
@netlify
Copy link

netlify bot commented Jun 19, 2022

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 01fa3ec
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/62b15ad00ea3ac0008173581
😎 Deploy Preview https://deploy-preview-1118--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.

@QiroNT
Copy link
Member

QiroNT commented Jun 19, 2022

Hi, thanks for the contribution.

I think the changed condition is still the same, and css-like files actually have context cache.

if (isSubdir(configDir, file)) {
this.fileContextCache.set(file, context)
return context
}

What's the problem with the current implementation? After fixing #1119 I don't see any issue on my side.

@TrickyPi
Copy link
Contributor Author

The changed Conditional isn't totally same as before.
https://github.com/unocss/unocss/pull/1118/files#diff-3241d63de07ad5b12662fc4d9f3559f3e4c2836772e8b921612675c05b9f6f87L76
the result of executing context.filter(code, id) is false if the id param is a path of css file,so the prompt of autoComplete for css file does not work.

@QiroNT
Copy link
Member

QiroNT commented Jun 19, 2022

I think... AutoComplete will still work since resolveClosestContext will 100% resolve a context for it.

The current logic before change basically is:

  • If resolveContext resolved a context and filter passed, then use the context.
  • If it's a css-like file, use the context from resolveClosestContext.
  • If none of the above matches, the prompt will not be activated.

There for, css-like files will always get a context either from resolveContext or resolveClosestContext, it should never fail.

EDIT: Oh I know, css-like files which have a context but don't pass the filter will not be resolved.
Is that a real issue? If the file is excluded, I think the autocomplete prompt shouldn't be activated.

@TrickyPi
Copy link
Contributor Author

TrickyPi commented Jun 19, 2022

it will cause another issue.
Existed the following dir structure

├── index.html
├── package.json
├── pnpm-lock.yaml
├── src
│   ├── App.css
│   ├── App.tsx
│   ├── favicon.svg
│   ├── index.css
│   ├── logo.svg
│   ├── main.tsx
│   └── vite-env.d.ts
├── tsconfig.json
├── tsconfig.node.json
└── vite.config.ts

Actually, the context of css-like file is null
Caused by this code

https://github.com/unocss/unocss/blob/1097c5bd682294a48f32a3ddf2ffaa965a269291/packages/vscode/src/contextLoader.ts#L131toL136

@TrickyPi
Copy link
Contributor Author

TrickyPi commented Jun 19, 2022

Oh I know, css-like files which have a context but don't pass the filter will not be resolved.
Is that a real issue? If the file is excluded, I think the autocomplete prompt shouldn't be activated.

yeah, it's a real issue(see #985). By the way, i don't know why the defaultExclude contains css-like files.
https://github.com/unocss/unocss/blob/main/packages/shared-integration/src/defaults.ts#L3

Copy link
Member

@QiroNT QiroNT left a comment

Choose a reason for hiding this comment

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

I see, it's ok.

If resolveClosestContext could be called only when needed then it would be better. It's not that expensive tho.

@antfu
Copy link
Member

antfu commented Jun 21, 2022

Can you help resolve the conflicts? Thanks

@TrickyPi
Copy link
Contributor Author

Ok, just a minute.

@TrickyPi
Copy link
Contributor Author

Done.

@antfu antfu changed the title fix(vscode): tweak Conditional of intelligent prompt && add context cache of css-like file fix(vscode): autocomplete for css Jun 21, 2022
@antfu antfu merged commit 8acd5d8 into unocss:main Jun 21, 2022
@TrickyPi TrickyPi deleted the fix/support-css-like-file branch June 23, 2022 15:59
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.

None yet

3 participants