Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Customizing content assist suggestions
Customizing content assist suggestions [message #1767499] Thu, 06 July 2017 09:35 Go to next message
Eclipse UserFriend
I am trying to extend AbstractMyDslProposalProvider in order to filter the content assistants suggestions for a containment reference.

I have found a nice description on how to filter suggests in the case of a cross reference using the AbstractJavaBasedContentProposalProvider's lookupCrossReference with a predicate parameter:
https://www.eclipse.org/forums/index.php/m/558687/

I would like to do the same with the containment refs but I cannot find any support for this in the API?.Any other ways to filter these?



Re: Customizing content assist suggestions [message #1767502 is a reply to message #1767499] Thu, 06 July 2017 10:12 Go to previous messageGo to next message
Eclipse UserFriend
can you please elaborate a bit more on what you want to exactly filter?
Re: Customizing content assist suggestions [message #1767508 is a reply to message #1767502] Thu, 06 July 2017 11:23 Go to previous messageGo to next message
Eclipse UserFriend
yes of course :) I have an abstract geometry object, that must be implemented as either a box, a cylinder, a sphere or a mesh. Even though one of these concrete geometrical implementations (box, sphere, cylinder or mesh) must be referenced after the Geometry keyword in the concrete syntax, the content assist suggestion box i polluted with additional suggestions from outer and inner scope.
But since this is an alternative parser rule, I dont think I can do much more to narrow it down further in metamodel, grammar or scoping - but if possible of course i should do it there...

index.php/fa/29876/0/

I have found this blogpost from you, that is related to the subject of manipulating proposals:
https://christiandietrich.wordpress.com/2015/03/19/xtext-and-strings-as-cross-references/

Here you alter the proposal at the time of running the accept method from the ICompletionProposalAcceptor - but I have to get to it earlier while creating the options for the suggest dropdown - but how to do that, I dont know...

GRAMMAR:

Visual:
	{Visual} 'Visual' (name=ID)? 
	'Geometry' geometry+=Geometry*
	(origin=Origin)?
	('Material' material=Material)?
	
;

Geometry:
	Box | Cylinder | Mesh | Sphere
	
;
-
Box:
	'Box' (name=ID)?
	'height' height=URDFAttrNumeric 
	'length' length=URDFAttrNumeric
	'width' width=URDFAttrNumeric 
;

Cylinder:
	'Cylinder' (name=ID)?
	'radius' radius=URDFAttrNumeric
	'length' length=URDFAttrNumeric	
;


Mesh:
	'Mesh' (name=ID)?
	'pathToFile' pathToFile=URDFAttrSTRING
	//('scale' dimension=Box)?
;

Sphere:
	'Sphere' (name=ID)?
	'radius' radius=URDFAttrNumeric	
;




  • Attachment: box.png
    (Size: 19.56KB, Downloaded 317 times)
Re: Customizing content assist suggestions [message #1767510 is a reply to message #1767508] Thu, 06 July 2017 11:33 Go to previous messageGo to next message
Eclipse UserFriend
Don't understand that

Geometries are optional

So you get the geometries
The optional origin stuff
And the optional material stuff

And thus the stuff that comes after the complete visual

What do you expect instead ?
Re: Customizing content assist suggestions [message #1767567 is a reply to message #1767510] Fri, 07 July 2017 04:01 Go to previous messageGo to next message
Eclipse UserFriend
I want to limit the suggestions, so only Box, Cylinder, Mesh or Sphere are suggested after typing the keyword Geometry - because one of these four geometrical shapes is required here to form a valid AST :)
Re: Customizing content assist suggestions [message #1767577 is a reply to message #1767567] Fri, 07 July 2017 04:49 Go to previous messageGo to next message
Eclipse UserFriend
no it is not ?!?

'Geometry' geometry+=Geometry+

and it should work
Re: Customizing content assist suggestions [message #1767581 is a reply to message #1767567] Fri, 07 July 2017 05:17 Go to previous messageGo to next message
Eclipse UserFriend
I am investigating a little further into this and I can see that ContentAssistContext holds an immutable list of 'next possible grammar elements': getFirstSetGrammarElements()
http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.6/org/eclipse/xtext/ui/editor/contentassist/ContentAssistContext.html#getFirstSetGrammarElements()

but I dont know if correct approach would be to try and build a 'clone' of current context with new version of this list of grammar elems.
Seems a little too cumbersome compares to how easy it is to filter cross refs as mentioned above - so I'm thinking there must be an easier way :)
Re: Customizing content assist suggestions [message #1767585 is a reply to message #1767581] Fri, 07 July 2017 05:31 Go to previous messageGo to next message
Eclipse UserFriend
sorry i dont understand. if i change grammar to

Visual:
{Visual} 'Visual' (name=ID)?
'Geometry' geometry+=Geometry+
(origin=Origin)?
('Material' material=Material)?

;


[Updated on: Fri, 07 July 2017 05:31] by Moderator

Re: Customizing content assist suggestions [message #1767595 is a reply to message #1767585] Fri, 07 July 2017 06:54 Go to previous messageGo to next message
Eclipse UserFriend
you are absolutely right! I apologize for the inconveninence! I would have sworn I had tested that option but maybe I forgot to regenerate the xtext artifacts on that run :(

I have one further, related question though - I also wish to narrow down suggestions for completion of this rule, which is a little complicated:

Link:
	{Link} 'Link' name=ID
	(('def' (inertial=Inertial | visual+=Visual | collision+=Collision)*) 
		| ('reuse' link=[Link] reuse=Reuse)
	)?	
; 


Here the user has to choose if he or she wants to define (def) a new Link or reuse (reuse) an existing one.

If he chooses to define a new link, the assignment of inertial, visuals and collisions are all optional - a Link is perfectly valid without either. But when the user types 'def' the proposal provider should narrow scope to inertial, visual or collision - but this is not the case now.

Can this also be achieved by refactoring the grammar - or by other means?

  • Attachment: def.png
    (Size: 11.84KB, Downloaded 105 times)
Re: Customizing content assist suggestions [message #1767596 is a reply to message #1767595] Fri, 07 July 2017 06:57 Go to previous messageGo to next message
Eclipse UserFriend
so if the user types def he has to specify Inertial / Visual / Collision????



('def' (inertial=Inertial | visual+=Visual | collision+=Collision)+)
Re: Customizing content assist suggestions [message #1768174 is a reply to message #1767596] Fri, 14 July 2017 06:38 Go to previous message
Eclipse UserFriend
Thanks - think I've got it now :)
Previous Topic:Eclipse support in Xtext as LSP + Generic Editor?
Next Topic:Are grammar mixins transitive?
Goto Forum:
  


Current Time: Wed Jul 23 13:43:52 EDT 2025

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

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

Back to the top