Xtext grammar autocompletion [message #1809343] |
Sat, 13 July 2019 18:03 |
Marshall Charron Messages: 72 Registered: August 2018 |
Member |
|
|
I have the following Xtext grammar :
ClassA :
'object' name=ID ('['declareNumberOfObjects=INT']')? ':' typeObjectA=TypeObjectA
;
ClassB :
'object' name=ID ':' typeObjectB=TypeObjectB
;
ClassC :
'object' name=ID ':' typeObjectC=TypeObjectC
;
TypeObjectA :
objectAToInstantiate=[ObjectA] 'platform' targetedPlatform=('TYPE1'|'TYPE2')
;
TypeObjectB :
objectBToInstantiate=[ObjectB] 'platform' targetedPlatform=('TYPE3'|'TYPE4')
;
TypeObjectC :
objectCToInstantiate=[ObjectC] 'platform' targetedPlatform=('TYPE5'|'TYPE6')
;
But I don't understand why when I arrive to the keyword 'platform' the autocompletion proposes me all TYPES (i.e TYPE1, TYPE2, TYPE3...etc) without taking into account the fact that I am in ClassA or ClassB or ClassC.
What I want is that if I am in ClassA the platform proposed would be TYPE1 or TYPE2 that's it, same for ClassB i.e TYPE3 or TYPE4...etc
Why this syntax does not achieve that and how can I achieve it ?
Regards
[Updated on: Sat, 13 July 2019 18:04] Report message to a moderator
|
|
|
Re: Xtext grammar autocompletion [message #1809344 is a reply to message #1809343] |
Sat, 13 July 2019 18:14 |
|
i dont understand your grammar is ambigous besides the types
=> unless you type TYPE3 or TYPE5
the model texts in the front are the same.
objectAToInstantiate=[ObjectA]
is parsed as
objectAToInstantiate=ID
as well as
objectBToInstantiate=[ObjectB]
is parsed as
objectBToInstantiate=ID
=> you parse
object ID : ID platform
=> works as intended cause your grammar is bad
you can override completeXXxx in the proposal Provider
e.g. org.eclipse.xtext.ui.editor.contentassist.AbstractJavaBasedContentProposalProvider.completeKeyword(Keyword, ContentAssistContext, ICompletionProposalAcceptor)
but i have doubts you will be able to distinguish the cases from contentAsssitContext.currentModel etc in this case
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03348 seconds