tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
485 stars 38 forks source link

fix emmet bug not inserting the correct template #31

Closed unlocomqx closed 5 years ago

unlocomqx commented 5 years ago

Somewhat hacky but should fix #19

Debug info below

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 screenshot_16

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

nightwolfz commented 5 years ago

@unlocomqx Could you release a jar somewhere with all your changes? I can't get anything to build (my knowledge of java = 0) and @tomblachut seems to be taking a long holiday

unlocomqx commented 5 years ago

I will merge my PR's in one branch and produce a JAR to have it installed. I need that as well

unlocomqx commented 5 years ago

@nightwolfz Upon testing with other PR's, this PR seems to break some functionality I will close it for now and look for a better way If @tiatin could provide an installable package from my install branch, that would be awesome I couldn't build because I ran into issues Here's the install branch https://github.com/unlocomqx/svelte-intellij/tree/install

tiatin commented 5 years ago

@unlocomqx - yesterday I already merged some your PRs (and I skipped this "emmet" one) into test branch https://github.com/tiatin/svelte-intellij. I also merged https://github.com/tomblachut/svelte-intellij/pull/18, but not sure if it is complete or not. And I also ran into issue with building. Reason was in old idea version. Updating versions fixed the build: https://github.com/tiatin/svelte-intellij/commit/92ef521815d2a93e19d77f0e6df64d743dc98616. And I created a release based on this test branch: https://github.com/tiatin/svelte-intellij/releases/tag/v0.7.1.

So far I can tell that your PR https://github.com/tomblachut/svelte-intellij/pull/30 seems not working (maybe https://github.com/tomblachut/svelte-intellij/pull/18 has influence on this, not yet sure): on:click is still highlighted with a tool-tip "Attribute on:click is not allowed here". But one thing was fixed for me: correct code formatting for {#each, {#if, etc. I guess adding "{" and "}" into <HTML_TAG> made parser to understand such constructions as HTML tags, and now auto-code formatting works fine with them.

I also have such strange issue: eachIssue

Also onClick It would be nice to have an option to navigate to openActivityPopup by ctrl+clicking it.

Later today I will build your install branch and will let you know, but I will update versions like this https://github.com/tiatin/svelte-intellij/commit/92ef521815d2a93e19d77f0e6df64d743dc98616 if you don't mind, otherwise I will fail to build.

Update: actually https://github.com/tomblachut/svelte-intellij/pull/30 works. Its goal was to fix {} without quotes but not on:click, so we are fine here.

tiatin commented 5 years ago

@unlocomqx @nightwolfz - release based on install branch: https://github.com/tiatin/svelte-intellij/releases/tag/v0.7.2. It has the same issues with store variables and on:click as in 0.7.1. But at least auto-tag-complete and auto-import-complete work.

unlocomqx commented 5 years ago

Thanks for the build, I will try your commit to successfully build it as well I couldn't figure out resolving JS references in attributes and interpolations because they're inside a CODE_FRAGMENT and I don't quite understand that part just yet Basically the IDE can't find JS Elements or HTML Elements inside the CODE_FRAGMENT, that's as far as I understood from debugging the API What's the issue which has most priority in your opinion?

tiatin commented 5 years ago

Code navigation is a nice feature, but I would update lexer in first priority to avoid incorrect syntax highlights. I will try to fix it myself as well. Thank you!

unlocomqx commented 5 years ago

I don't fully understand the lexer part just yet. If you make any progress, I will surely learn from it :))

tomblachut commented 5 years ago

@nightwolfz @tiatin @nightwolfz I'm back from the dead (actually from deadline at work but I guess it's the same). I have another upcoming deadline so it's not so great but I'll try to be responsive.

Let me know how can I help you understand codebase.

@tiatin about updating versions. It's strange, because for me it works. I wanted to lock versions so everyone will use the same build but maybe it would be better to use latest snapshot in light of your issues.

18 requied some testing. I didn't want to rush and break everyones IDEs.

unlocomqx commented 5 years ago

@tomblachut not to worry at all, I also get drowned in work sometimes so I know what it's like