Comments (14)
Here's some debug info
In
com.intellij.codeInsight.template.emmet.XmlEmmetParser#getDefaultTemplateKey
then
com.intellij.codeInsight.template.emmet.ZenCodingUtil#isHtml
,
the language is checked and must be HTML or XML and so on
To pass that condition, you need to override getBaseLanguage
in SvelteLanguage
and return HtmlLanguage.INSTANCE
Even so, emmet fails because it creates the wrong dummy file type (SvelteFile instead of HTML File)
This is because it reads the file language (which is SvelteLanguage) and doesn't look for a base language that is HTML
So then com.intellij.codeInsight.template.emmet.tokens.TemplateToken#getXmlTag
fails to find the XML tag that was added dynamically and null is returned
So basically com.intellij.codeInsight.template.emmet.tokens.TemplateToken#setTemplateText
should use the HTML language instead of the file language which it gets through callback.getFile().getLanguage()
Or we should find a way to allow PsiTreeUtil
to find an XmlTag
inside HTML_FRAGMENT
elements
from svelte-intellij.
@unlocomqx thx to your finding about setTemplateText
I managed to do something
For example
<ul>
{#each assets as {title} (a.id)}
.header
{/each}
</ul>
Is expanded into
<ul>
{#each assets as {title} (a.id)}
<li class=""></li>
{/each}
</ul>
So finding a parent works even across Svelte outer fragments which is great. Expanding if blocks etc. still works. Figuring out how to fix complex emmet patterns will be easy enough I hope.
My approach revolves around updating SvelteZenCodingGeneratorImpl
override fun createParser(tokens: MutableList<ZenCodingToken>?, callback: CustomTemplateCallback, generator: ZenCodingGenerator?, surroundWithTemplate: Boolean): EmmetParser {
return XmlEmmetParser(tokens, SvelteZenCodingCustomTemplateCallback(callback), generator, surroundWithTemplate)
}
class SvelteZenCodingCustomTemplateCallback(callback: CustomTemplateCallback) : CustomTemplateCallback(callback.editor, callback.file.viewProvider.getPsi(HTMLLanguage.INSTANCE))
Notice that I overrode PsiFile in callback to always be HTML one.
from svelte-intellij.
In #40 I've changed how whitespace is parsed.
Now it's delegated to HTML side with notable exception of continuous whitespace between Svelte mustaches and first non-whitespace HTML character, it's required for current (bad) implementation of formatter to work.
Anyway that fixed Emmet partially.
Preview still does not work with the last character in a file. Add one space after Emmet shorthand and everything starts to work. Anyway you can expand shorthand and it works in both cases.
Remaining unsolved issue is shorthand directly after Svelte mustache. I suspect this is connected to mentioned whitespace handling and by extension formatter. Edit. No it doesn't. Mustaches live in different PSI, that must be an issue.
from svelte-intellij.
I was able to reproduce,
It's not a big deal really but I will try to debug it sometime nonetheless
from svelte-intellij.
Really weird, thanks for raising!
from svelte-intellij.
Brilliant
I will try to figure out why it doesn't assign the attribute value correctly
from svelte-intellij.
I did some debugging and found that this line gets the Psi File with Svelte Language when cursor is inside a Svelte Fragment
TemplateManagerImpl.java:253
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, myProject);
That file is used to instantiate CustomTemplateCallback in
TemplateManagerImpl.java:263
CustomTemplateCallback templateCallback = new CustomTemplateCallback(editor, file);
(is there a way to override that?)
Then a dummy file is created using Svelte Language here
GenerationNode.java:274
PsiFile dummyFile = fileFactory.createFileFromText(...
In the next line PsiTreeUtil.findChildOfType can't find the tag and null is returned which prevents entering the if which contains a call to setAttributeValues
from svelte-intellij.
That's great
IMO, the edge cases are not severe
This one is because the document ends with a SVELTE_FRAGMENT
from svelte-intellij.
@unlocomqx in branch with lexer fixes document actually ends with XmlToken
from svelte-intellij.
I just tested with rework-lexer, it worked correctly
from svelte-intellij.
yeah it expands correctly but preview does not work for me as shown in screenshot
from svelte-intellij.
Sry for the confusion, how do you get the preview to pop up? is it automatic?
from svelte-intellij.
No worries. You need to enable it and then it's automatic
Actually I find it useless but users can expect it to work
from svelte-intellij.
As I expected, it's the same as this
Then a dummy file is created using Svelte Language here
GenerationNode.java:274
PsiFile dummyFile = fileFactory.createFileFromText(...
In the next line
PsiTreeUtil.findChildOfType
can't find the tag and null is returned which prevents entering the if which contains a call tosetAttributeValues
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.