Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Rename fails if cursor is behind identifier
Rename fails if cursor is behind identifier [message #1838275] Sat, 20 February 2021 06:12 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hi

I have a grammar for variable declaration like this (stripped):
VariableList:
	 'var' Variable (',' Variable)* ";"
;

Variable:
     name ('=' Expression )?
;


Example texts
var a;
var b = 1.0;
var a = 2.3, b;


Now a problem occurs during renaming:
If the cursor is directly behind the variable name (var a|;), then the IRenameContext targetElement is the VariableList, not the Variable. Hence in this case, the rename is not working.
I guess the selection is seen as the character after the cursor, and in that case this might be the semicolon or the comma.

There is the solution to customize the RenameContextFactory, detect there the VariableList and change the targetElement to the right Variable.

My question:'
Is there a better way? Can this be done without the customized context factory?
Is there a way to make clear that the cursor position behind the variable name (identifier) belong to it?

Frank



[Updated on: Sat, 20 February 2021 06:36]

Report message to a moderator

Re: Rename fails if cursor is behind identifier [message #1838276 is a reply to message #1838275] Sat, 20 February 2021 06:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i dont think so. maybe customizing
org.eclipse.xtext.resource.EObjectAtOffsetHelper.resolveElementAt(XtextResource, int)
also works


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Rename fails if cursor is behind identifier [message #1838279 is a reply to message #1838276] Sat, 20 February 2021 12:02 Go to previous message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hello Christian,

thanks!
This makes the implementation way better.
Instead going onto text level, i can just query the cursor position -1 and see if the variable is found there.

Frank
Previous Topic:Content assist edit positions and template variables
Next Topic:Validator Testing with JUnit 5
Goto Forum:
  


Current Time: Thu Apr 25 12:37:04 GMT 2024

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

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

Back to the top