Menus (Ctrl+Space)

Hi.

I'm a newbie and it seems that I'm a bit confused :)

I have a concept A with child concept B.
Concept B in its turn has an optional reference to concept A (i.e. [0..1]).

I'd like to create an editor for concept B with menu (Ctrl+Space) with list of all instances of concept A. If I have not optional reference, such a menu is generated automatically if I specify primary replace child menu.
But I don't get how to create it in case of optional reference.

Not sure if such description of my problem is clear :)
10 comments
Update: The problem is that I use editor component of concept B inside editor of concept A. It seems that editor components work in another, strange way.
0
Both cases (using components and not) work just fine for me. Maybe I'm missing a bit specific to your setup? Would you mind sharing the demo you have?

Here's the component definition I'm using for B:

editor component compForB            
  overrides:          
    <no EditorComponent>             
  applicable concept: 
    B  
       
  component cell layout:             
     [- ref: ( % a % -> { name } ) -]
prettyPrint();

Here's A's editor:

<default> editor for concept A       
  node cell layout:   
     [- A { name } with ( % b % -> # compForB # ) -]
       
  inspected cell layout:             
    <choose cell model>              
prettyPrint();

Vaclav
0
Ok. So here my version of this:

Concepts
A's Concept
concept A extends BaseConcept 
          implements INamedConcept           

  instance can be root: true 
  alias: <no alias> 
  short description: <no short description> 
 
  properties: 
  << ... >> 
 
  children: 
  b : B[1] 
 
  references: 
  << ... >>
prettyPrint();

B's Concept
concept B extends BaseConcept         
          implements <none>           
        
  instance can be root: false 
  alias: <no alias> 
  short description: <no short description> 
 
  properties: 
  body : string 
 
  children: 
  << ... >> 
 
  references: 
  a : A[0..1]
prettyPrint();


The important part is that B has [0..1] reference to A, not [1].

Also I have such component

B's component editor
editor component compForB 
  overrides:              
    <no EditorComponent>  
  applicable concept:     
    B      
           
  component cell layout:  
     ( % a % -> { name } )
prettyPrint();

And finally the editor, where I use it:

A's editor
<default> editor for concept A             
  node cell layout:         
     [/      
      { name }              
      <constant>            
      [> ( % b % -> # compForB # ) and its body: ( % b % -> { body } ) <]
     /]      
             
  inspected cell layout:    
    <choose cell model>     
prettyPrint();

And the result in sandbox solution:

In first case it just shows B node in autocompletion list (and it seems that nothing changes if I choose it)
mps_playground1.png


If I change the reference in B from [0..1] to [1], i.e. from "B may have a reference to A" to "B must have a reference to A", then we have the following:
mps_playground2.png


My question is: how can I make such a menu but with optional reference to A? Or I just simply don't get something?
Sorry for a long post :) I hope, the definition of my problem is clear. I can create a full project with this example if it's needed.
0
The first completion menu contains an entry "B", which means that Test1 does not currently hold any child B and so MPS prompts you for picking B or any of its potential subconcepts to instantiate. Although you have not mentioned that, I assume the cardinality of B in A is [0..1]. Is that right?

In such case this is standard and correct behaviour - you first need to create a B child, so you could make it refer to an A in a second step. I expect that after you select the B in the menu, you get a second completion menu with the correct (A) items.

If you make the cardinality of B in A [1], MPS will create an instance of B for each created A automatically and so you avoid the first completion menu.
If instead, as you tried, make the cardinality of A in B [1], MPS will treat B as a "Smart reference" and thus populate the completion menu with possible As, even if there's no B in your current A. B becomes somewhat invisible.
0
Although you have not mentioned that, I assume the cardinality of B in A is [0..1]. Is that right?

No, the cardinality of B in A is [1]. So each A always has B-child. I've put my declarations of concepts A and B in my previous message under the {cut}. Please, take a look on it.


I expect that after you select the B in the menu, you get a second completion menu with the correct (A) items.

Unfortunately, no. Selecting of B changes nothing.
0
And one more thing:

If I use concept editor instead of editor component, everything is OK. I can make a repo with example.
0
Please do share the project. I seem to be doing exactly the same thing without any issues.
0
I've extended my example a bit to show the difference. So right now I have the following behavior:

mps_playground3.png


You can find my whole project here: https://bitbucket.org/gooroo/mps_playground
I've commited all the stuff (source_gen, caches etc.)
0
Ok, the crucial difference is that your compForB uses the "( % parent % -> { name } )" cell as the root of the editor component. So the cell serves two purposes - it represents the whole B instance and it also represents the "parent" reference.

When pressing "Control + Space" on the cell MPS prefers to offer substitutions for B (replacing the B instance with a new one) instead of showing the completion menu for the "parent" reference inside B. This is one of heuristics that MPS uses to be more in-line with typical usages.

A solution for your case would be to wrap the cell in a collection cell and prepend it with a transparent constant cell:
[- <constant> ( % parent % -> { name } ) -]
prettyPrint();

where the constant cell has the following properties to become invisible:
Style:     
<no base style> {         
  selectable : false      
  punctuation-left : true 
  punctuation-right : true
}          
prettyPrint();

Vaclav
0
I would never solve this issue without your help. Thanks a lot. Everything seems to be working fine now.
0

Please sign in to leave a comment.