Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to find the closest reference?(How to deal with values with duplicated names?)
How to find the closest reference? [message #707916] Tue, 02 August 2011 08:09 Go to next message
alex.ren2006 is currently offline alex.ren2006Friend
Messages: 46
Registered: June 2011
Member
Hi all, I am currently working on building an IDE for ATS (www.ats-lang.org). In ATS, the same name can be used for many times. For clarity of the problem, the sample grammar goes as follows:
=================================
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	name=ID '=' INT
	| name=ID '=' mcontent=[Greeting | ID]
	;
=================================
I also commented out the
=================================
composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
=================================
in the mwe2 file.

The corresponding source code would be like this
=================================
x = 3
x = 4
y = 4
z = x
=================================
When I Ctrl-Click on "z", it refers to the first "x", which is not what I want. Is it possible to make it jump to the second "x" which is the closest one to "z". Or is it possible to show another dialogue so that the programmer can choose? Either way is fine, any suggestion about how to do this based on Xtext is highly appreciated. Thanks a lot.

Re: How to find the closest reference? [message #708110 is a reply to message #707916] Tue, 02 August 2011 13:31 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

as far as I know there is no hook for "linking based on user choice". The linker will grab the first object of the scope that fits the name. So what you need to do is adapt the local scope provider, creating the scope yourself.
There you have two choices: either you make sure that each name appears only once, or the closer definition is found first. For calculating the distance, navigate to the node model and extract the offset of the parser node. You will find Node(Model)Utils helpful.

Alex
Re: How to find the closest reference? [message #708514 is a reply to message #708110] Tue, 02 August 2011 22:28 Go to previous message
alex.ren2006 is currently offline alex.ren2006Friend
Messages: 46
Registered: June 2011
Member
Thank you very much for your advice. I am now reading the ImportedNamespaceAwareLocalSpaceProvider. I think the easy way is to imitate it and then write my own CustomImportedNamespaceAwareLocalSpaceProvider. I am still a newbie to Xtext. Please correct if I am wrong. In the function
============================
protected IScope getLocalElementsScope(IScope parent, final EObject context,
			final EReference reference) {
=============================
I see the code
=============================
ISelectable allDescriptions = getAllDescriptions(context.eResource());
=============================
Does this "allDescriptions" contain all the nodes to create the scope?
Previous Topic:Finding references from builder
Next Topic:Help for grammar
Goto Forum:
  


Current Time: Wed Apr 24 13:41:13 GMT 2024

Powered by FUDForum. Page generated in 0.03333 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top