On this page:
- Injecting a language into the source code and cancelling language injection
- Toggling between global and project injections
Learn more about language injections from the following pages in this part:
Before you start working with language injections, make sure that IntelliLang plugin is enabled.
The plugin is bundled with WebStorm and activated by default. If not, enable the plugin as described in Enabling and Disabling Plugins.
When the editor recognizes a string as a language injection:
- Syntax and error highlighting and coding assistance are extended to this string.
- You can open and modify it in a separate tab in the editor,
as if you were working with the source code in the corresponding language.
To open an injection in the editor, use the Edit <Language> Fragment intention action.
Injecting a language into the source code and cancelling language injection
To tell WebStorm that certain text should be treated as an embedded source code fragment, you can use:
- The Inject Language/Reference intention action, which is applied to a particular string:
After that, you have to select the desired language from the menu:
Note that if you use this method, it’s possible that the string literal will stay marked as a language injection only within a limited period of time. That is, WebStorm, at a certain moment, may "forget" that the corresponding literal is a language injection. The period of the injection "persistence" will depend on the language, context and the modifications that you make in other parts of your source code.
- The Language Injection page of the Settings dialog.
By creating new language injection configurations on that page, you can specify that a certain method parameter, text in an XML tag, or XML attribute should always
be treated as an embedded source code fragment in another language.
WebStorm comes with a set of predefined injection configurations which is quite sufficient to ensure high productivity and comfortable environment. Therefore it is strongly recommended that you use the predefined injection configurations and avoid creating new ones.
To cancel language injection, choose the intention action Un-inject Language/Reference.
Toggling between global and project injections
WebStorm distinguishes the project and global states of injection configurations.
- Character strings configured as project injections are treated as source code only within the current project.
- Character strings configured as global injections are treated as source code at the WebStorm level, that is, within any WebStorm project.