RubyMine 2016.2 Help

Using Language Injections

In this section:


RubyMine makes it possible to work with islands of different languages embedded in the source code. You can inject other languages into string literals. This can be done within the source code written in most (but not all) of the supported languages. The typical examples are HTML fragments injected into JavaScript code, SQL statements in XML, and so on.

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.


Before you start working with language injections, make sure that the IntelliLang plugin is enabled. The plugin is bundled with RubyMine and is activated by default. If it is not, enable the plugin as described in Enabling and Disabling Plugins.

Injecting a language into the source code and cancelling language injection

To tell RubyMine 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, RubyMine, 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 Injections 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.

For example, SQL injection in JavaScript code will look as follows:

var i; for (var j=1;j<10;j++){ var s= "SELECT * FROM A WHERE B=C"; }

To cancel language injection, choose the intention action Un-inject Language/Reference.

Moving injections between the IDE and the project levels

User-defined injections are assigned either to the IDE or the project level. The IDE-level injections are available in all of your projects. The project-level injections can be used only in the project in which they are defined.

To move the injections between the IDE and the project levels, use the Move to Project/IDE Scope icon  icon_injection_move_to_project_make_global  on the Language Injections page of the Settings/Preferences dialog.

The built-in injections are the IDE-level ones, and their scope cannot be changed.

See Also

Last modified: 1 September 2016