Skip to main content



      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 01:12 Go to next message
Eclipse UserFriend
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 01:36] by Moderator

Re: Rename fails if cursor is behind identifier [message #1838276 is a reply to message #1838275] Sat, 20 February 2021 01:33 Go to previous messageGo to next message
Eclipse UserFriend
i dont think so. maybe customizing
org.eclipse.xtext.resource.EObjectAtOffsetHelper.resolveElementAt(XtextResource, int)
also works
Re: Rename fails if cursor is behind identifier [message #1838279 is a reply to message #1838276] Sat, 20 February 2021 07:02 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 16:43:59 EDT 2025

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

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

Back to the top