Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Proposal depending on cursor position
Proposal depending on cursor position [message #1065127] Mon, 24 June 2013 13:09 Go to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Hi

Based on the following part of grammar, I am developing my own proposal provider method "complete_GENERIC_PARAM":
My_Command: {My_Command} 'COMMAND' params+=GENERIC_PARAM+;
GENERIC_PARAM : ID;

If I have already typed
COMMAND param2 param3
and I would like to insert a value between 'COMMAND' and 'param2', how could I know the number of parameters already set before and after the cursor in the context of my command, so that I can compute the proposal correctly ?


I tried something like that, but it does not work Sad
int paramIndex = 0;
INode lastNode = context.getCurrentNode();
while ((lastNode != null) && (lastNode.getGrammarElement() instanceof Keyword))
{
  if (!(lastNode instanceof HiddenLeafNode)) paramIndex++;
  lastNode = lastNode.getPreviousSibling();
}

Thanks

[Updated on: Mon, 24 June 2013 14:06]

Report message to a moderator

Re: Proposal depending on cursor position [message #1065210 is a reply to message #1065127] Mon, 24 June 2013 19:49 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You may want to dig into the node model. Have a look at NodeModelUtils.

Am 24.06.13 15:09, schrieb Vincent De Bry:
> Hi
>
> Based on the following part of garammar, I am developing my own proposal
> provider method "complete_GENERIC_PARAM":
>
> My_Command: {My_Command} 'COMMAND' params+=GENERIC_PARAM+;
> GENERIC_PARAM : ID;
>
> If I have already typed
> COMMAND param2 param3 and I would like to insert a value between
> 'COMMAND' and 'param2', how could I know the number of parameters
> already set before and after the cursor in the context of my command, so
> that I can compute the proposal correctly ?
>
> Thanks


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Proposal depending on cursor position [message #1065258 is a reply to message #1065210] Tue, 25 June 2013 06:53 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
That's a track obviously.... not obvious.

Thanks though.
Re: Proposal depending on cursor position [message #1065276 is a reply to message #1065258] Tue, 25 June 2013 08:23 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
The node model carries the syntactical information, e.g. offset and
length in the textual model. NodeModelUtils helps you to find the node
for a semantic element.

So my proposal is to examine the children (params) of the context
element (of type in your case My_Command) get their respective node and
compare their offsets to the caret position.


Am 25.06.13 08:53, schrieb Vincent De Bry:
> That's a track obviously.... not obvious.
>
> Thanks though.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Grammar equivalent for Java interface
Next Topic:instance Create
Goto Forum:
  


Current Time: Wed Sep 25 00:07:08 GMT 2024

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

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

Back to the top