Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » reducing cross reference to current DSL file(how can I narrow the content assist to crossreference only objects of the current DSL file)
reducing cross reference to current DSL file [message #1229358] Thu, 09 January 2014 09:25 Go to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
I have a grammar with a cross reference.

This runs fine when I test it. But when I have in my workspace another DSL file with the same extension, the content assist offers me the items defined in my current DSL file as well as the items of the other file as well.

So how can I limit the cross reference to items defined in the current DSL file only?

As a XTEXT/JAVA/... novice, some sample code would be nice.

TIA, Uli


My Grammar is:
grammar de.ulrichmerkel.Narrowcross1 with org.eclipse.xtext.common.Terminals

generate narrowcross1 "http://www.ulrichmerkel.de/Narrowcross1"

Model:
greetings+=Greeting*
sendto+=Areference*;

Greeting:
'Hello' name=ID '!';

Areference:
"sendto" target=[Greeting]
;

And for the Test I have
A1.narrowcross1 as:
Hello Paul !
Hello Peter !

and A2.narrowcross1 as:
Hello Mary !


adding a "sendto", the content assist offers me Peter, Paul and Mary for A1 and A2
But I want to restrict it to "Peter and Paul" for A1 and "Mary" for A2

[Updated on: Thu, 09 January 2014 09:36]

Report message to a moderator

Re: reducing cross reference to current DSL file [message #1229360 is a reply to message #1229358] Thu, 09 January 2014 09:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12044
Registered: July 2009
Senior Member
Hi have a Look at defaultglobalscopeprovider

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: reducing cross reference to current DSL file [message #1229365 is a reply to message #1229360] Thu, 09 January 2014 09:47 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
Thanks Christian,

but for a novice like me, the issues I googled raise more questions than answers.

I found something at: http://xtextcasts.org/episodes/17-restricting-scope

Can I base my modification on his example (dropping the .filter clause) ?

public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
def IScope scope_Farewell_greeting(Farewell farewell, EReference eReference) {
Scopes::scopeFor((farewell.eContainer as Model).greetings.filter [ honest ])
}
}

TIA, Uli
Re: reducing cross reference to current DSL file [message #1229368 is a reply to message #1229365] Thu, 09 January 2014 09:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12044
Registered: July 2009
Senior Member
Hi,

yes and no.

the delegatiion hierarchy is

AbstractDeclarativeScopeProvider -> ImportedNamespaceAwareLocalScopeProvider -> DefaultGlobalScopeProvider

if you add a scope method to your AbstractDeclarativeScopeProvider you have to explicitely collect all candidate.

if you customize IGlobalScopeProvider (returning IScope::NULLScope)
or use SimpleLocalScopeProvider instead of ImportedNamespaceAwareLocalScopeProvider
you can keep the default behaviour for local files anyway respectively change it
to be local only


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: reducing cross reference to current DSL file [message #1229371 is a reply to message #1229365] Thu, 09 January 2014 10:00 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
OK, I got it, my /de.ulrichmerkel.narrowcross2/src/de/ulrichmerkel/scoping/Narrowcross2ScopeProvider.xtend reads as:

/*
* generated by Xtext
*/
package de.ulrichmerkel.scoping

import de.ulrichmerkel.narrowcross2.Areference
import de.ulrichmerkel.narrowcross2.Model
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider

/**
* This class contains custom scoping description.
*
* see : http://www.eclipse.org/Xtext/documentation.html#scoping
* on how and when to use it
*
*/
class Narrowcross2ScopeProvider extends AbstractDeclarativeScopeProvider {
def IScope scope_Areference_target(Areference areference, EReference eReference) {
Scopes::scopeFor((areference.eContainer as Model).greetings)
}

}

Re: reducing cross reference to current DSL file [message #1229372 is a reply to message #1229368] Thu, 09 January 2014 10:05 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
Hi Christian,

It looks like I will get a more general solution implementing your way.

But it's a bit harder to work out what needs to be coded.

Thanks again,
Uli
Re: reducing cross reference to current DSL file [message #1229380 is a reply to message #1229368] Thu, 09 January 2014 10:26 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
Christian Dietrich wrote on Thu, 09 January 2014 04:52
Hi,
or use SimpleLocalScopeProvider instead of ImportedNamespaceAwareLocalScopeProvider


I examined the mwe2 file, but I could not find it, where do I have to replace "ImportedNamespaceAwareLocalScopeProvider" with "SimpleLocalScopeProvider"?
Re: reducing cross reference to current DSL file [message #1229390 is a reply to message #1229380] Thu, 09 January 2014 10:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12044
Registered: July 2009
Senior Member
	public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
		binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.class);
	}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: reducing cross reference to current DSL file [message #1230626 is a reply to message #1229390] Sun, 12 January 2014 16:01 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
Hi Christian, I tried to follow your rules but it seems they do not work
when I launch my editor in Eclipse Kepler

Do you see anything wrong with my doing?

TIA, Uli

I found the lines you mentioned in :
de.ulrichmerkel.narrowcross3\src-gen\de\ulrichmerkel\AbstractNarrowcross3RuntimeModule.java

with a hint
/**
* Manual modifications go to {de.ulrichmerkel.Narrowcross3RuntimeModule}
*/

I put there:
package de.ulrichmerkel;

/**
* Use this class to register components to be used at runtime / without the
* Equinox extension registry.
*/
public class Narrowcross3RuntimeModule extends
de.ulrichmerkel.AbstractNarrowcross3RuntimeModule {

// contributed by
// org.eclipse.xtext.generator.scoping.AbstractScopingFragment

// contributed by
// org.eclipse.xtext.generator.scoping.AbstractScopingFragment
@Override
public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class)
.annotatedWith(
com.google.inject.name.Names
.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
.to(org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider.class);
}

}
Re: reducing cross reference to current DSL file [message #1230631 is a reply to message #1230626] Sun, 12 January 2014 16:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12044
Registered: July 2009
Senior Member
Hi,

i missinterpreted the class.
it delegates to gobalscopeprovider too.
soo you have to come up with your own.


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: reducing cross reference to current DSL file [message #1230938 is a reply to message #1230631] Mon, 13 January 2014 12:18 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
Hi Christian,

looks like my minimal java knowledge needs some more hints what I have to do where.

from your: customize IGlobalScopeProvider (returning IScope::NULLScope)
I assume that I have to somewhere change the return stops.

Can you give me a hand what I have to do (babystep wise), please?

TIA, Uli

[Updated on: Mon, 13 January 2014 12:19]

Report message to a moderator

Re: reducing cross reference to current DSL file [message #1230940 is a reply to message #1230938] Mon, 13 January 2014 12:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12044
Registered: July 2009
Senior Member
	@Override
	public Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() {
		return NullGlobalScopeProvider.class;
	}


public class NullGlobalScopeProvider implements IGlobalScopeProvider {

	@Override
	public IScope getScope(Resource context, EReference reference,
			Predicate<IEObjectDescription> filter) {
		return IScope.NULLSCOPE;
	}

}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: reducing cross reference to current DSL file [message #1230943 is a reply to message #1230940] Mon, 13 January 2014 12:33 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
Hi Christian, thanks for the code snippets.

Can you give me a hint which files I have to put them in?

TIA, Uli

P.S. I know it's a foolish question, but I'm lost there
Re: reducing cross reference to current DSL file [message #1230945 is a reply to message #1230943] Mon, 13 January 2014 12:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12044
Registered: July 2009
Senior Member
the binding to yourdslruntimemodule.
the class to a corresponding java file in the runtime project (or a depending plugin project)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: reducing cross reference to current DSL file [message #1230947 is a reply to message #1230945] Mon, 13 January 2014 12:41 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 233
Registered: June 2013
Senior Member
Got it now,

thanks a lot for your patience,
Uli
Previous Topic:[MWE] EcoreGenerator @generated NOT
Next Topic:Coffeescript-eclipse: XtextDocument and XtextResource have run out of sync
Goto Forum:
  


Current Time: Mon Jun 25 10:34:41 GMT 2018

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

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

Back to the top