reducing cross reference to current DSL file [message #1229358] |
Thu, 09 January 2014 09:25  |
Eclipse User |
|
|
|
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] by Moderator Report message to a moderator
|
|
|
|
|
Re: reducing cross reference to current DSL file [message #1229368 is a reply to message #1229365] |
Thu, 09 January 2014 09:52   |
Eclipse User |
|
|
|
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
|
|
|
Re: reducing cross reference to current DSL file [message #1229371 is a reply to message #1229365] |
Thu, 09 January 2014 10:00   |
Eclipse User |
|
|
|
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 #1229380 is a reply to message #1229368] |
Thu, 09 January 2014 10:26   |
Eclipse User |
|
|
|
Christian Dietrich wrote on Thu, 09 January 2014 04:52Hi,
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   |
Eclipse User |
|
|
|
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);
}
|
|
|
Re: reducing cross reference to current DSL file [message #1230626 is a reply to message #1229390] |
Sun, 12 January 2014 16:01   |
Eclipse User |
|
|
|
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 #1230940 is a reply to message #1230938] |
Mon, 13 January 2014 12:22   |
Eclipse User |
|
|
|
@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;
}
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05058 seconds