Home » Modeling » TMF (Xtext) » Narrowing content assist choices(XTetxt : Filter proposed choices)
Narrowing content assist choices [message #558169] |
Fri, 10 September 2010 12:00 |
Jerome Messages: 5 Registered: September 2010 |
Junior Member |
|
|
Hello,
I am new to XText and I'd like to do a sort of Ctrl+Space choice filtering with that (very nice ) plugin. Until now, I haven't found a way to make it.
Let's keep it simple and take an example. I want to use Xtext in order to provide content assist with this kind of text:
Classroom B442 has students:
Annie present
Bob missing
Zoe present
{Bob, Job, Annie} are possible choices and {absent, present} are their possible state.
Until now it's okay, we found our way and managed to write the xtext grammar, scope provider...etc.
But I want to narrow the choices proposed by Ctrl+Space when encountering a student.
In the classroom example, we could decide to fill the presence sheet alphabetically and have all the students listed. When doing Ctrl-space for the Nth student choice, I want content assist to propose only the Nth. That way, after Annie, the only viable (and possible) choice is Bob.
So my grammar looks like that:
InputClassroom:
'Classroom ' classroomName=[ClassroomDefinition] ' has students : '
(students+=InputStudent)*
InputStudent:
chosenStudent=[StudentDefinition] state
enum state:
' present ' | ' missing '
ClassroomDefinition:
'Classroom ' classRoomName=ID
(classroomStudents+= StudentDefinition)*
StudentDefinition:
'Student ' studentName=ID
And the database looks like:
Classroom B442
Annie
Bob
Zoe
Student Annie
....
Student Bob
...
Student Zoe
...
In order to narrow the choices, I modified the scope provider that way:
public IScope scope_ InputStudent _ chosenStudent (InputStudent inputStudent, EReference ref) {
StudentDefinition nextStudent = ((InputClassroom)inputStudent.eContainer()).getClassroomDefinition(). GetClassroomStudent ().size()-1);
@SuppressWarnings("unchecked")
EList<EObject> choices = (EList<EObject>) Proxy.newProxyInstance(Student.class.getClassLoader(),
new Class [] {EList.class}, new InvocationHandler() {
private List< StudentDefinition> list = new ArrayList< StudentDefinition> ();
@Override
public Object invoke(Object obj, Method meth, Object[] args)
throws Throwable {
return meth.invoke(list, args);
}
});
choices.add(nextStudent);
return Scopes.scopeFor(choices);
}
Okay it's a bit dirty and it's doing half what I expected... It's not compliant with the validation process of Xtext (which seems to call that scope method). When we have more than one student in the classroom, little red cross will appear in the editor for the first one. That makes sense because I check the number of already provided students to propose only one possible choice... but then, how can I modify my grammar / scope provider or else in Xtext in order to have this behaviour ?
Thanks a lot, Jérôme
[Updated on: Fri, 10 September 2010 12:05] Report message to a moderator
|
|
| | |
Re: Narrowing content assist choices [message #558290 is a reply to message #558192] |
Fri, 10 September 2010 20:06 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
Hi Meinte,
I did not say that modifying content assist changes the language. I argued that in order to get the wanted content assist you should not necessarily restrict the semantics of the language.
As I understand the example, it really does not matter in which order the students are listed (i.e. all are visible from everywhere within the classroom), but the user might always want to place them in alphabetical order, so that a corresponding adaption to the content assist would make sense.
It would not be sensible to change the scoping for that. As hinted, links will be broken, once the list of student changes etc. Taking a far fetched java analogon: how would you feel about not being able to navigate to an interface your class is supposed to implement, just because some of the required methods are missing? The interface is still visible, only some constraints are not yet met.
I propose the same thing: let all the students be visible, but make content assist smarter.
By the way, scoping and content assist are usually not smart enough by default not to allow for multiple references to the same object. Although this may be a semantic requirement of your language, you would not use scoping to take care of that but rather have a validation rule.
Alex
|
|
| | |
Re: Narrowing content assist choices [message #558608 is a reply to message #558169] |
Mon, 13 September 2010 16:36 |
Jerome Messages: 5 Registered: September 2010 |
Junior Member |
|
|
Thanks for these replies. You are right, customizing the "scoping" that way produces an incoherent set of data in Xtext workflow and could trigger many problems :s
From my understanding, scoping is providing a set of possible values and content assist is relying on these values to display it on the GUI. Is that correct ? Therefore, where could I (find) override or extend the content assist and define my narrowing rule ?
I find Xtext's documentation a bit difficult (at least for an Xtext beginner), so my question may look stupid
So, If I understood, my scope provider will allow all the valid values (all students) and my content assist will propose the user a reduced (but still valid) choice (only the next student in the alphabetical order).
Then, the validation process will have to take into account that new rule in order to make sure that the user chose the student by alphabetical order. Then, where do I customize that validation ?
Thanks, Jerome
|
|
| | | |
Goto Forum:
Current Time: Fri Apr 26 05:35:29 GMT 2024
Powered by FUDForum. Page generated in 0.03206 seconds
|