Auto-Completion cross-reference from a non-xtext model [message #1809571] |
Thu, 18 July 2019 06:40  |
Eclipse User |
|
|
|
Hello everybody, first i need to say i'm a bit of a newbie in DSLs and especially in Xtext.
So here's the problem:
I have a working xtext model for a type of file *.it. What i need to deal with is these statement of the whole grammar:
AddStatement: 'add' addName=package 'for' fields=FieldList;
.
or
It is used to handle these .it files for the statements like this one :
add Package for
fieldName1= 'something',
fieldName2= 'otherValue',
;
Now, i have a file in the same project a uniaue file of *.data which is "similar" to a CSV file:
XX
{
1, someFieldDescription, xxx
+
2, someFieldDescription, yyy
+
}
YY
{
1, someFieldDescription, aaa
+
2, someFieldDescription, zzz
+
}
.....
So the thing is that i would like to have an auto-completion that lists as an autocompletion all the packages of .data file (ex : XX and YY) and also the inner fields of each packages (ex: xxx and yyy for XX).
if "data" is parsed it could also show the packages of the file then " . " and after the corresponding fields.
Do you have any idea how i could achieve this ?
|
|
|
|
|
|
|
|
|
Re: Auto-Completion cross-reference from a non-xtext model [message #1809784 is a reply to message #1809742] |
Tue, 23 July 2019 08:01   |
Eclipse User |
|
|
|
Actually i think that my problem could be fixed with this answer : https://www.eclipse.org/forums/index.php?t=msg&th=209411&goto=671493&#msg_671493Quote:Hi Ulli,
Welcome to the Xtext community!
See answers inline.
On 5/17/11 2:02 PM, Ulli Hafner wrote:
> Hi,
>
> I'm trying to write a xtext grammar that uses some predefined instances that
> are computed dynamically. Where is the best way to load these instances so
> that these instances are available when pressing CTRL-SPACE?
>
> My grammar is quite simple:
> ----------------
> grammar de.faktorlogik.ips.dsl.Rules with org.eclipse.xtext.common.Terminals
>
> generate rules "http://www.faktorlogik.de/ips/dsl/Rules"
>
> Model:
> rule=Rule;
>
> Concept:
> 'concept' name=ID;
>
> Property:
> 'property' name=ID;
>
> Rule:
> concept=[Concept] 'and' restriction=Restriction;
>
> Restriction:
> '(' property=[Property] 'some' concept=[Concept] ')';
> ----------------------
>
> Concept and Property instances are actually not defined using the editor, they
> are created dynamically. I only defined them in the grammar in order to use
> them as references in the Rule definition.
>
I would consider maintaining the Ecore model by hand as the parser rules for
Concept and Property are not used and thus rather confusing.
> My Editor should basically parse the following input:
> ----------------------
> concept1 and (property1 some concept2)
> ----------------------
>
> The elements concept1, property1, and concept2 are dynamically computed.
>
> Currently I've extended from AbstractDeclarativeScopeProvider and instantiate
> the objects dynamically from within methods
>
> public IScope scope_Concept(Model model, EReference reference) {
> return new MapBasedScope(computeAvailableConcepts());
> }
>
> public IScope scope_Property(Model model, EReference reference) {
> return new MapBasedScope(computeAvailableProperties())
> }
>
> This approach works for the context assist, however I'm always getting the
> following validation error:
>
> The feature 'property' of
> 'de.faktorlogik.ips.dsl.rules.impl.RestrictionImpl@1fdbab5 {platform:/resource/hello.world/src/rules.flips#//@rule/@res triction}'
> contains a dangling reference
> 'de.faktorlogik.ips.dsl.rules.impl.PropertyImpl@a484c7{#//}' rules.flips
> /hello.world/src line: 1 /hello.world/src/rules.flips Xtext Check (fast)
>
> Am I doing something fundamentally wrong? Or where would be the best place to
> instantiate those predefined instances? (Currently the scope methods are
> invoked on every CTRL-SPACE, maybe a method that would be invoked only once
> would be sufficient?
>
The problem is that your Concept and Property instances are not contained by
any EMF resource. And there is a standard EMF validation checking against
references to such non-contained objects.
I would consider the following approaches (in the given order) to solve the
problem:
1. Presumably the Concept and Property instances are created based on some
other external, persisted data. If possible and feasible it would make sense
to implement an IResourceServiceProvider (see also
GenericResourceServiceProvider) for this external content. That way you could
add the Concept and Property instances to the Xtext index and link against that.
2. On the fly generate an EMF Resource containing the Concepts and Properties
and add it to the ResourceSet which contains your model. You could do this
dynamically in the ScopeProvider or possibly up front in the Linker (using the
afterModelLinked() hook).
3. Add the Concept and Property instances as additional top-level objects to
the XtextResource containing your model. This however makes most sense if
these instances are derived from data in your model. (Xbase based languages
use this approach to store derived Java types.)
4. Disable the EMF validation. You can do this by binding a
@Named(CompositeEValidator.USE_EOBJECT_VALIDATOR) Boolean to "false". You
could also be more specific and bind CompositeEValidator to a custom subclass
where you override initDefaults() to add an EObjectValidator which in
validate_EveryReferenceIsContained() returns "true". But I wouldn't really
recommend this approach if you don't have very good reasons.
Hope that helps,
--knut
But i didn't manage to get how to do it, is it still the good way to do what i need ?
[Updated on: Tue, 23 July 2019 08:02] by Moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.28226 seconds