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

VSCode extension does not provide intellisense for shortcuts or rules added in custom preset. #3000

Closed
4 tasks done
KraXen72 opened this issue Aug 18, 2023 · 8 comments
Closed
4 tasks done
Labels

Comments

@KraXen72
Copy link

KraXen72 commented Aug 18, 2023

UnoCSS version

0.55.1

Describe the bug

Shortcuts and rules added in custom preset files (which are defined in configDeps vite plugin option and imported to uno.config.ts) work in the resulting app, but don't have autocomplete, unless VSCode extension is reloaded with the reload command.

Reproduction

I tried to reproduce it in stackblitz, but that apparently doesen't use the VSCode extension (i got no autocomplete at all), and the playground does not allow creating arbitrary ts files to import in the config.
Anyway, i made the basic repro in stackblitz, you can download it and open in VSCode.

How to repro:

  • https://stackblitz.com/edit/unocss-unocss-i31ibt?file=uno.config.ts

  • run UnoCSS: reload command to load the unocss extension LSP (workaround for extension version 0.55.1)

  • add a new shortcut / rule in the custom-preset file.

  • try using it in the code; it will work, but you will not get intellisense for it

    • old shortcut:
      image
    • new shortcut:
      image
  • current workaround: if you define your shortcuts / rules directly in uno.config.ts, you will get intellisense immediately

  • run UnoCSS: reload command, you now have intellisense

System Info

Windows 10, Vivaldi, svelte

Validations

@sixdjango
Copy link

me too bro~

@KraXen72
Copy link
Author

this is still not resloved by #3005 . i updated unocss and all @unocss/* packagages to 0.55.2, the VSCode extension too. Luckily, since #3005 did resolve #3001, (reloading launching multiple UnoCSS LSP instances) a quick reload of the extension is all you need. still a workaround, but pretty usable at this point.l

@Jannchie
Copy link
Contributor

You are right, I am sure that to address this issue, changes need to be made here. It appears that making it detect changes to the presets.ts file is necessary. This seems to be a bit complicated, as it might require parsing the import section of uno.config.ts.

@KraXen72
Copy link
Author

it appears that making it detect changes to the presets.ts file is necessary.

i could not find a presets.ts file anywhere, using github codeserach or sourcegraph.
Do you prehaps mean the presets field in config? if you are planning on checking just that, remember that people can import and edit stuff other than presets in different files. for example, one could create a file that exports a shortcuts object, include the file in vite plugin's configDeps options, and import that shortcuts field in config.

@Jannchie
Copy link
Contributor

Oh, I mean presets.ts is your custom preset file.

Currently the extension only reload config on changes to the config file (uno.config.ts), not to your custom preset that is imported into it. Trying to listen for updates to all dependencies of uno.config.ts doesn't seem to be very simple.

I'm not sure, but I think in general, custom preset usually would be another standalone library. So most people will not have a need to auto-reload presets. If you need to auto reload config like shortcuts, the easiest way is to write everything in uno.config.ts...

@KraXen72
Copy link
Author

the @unocss/config package has an option called configDeps - it already reloads the app when any file in this array is changed. maybe just use the same behaviour? it's a lot of work to implement some import resolution algorithm if the user defines the files the config depends on anyway.
It would be also great if the config documentation was updated to mention that the user needs to define this configDeps key, as it is currently not well documented.

@Tzyito
Copy link

Tzyito commented Aug 30, 2023

I found that when the custom preset rules are changed, hmr cannot be triggered. It may be that unocss does not monitor the changes of the preset files in config?

@Simon-He95
Copy link
Contributor

I think this issue could be closed

@zyyv zyyv closed this as completed Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants