简体   繁体   中英

Eclipse>WST>JSDT Javascript Refactoring Renaming variables working half of the time

In Eclipse (I am running 3.8.0 @ Linux (Mint 14 (Ubuntu (Debian))) at the moment), renaming variables using Refactor is an option that seems randomly available. For some code it's there, and for other code it's not.

I tried to see a pattern why some var declarations are up for renaming and others are not, but I haven't found it yet.

Why does refactor->rename not work for some code? How can I make this work?

You can see by the highlighted references that Eclipse is very aware of what should be refactored, so I don't understand what the problem is.

No problem: 在此输入图像描述

Problem: 在此输入图像描述

You can always use Ctrl + 2 + R (Press R after appearing a small dropdown) to refactor the variable... [ Got it by chance ].

Update

working on Eclipse Neon... can't say about other older version. because it is the latest stable version at the time I am writing the answer.

Update 3-May-2017

one drawback is that it replaces all occurrences of that variable in the file. special care is required.

I noticed that renaming is not available, when the project is not a JS project or if I open it with the non-default JS editor. (Spket JS Editor in my case.)

So try this:

  • Make sure in your .project file jsNature is set.

Eg (In my case I have JS code inside a Java project):

<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
    <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
  • Right click file -> Open with -> JavaScript Editor

Works for my using Eclipse Kepler.

我可以使用JSDT“JavaScript Editor”在Aptana Studio 3.0(基于Eclipse)下重命名本地变量,并在屏幕截图中显示JS功能: http//imgur.com/246oTY5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM