Comments (13)
I was able to suppress this error cheaply with HighlightErrorFilter
Keep in mind there are more complicated cases than one word interpolation and they are still broken
from svelte-intellij.
<div class="counter-digits" style="transform: translate(0, {100 * offset}%)">
This line from the official SvelteKit demo project results in a mis-parse, I'm assuming this is one of the more complex cases you were talking about. Is there any workaround for this currently?
from svelte-intellij.
Fixed in WEB-59773 Svelte: "mismatched parameters" error when using variables as function arguments in inline style
from svelte-intellij.
Oh my... this is actually parser error, not an inspection, which is even harder to fix.
This would require overriding at least CSS parsing only for inline styles
com.intellij.psi.css.impl.parsing.CssParser2#createTermExpectedErrorElement
from svelte-intellij.
Maybe Vue plugin will save us as always, I will try to find what they do with :style
attributes
from svelte-intellij.
This is more complicated than that. As far as I know you can't interpolate string attributes in Vue. Attribute value is either JS expression or string, which is then handled specially by IntelliJ for style and event handler attributes.
In Svelte case you can do basically whatever you want, and CSS parser sees only opacity:
. Try to write that inside normal CSS file and you'll get the same error.
from svelte-intellij.
I see, so inline styles parsing should be enhanced allowing arbitrary JS expressions inside {}
from svelte-intellij.
hmm, I see two options here, correct me if I'm wrong please, this is all guesswork.
- We disable css parsing of
style
attributes, treat it as a normal attribute. - We try to interpolate the variable and pass it to the css parser? If this is even possible.
from svelte-intellij.
- It could work for now. We could even detect interpolations and disable CSS parsing only when they are present to avoid conflict. I like to write inline styles from time to time and CSS parsing is valuable.
- More like @AleksandrSl has said, disable parsing of curlies inside style tag on HTML level and override CSS parsing so curlies are handled there.
- There's a flag
strict
inside CSS parser. It's set to true by default, changing it hides those errors, but AST will be still wrong so CSS inspections etc. may fail
1 & 2 will require a lot of if statements :)
from svelte-intellij.
Cool, @tomblachut can you show me where can I disable the strict
flag in the code? I can help test it out to see any problems. Thanks.
from svelte-intellij.
@shirotech The short answer is that I don't know :)
It works like this: IntelliJ has decoupled lexing and parsing. Lexing is more basic, converts characters into tokens like keyword or number. What's interesing, there's something called lazy parseable tokens, or chameleons. CSS inside HTML is lazy parseable.
You need to check how SvelteHtmlLexer decides which classes to use when encountering style
attribute. It's somewhere in superclasses. It's important to only change inline styles, not the style tags. Good starting point is com.intellij.lexer.HtmlLexer#ourInlineStyleElementType
. It's private static so unfortunately it can't be just overriden.
Then you'll probably need to create dedicated element type, you can check SvelteJSLazyElementType
for inspiration, or look for something that has CSS in the name. I think default is com.intellij.psi.css.impl.CssElementTypes.CssDeclarationBlockElementType
In said element you can define which parser class is used to parse inline CSS. By default it's very roundabout. Token has Language
bound in constructor. Language
has associated ParserDefiniton
.
com.intellij.lang.css.CSSParserDefinition#createParser
returns com.intellij.psi.css.impl.parsing.CssParser2
. It needs to be replaced in lazy element type with something that ignores errors (check com.intellij.psi.css.impl.parsing.CssParser2#createErrorElement
)
I know this is monumental work if it's your first time with IntelliJ SDK. Good luck. I realised even more how complicated is that after writing this comment.
from svelte-intellij.
I was able to suppress this error cheaply with
HighlightErrorFilter
Keep in mind there are more complicated cases than one word interpolation and they are still broken
How does one go about using that Filter?
from svelte-intellij.
How does one go about using that Filter?
it works automatically but covers only simplest cases
from svelte-intellij.
Related Issues (20)
- Generated types dir is not recognized in Svelte compoenents HOT 6
- Update SvelteJSReferenceExpressionResolver for 223 intellij branch HOT 1
- Comment with Line Comment broken for <script> section of .svelte files HOT 3
- Support NPM Workspaces for "Go to Declaration" HOT 1
- Add support for `context="module"` HOT 2
- Add support for @const HOT 1
- delete is not highlighted as a keyword in "<script>" block HOT 3
- Support for "endpoints" tool window integration HOT 1
- Auto-import does not emit `import type` for types HOT 1
- "Rename" refactoring HOT 1
- destructed exports are not suggested HOT 1
- typescript declarations not working correctly for derived stores. HOT 1
- Unresolved variable for store when using TypeScript HOT 2
- No errors on missing 'type' imports HOT 2
- type errors not showing on component props HOT 2
- Exported functions from initialized components are "unresolved" HOT 4
- `typeof` not hinted/colored in Svelte files HOT 1
- Reference to `./$types` does not work in .svelte files but works in .ts files HOT 6
- Importing files with extension .js instead of .ts HOT 3
- Update on plugin release schedule HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-intellij.