limit scoping of first fragment of qualified name? [message #807365] |
Sun, 26 February 2012 05:24  |
Eclipse User |
|
|
|
Hi,
For using import files and namespaces together the best option was to use only importNamespace. the first fragment of the qualified name will be the filelocation.
Now this all works great but not for the content assist because it should only propose content from the imported files and not from all files. This is normal behaviour because the filelocation are also "namespaces" and thus the content assist proposes file.dsl::content.
My question is what is the best option to limit the content assist to only propose content from files included. (otherwise the content assist list would get extremely big for projects with many files). I made a custom proposals so it works for one Xtext Rule, but then I have to create lot's of proposals for all other Rules referening to a FQN object. Could I solve it with scoping and how?
Please note I cant use importURI, because including files should be able to extend namespaces, so some behaviour of importnamespace is required for including files.
the full grammar is over 500 lines now, so here's a snippet:
Model:
includes+=IncludeFile*
elements+=AbstractElement*
;
FQN:
ID ("::" ID)*
;
// including files:
IncludeFile:
'#include' importedNamespace=STRING
;
// including some of the abstract elements :
Import:
'using' (ImportVocabulary|ImportNamespace)
;
ImportVocabulary:
'vocabulary' importedNamespace=FQN
;
ImportNamespace:
'namespace' importedNamespace=FQN
;
InternPointer:
pointername=[SymbolDeclaration|FQN] ('[' (arg=TypeReference (',' args+=TypeReference)*)? ']')?
;
...
So what I could get to work is making a custom content assist for internpointer_pointername. But there are a lot more of these references
I hope there is a compacter (and more stable) solution by custom scoping?
Regards,
Phil
|
|
|
|
Re: limit scoping of first fragment of qualified name? [message #808138 is a reply to message #807559] |
Mon, 27 February 2012 07:52  |
Eclipse User |
|
|
|
Hi Meinte Boersma
it does not work with importnamespace now.
It is just "simple names" now, it doesn't matter which namespace is used. How to add qualified name functionality?
example of use:
vocname::vocelement // works
vocelement // works not with vocname imported
public IScope scope_SymbolDeclaration(final Model model, EReference reference) {
IScope unfilteredScope = scopeProvider.getScope(model, reference);
Predicate<IEObjectDescription> filter = new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
System.out.println(model.eResource().getURI().lastSegment() + "==" + input.getQualifiedName().getFirstSegment());
// keep the owning resource
if (model.eResource().getURI().lastSegment() != null) {
if (model.eResource().getURI().lastSegment().equals(input.getQualifiedName().getFirstSegment())) {
return true;
}
}
// keep the included resources
for (IncludeFile file : model.getIncludes()) {
if (input.getQualifiedName().getFirstSegment().equals(file.getImportedNamespace())) {
return true;
}
}
return false;
}
};
return new FilteringScope(unfilteredScope, filter);
}
EDIT ::
got it fixed, dunno why not scope_SymbolDeclaration(model,..) could be used
It works as below:
public IScope scope_SymbolDeclaration(final EObject context, EReference reference) {
IScope unfilteredScope = super.delegateGetScope(context, reference);
Predicate<IEObjectDescription> filter = new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
// keep the owning resource
if (context.eResource().getURI().lastSegment() != null) {
if (context.eResource().getURI().lastSegment().equals(input.getQualifiedName().getFirstSegment())) {
return true;
}
}
// keep the included resources
EObject model = context;
while (!(model instanceof Model)) model = model.eContainer();
if (model instanceof Model) {
for (IncludeFile file : ((Model)model).getIncludes()) {
if (input.getQualifiedName().getFirstSegment().equals(file.getImportedNamespace())) {
return true;
}
}
}
return false;
}
};
return new FilteringScope(unfilteredScope, filter);
}
Any improvements?
Regards,
Phi
[Updated on: Mon, 27 February 2012 13:04] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03710 seconds