Skip to content

VSCode Extension: Errors/Warnings don't refresh (or are incorrect) if there is an unused CSS selector, when using PostCSS #1019

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

Closed
danieldiekmeier opened this issue May 22, 2021 · 7 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@danieldiekmeier
Copy link
Contributor

Describe the bug

I stumbled over a weird error, where the errors/warnings (aka the yellow and red squiggly lines in the editor) are not updated (or are incorrect), if I use svelte-preprocess with PostCSS and have an unused Selector in the CSS.

Screenshot so it's a bit clearer what I'm talking about:

My svelte.config.js:

const preprocess = require('svelte-preprocess')

module.exports = {
  preprocess: preprocess({
    postcss: true,
  }),
}

Example component:

<script>
  const a = 10
</script>

<div>{a}</div>

<style>
  .unused {
    background-color: red;
  }
</style>

The bug doesn't happen if I comment out postcss: true. I tried removing all my PostCSS plugins, but that didn't change the behavior. Additionally, I noticed that I don't actually get a warning for the unused CSS selector in VSCode at all. (I do get it when I run svelte-check, so the basic functionality should be there?)

I hope I provided any relevant information here, but I'm glad to clarify anything that's unclear.

To Reproduce
Steps to reproduce the behavior:

  • Configure svelte-preprocess with postcss: true
  • In a Svelte file, use a <style> tag that contains at least one unused CSS selector
  • Edit the rest of the file in a way that should produce a warning
  • Thy typical helpful warnings and errors will not refresh, or they'll show an Unexpected token error in unexpected places

Expected behavior

  • Errors and warnings should work in exactly the same way as they do when no unused selector appears in the <style> tag

Screenshots

Toggle, because they are pretty large

I start from this working example: Svelte can correctly identify that I did in fact define a before using it. It can also tell that the div is a used selector in this context.

image

And if I change the variable name from a to b, it correctly warns me:

image

If I then change the CSS selector to something that's not used in the component, it still warns me:

image

But if I then change the variable name back from b to a, it still warns me:

image

In fact, it will not correctly refresh the warnings/errors and be pretty confused, no matter what I do:

image

System

  • OS: macOS 11.3.1
  • IDE: VSCode 1.56.2
  • Plugin/Package: Svelte for VSCode v104.12.2
@danieldiekmeier danieldiekmeier added the bug Something isn't working label May 22, 2021
@madupuis90
Copy link

I'm having the same problems. Random typescript errors that were only fixed when I commented my scss styles.

unknown

<style lang="scss">
  @import "bulma/bulma.sass";
</style>

@jasonlyu123
Copy link
Member

jasonlyu123 commented May 25, 2021

The cause of this seems to be because some svelte diagnostics, like unused-export-let or css-unused-selector, can't be source mapped back to the original position. But there might be multiple causes of the source mapping issue. I think we can at least place it at the start of the file to avoid diagnostics not getting updates.

@dummdidumm
Copy link
Member

I can't reproduce this yet. What I see though is that because of postcss: true, the source maps are messed up (guess we can't do much there if no proper source map was provided). I don't get unmapped/negative lines through that though.

@jasonlyu123
Copy link
Member

A preprocess without a source map might reproduce the problem I mentioned.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue May 28, 2021
Try to catch some cases of invalid ranges which may cause the LSP to get confused and not update diagnostics anymore
sveltejs#1019
dummdidumm added a commit that referenced this issue May 28, 2021
Try to catch some cases of invalid ranges which may cause the LSP to get confused and not update diagnostics anymore
#1019
@dummdidumm
Copy link
Member

Version 105 of the extension was released where I tried to be more robust about possibly invalid mappings. Please let me know if that fixed it or if the issue still persists.

@danieldiekmeier
Copy link
Contributor Author

Looks good! The warning does show up now, and I can still edit the rest of the files as before. Thanks for looking into this!

image

@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label May 28, 2021
@madupuis90
Copy link

Version 105 seeems to fix my issue too. Thanks for the quick fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

4 participants