Editor Component for code Fragments


For a Finite-State-Machine-Editor-Plugin I need some editor components that handles the code that shall be executed on transitions/entry/exit/conditions etc.  All the code stuff that is e.g. described in the W3C-SCXML standard.

Clearly I also want syntax highlight and completion. But this depends on the code of the whole FSM, which shall not be shown to the user. I guess that a LanguageTextField would be a good choice for such component. 

Perhaps I can use language injection to give the editor the whole code around these code fragments. 
Or somehow restrict the LanguageTextField to only the relevant part of the document.

What would be a way to configure a LanguageTextField such way? 
Or is there a better way to archive this?

Regards, Bernd


Hi Bernd,

Sorry, but it's unclear what you want to achieve. What editor components do you need? Where do you want to see/use them? What does it mean that “components handle the code that shall be executed on transitions/…”? What is the code of the whole FSM? Is it something like a standard library code?

Could you please provide some examples of the expected behavior? Are there similar existing features in the IDE or other plugins you can refer to?


Hi Karol!

Thanks for you time!
Hardest part of SW is to understand what the users wants and what he really needs :)

I don't know any plug-in that does something similar.  
I know that Qt creator has a similar editor: https://doc.qt.io/qtcreator/creator-scxml.html

I will try to explain in more detail.
As I mention I plan to create an editor-component for “executable content” in SCXML (a notation that defines Harel Statecharts). You can take a look into the spec for the “executable content”-part from W3C (only if your have to much time ;): https://www.w3.org/TR/scxml/#executable 

Short: SCXML defines a data-model which supports execution of expressions and scripts. 
The source code of these expressions or scripts is embedded in the XML. 
The code have access to the data-model declarations and possibly other stuff from the platform of the data-model. The language of this code can by a script-language like ECMAScript or any other supported language (with some help from a code-generator).

QT e.g. has a “c++ Datamodel”. https://doc.qt.io/qt-6/qscxmlcppdatamodel.html
I as a JVM-human want to support JVM languages :)

A simple code fragment would look similar to this 

“count” would be declared somewhere else in the data model. 

<data id="count" expr="0"/>

For Java “count” would be declared as member in the generated class. For ECMAScript “count” will be some global data definition. In both cases I plan to add these declarations to the code “around” the injection. The user shall not see this if entering the code for the script element, but getting auto-completion and syntax validation.

Inside the standard XML-editor I can use language-injection for these xml-elements as normal, providing the declaration + platform code “around” the script-fragments to support auto-completion etc. I tested this, it works fine. 
But editing SCXML as XML code is not very satisfactory.

I want to create a separate editor-component to edit one of these code-fragments in or beside a graphical editor. So I have no XML around the scripts to inject anything. 

With normal language-injection I would need a “empty” language (guessing) in which I can inject. But this sounds silly and I don't know if this would work correctly at the end. 

Any ideas? 
E.g. any way to give the code around the fragments to a LanguageTextField?

Best Regards and happy new year :)



Hi Bernd,

Thanks for the clarification. 

As far as I understand, you want to have a custom graphical editor with a diagram of states and transitions. Each state may contain Java code to execute, and you want to have the possibility of editing this code from states, either in the graphical editor or at the side in additional editor.

You most likely will need to implement a custom com.intellij.openapi.fileEditor.FileEditorProvider.

You can find example graphical editor implementations similar by browsing existing plugins implementing custom editors:

I'm not sure what would be the best way to provide implicit class and members definitions. Implicit members can be provided by com.intellij.psi.augment.PsiAugmentProvider in the existing classes, but it doesn't seem applicable in your case, as you rather need to wrap an expression into an implicit class.

Your proposal with an “empty” language doesn't sound that silly, in my opinion. You could create your custom host language and inject wrapping code with https://plugins.jetbrains.com/docs/intellij/language-injection.html#multihostinjector which I guess you tried already for XML. I don't see any potential issues with this now, but I can't guarantee it will work. Proof of concept shouldn't be hard to implement.


I haven't read this whole thread in detail, so sorry if I've missed something, but in my plugin I create synthetic classes using com.intellij.psi.impl.source.PsiExtensibleClass whose JavaDoc states: “A class which may be extended via com.intellij.psi.augment.PsiAugmentProvider”. I don't actually use it with PAP, I use com.intellij.psi.impl.light.LightFieldBuilder and friends (see the other classes in the package) to fill in the details of the class. But either approach might be useful for you.


Hi Colin!

I don't get the idea how adding PSI-elements to a class may help to create a editor for code-fragments.  Can you give me some more insides?

Best Regards,