How to Create a basic Plugin in MPS and run it on MPS

Hi All,

I am a newbie in MPS and playing with it to create a DSL on my existing Java API. I want to create a basic plugin to handle my DSL which can run inside MPS. Is there any tutorial or wiki to see how to create a plugin and run inside MPS.
Cheers
Kunal
12 comments
Hi Vaclav,
Thanks for the quick reply.
The link you gave shows more of building a Plugin Solution but
I am looking for sample examples/code to hook a plugin/bind a plugin on some key events such as Ctr+S . To be more clear how to write a hello plugin on which if a user presses Ctr+s, hello should be displayed on console.

Cheers
Kunal
0
Hi Vaclav,
Thanks for the URL, I went through it and managed to add few actions. Out of that I am facing some difficulty in writing some code inside execute(event) block of Actions section.

I am trying to Sysout some string inside execute(event) block but I cannot see any message , Can you help me as if I am missing something


action TestAction {         
  mnemonic: <no mnemonic>   
  execute outside command: false            
  also available in: << ... >>              
              
  caption: Save Model        
  description: <no description>            
  icon: <no icon>            
              
  construction parameters   
    << ... >>
              
  action context parameters ( always visible = false )     
    << ... >>
              
  <update block>            
              
  execute(event)->void {
System.out.println("Action Invoked");
     
     
     
}
              
  additional methods         
              
  << ... >>   
}     
Cheers
0
System.out would print to the standard output, which is not bound to the MPS Messages tool window, so you cannot see it.
Use the logging statements from the jetbrains.mps.baselanguage.logging language, instead, such as info "" or warn "".

Vaclav
0
Hi Vaclav,
I am adding log and info to print the logs but I cannot see them either in MPS Messages View or mps.log file. Do I need to some additional steps to view the logs ?FYI I already added
BasicConfigurator.configure(); in the code.

Please suggest.

Thanks
0
Does invoking the Tools -> Reload All Classes menu item after you add the log statements and rebuild the language/solution help? Or restarting MPS?
0
Hi Vaclav,

Thanks for the quick reply. I did Reload Classes from Toolsmenu after I have added the log statement or Restarted MPS and what find only 1 log to be displayed for the below code Snippet that I added in Action of My Plugin. The Line that gets displayed is INFO-editableSModel  and after there is no log even when I add new Node or Remove Node or press Ctrl+S to save Model. Do I need to do anything else?
Below is Code Snippet:
execute(event)->void {
BasicConfigurator.configure(); 

SModel model = this.context.getModel(); 
if (model instanceof EditableSModel) { 
  info "editable SModel"; 
  EditableSModel model1 = (EditableSModel) model; 
  model1.addChangeListener(new SModelChangeListener() { 
    public void nodeAdded(SModel p0, SNode p1, String p2, SNode p3) { 
      
      info "Node is Added"; 
    } 
    public void nodeRemoved(SModel p0, SNode p1, String p2, SNode p3) { 
      info "Node" + p1.getName() + "is Removed"; 
      
    } 
    public void propertyChanged(SNode p0, String p1, String p2, String p3) { 
      <no statements> 
    } 
    public void referenceChanged(SNode p0, String p1, SReference p2, SReference p3) { 
      <no statements> 
    } 
  }); 

}
prettyPrint();

Thanks
Kunal
0
The code works just fine for me. Are you sure you are adding the nodes to the model that has the listeners attached?
0
Vaclav, Here in the above code :
EditorContext context key: EDITOR_CONTEXT required
SModel model = this.context.getModel(); 
prettyPrint();

I am adding Node to Constant Sandbox,Btwn this should work on all Models as the Context is Editor and what ever Model is represented on Editor, it should trigger the Underlying Actions of Plugin, Right?
0
Yes, since you are registering the listeners with the model retrieved from EDITOR_CONTEXT of the action, i.e. the model containing the node, on which you invoked the registering action, you will be notified whenever this particular model changes.
0

Please sign in to leave a comment.