How cross-reference is found by Xtext? [message #714863] |
Thu, 11 August 2011 16:20 |
alex.ren2006 Messages: 46 Registered: June 2011 |
Member |
|
|
I am currently building an IDE for ATS (www.ats-lang.org). I get into some trouble in dealing with cross-reference. The following is my guess of the mechanism of cross-reference in Xtext. Please correct me if I am wrong. Then I may stand a better chance to solve the problem I am facing now.
In my mwe2 file, I use the default "fragment = exporting.QualifiedNamesFragment {}". So I think Xtext actually finds the reference by comparison of names.
Once I Ctrl-Click on certain element of the source code, Xtext will
1. get the full name of the element such as scope01.scope02.obja.
2. get the scope of the element (the scope may contain nested scope).
3. compare the name of the element (scope01.scope02.obja) to the names of the objects in the scope. The comparison appears in the following steps
1) try to find the ojbect with name "scope01.scope02.obja". If it failed, then go to step 2), else that's the reference we need.
2) try to find the object with name "scope1.obja". If it failed, then go to step 3), else that's the reference we need.
3) try to find the object with name "obja". If it failed, then reports that no reference is found, else that's the reference we need.
Is my guess correct? Can anyone point to me which part of Xtext code is for looking up cross-reference? (Is there any design document which can assist me to read the Xtext source code?) Thanks a lot for your advice in advance.
[Updated on: Thu, 11 August 2011 16:20] Report message to a moderator
|
|
|
Re: How cross-reference is found by Xtext? [message #714908 is a reply to message #714863] |
Thu, 11 August 2011 18:13 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
Hi,
there is the Xtext documentation, several blog entries by the Xtext developers, many threads in this forum. Also, I started working on a series of blog entries on cross referencing in Xtext. Scopes and and qualified names are related but not identical. The qualified name is composed based on the names in the containment hierarchy of the element.
If you do Ctrl-Click all the work (the linking) has already been done, i.e. the linked object is already known (URI) and can be opened. The fun part happens before. The essential part is the scoping. Basically the scope provides a lookup mechanism for visible elements mapping names (simple or qualified, with/without imports) to the corresponding object(description)s.
Step 1 is "incorrect" already. If you have a cross reference, Xtext will not restore the full name, but rather search the scope for exactly that name (possibly taking name space imports into account). An object may be contained in the nested scope under several names.
Take the standard entity example. An entity X has attributes att1, att2. Within that entity the attributes are visible via their simple names (att1, att2) and due to the outer scope via their long names (X.att1, X.att2) as well. Outside that entity, they are visible via their long names.
It is easiest to help, when you tell exactly what the problem is (here is my grammar, here is a sample of the model where linking does not work as expected, I get the following error message - I don't understand it/I understand it but do not know what to do about it).
Try out the concept in a toy project first. This will help you concentrate on the actual problem. Maybe it is a grammar problem, maybe a naming problem, maybe an import problem or you really need to adapt the scope provider.
Alex
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.02909 seconds