Language Injection - Can't enable new ones

 I created a new language injection that matches everything between <# and #>. The framework I am working with uses that to denote JavaScript in a few places.

 

Anyways, I see the Language Injections in the list of all of them, but every time I click the enable checkbox, nothing happens (i.e. it stays unchecked). Any ideas would be hugely appreciated!

10 comments
Avatar
Vladimir Luchansky
Comment actions Permalink

Hello,

After nothing happens, can you see any fresh errors in Help > Show Log in ... > idea.log?

0
Comment actions Permalink

There aren't any errors in there when I click the checkbox.

0
Comment actions Permalink

Please share the injection with us (you can export it via the tool button).

0
Comment actions Permalink

<LanguageInjectionConfiguration>
<injection language="JavaScript" injector-id="php">
<display-name>New Injection</display-name>
<value-pattern>\&lt;#((.|\n)*)#&gt;</value-pattern>
</injection>
</LanguageInjectionConfiguration>

That is the injection.

(sorry, not sure how to format that)

0
Comment actions Permalink

I have this issue as well, and still (Webstorm 2021.2)

Injection:


<?xml version="1.0"?>
-<LanguageInjectionConfiguration>
-<injection language="liquid" injector-id="js">
<display-name>Liquid javascript tag</display-name>
<prefix>{% javascript %}</prefix>
<suffix>{% endjavascript %}</suffix>
</injection>
</LanguageInjectionConfiguration>

As the OP says, the new injection simply can't be enabled. It's basically a disabled checkbox and I don't know why.

the {% javascript %} tag is new in Shopify liquid and it sure would be nice to see the stuff in between as javascript code.

0
Comment actions Permalink

@Sadamson 

1. Please show a screenshot of it (the Edit window for this rule).

2. Which language are you trying to inject and where (a code sample)?

3. Do you use Liquid or Twig plugin for this?

If it's Liquid (which makes sense) then AFAIK it does not yet properly support permanent injection rules. You can inject temporarily in the Editor (and it will last for the editing sessions) but that still may lack some functionality inside (e.g. proper formatter support etc).

Here you can check about injecting JSON into {% schema %}: this comment https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000366524/comments/4403007293586 and below

 

P.S. From what I see from your snippet / my understanding of it right now: this unlikely to be working this way.

P.P.S. Next time you better create a separate thread with you issue: it may be not relevant to the one that OP had.

0
Comment actions Permalink

Thanks for the update. I do use the Liquid plugin. The javascript tag is new with Shopify 2.0 (it combines and minifies at build time it seems).

After playing it seems like the field Places Patterns is required and leaving it blank makes the LI unselectable. (If that's the case it seems like it should be a required field?) I don't know what it's supposed to do but putting in a placeholder allows me to select the box. 

After it's enabled my code doesn't actually turn into javascript, but as you pointed out it might be the plugin. I've attached a screenshot of my LI in case you have some ideas for what should be in Places Patterns. To be clear, the one as defined in the screenshot does in fact allow you to select it but doesn't actually highlight the javascript. Any thoughts?

Sorry about the comment on a very old issue. My issue was exactly OP's and on forums like Stack Overflow you get in trouble for starting new ones.

 

0
Comment actions Permalink

@Sadamson

The Injection rule on your screenshot makes no sense to me. Right now I read it as "inject JS into JS and add fancy {% javascript %} {% endjavascript %} around it" (I say "fancy" because those tags are not JS at all and mean an invalid code in JS context).

jsLiteralExpression() makes sense in JS context only while you are in Liquid context (Liquid file)...

Right now you can try the manual injection as per my comment with step-by-step screenshots in the aforementioned link. At least you will have something for the session:

 

P.S. This is how you permanently inject JSON into {% schema %} when using Twig plugin instead of Liquid for .liquid files (Liquid has very similar syntax to Twig: you will have no code completion for Liquid tags/functions but at least will have syntax colors for tags).

To use the same but to have JavaScript in {% javascript %} tag -- just replace the injected language and tag name (once again: using Twig plugin for handling .liquid files)

 

As I have mentioned earlier: it does not look like Liquid plugin can provide permanent injections yet.

P.P.S. A general ticket for Liquid support (with links to other / specific tickets): https://youtrack.jetbrains.com/issue/RUBY-7210

0
Comment actions Permalink

Okay thank you. I guess I completely misunderstood what these are for. What I want is for my IDE to recognize code between "{% javascript %}" and "{% endjavascript %}" as javascript code. I thought that's what prefix and suffix meant. Sorry for the confusion. I'll check out your links, and I do know I can inject it per session but was hoping for something permanent.

0
Comment actions Permalink

Removing the liquid plugin and replacing it with the Twig plugin, associating liquid with the Twig plugin, and a pattern of

+ twigCustomStatement("javascript")

Did the trick. Thank you for the help. 

So the reason the Language Injection couldn't be enabled is that Places Patterns is required, and the reason it didn't work properly is because I was misunderstanding its function. But with your help I was able to make it behave the way I wanted. Thanks again!

1

Please sign in to leave a comment.