Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm limit refactor scope to current file only

EDIT: Here's the link to the issue I created [ https://youtrack.jetbrains.com/issue/WEB-21956 ]

Is it possible to limit the refactoring scope of WebStorm to the file in which you've issued the refactor (by default)?

In this case I've got a file I'm editing and I want to refactor (rename) one variable. WebStorm then issues a search through all the files in the entire project. I've searched for this online and I can only find scope limitations for specific folders. I hope I'm not expected to create scope for each file.

P.S. I found this related question (https://stackoverflow.com/questions/33197566/pycharm-limit-refactor-renaming-to-current-file). Though I'm unable to comment on it as I don't have 50 rep yet (for shame). Chances are that if it's not in PyCharm it's not in WebStorm (they share code) so this is more of a double check. If it turns out that it is really not present I'll add a link to a feature request I'll be posting to WebStorm issues.

like image 885
Byebye Avatar asked Apr 14 '16 07:04

Byebye


People also ask

How do I refactor code in WebStorm?

Press F6 or choose Refactor | Move from the context menu or from the main menu. Alternatively, choose Refactor | Refactor This or press Ctrl+Alt+Shift+T , then choose Move from the list. The Move Module Members dialog opens. Specify the destination file and select the members to move.

How do I change all occurrences in IntelliJ?

Press Ctrl + Alt + Shift + J on Windows/Linux, and ⌘ + ^ + G on macOS. After the selection is complete, you can start editing all the fragments as if they were all the same one.

How do I rename a file in WebStorm?

To rename a file or a folderIn the Project tool window, select the file or folder to rename and choose Refactor | Rename from the context menu or press Shift+F6 . In the dialog that opens, type the new name of the file or folder.

How do I search globally in IntelliJ?

Use ⇧⇧ (macOS), or Shift+Shift (Windows/Linux), to bring up the Search Everywhere dialog. You can search across Classes, Files, Symbols and Actions. You can also use forward slash to filter the results to a specific area, such as /editor.


1 Answers

As of WebStorm 2016.1.3 it doesn't seem to be possible to change the default behaviour of the Rename Refactoring. The only options available are for renaming within a limited scope, in which case you can enable or disable the in-place mode (see docs).

Here are two possible workflows. I'll give instructions using PC keyboard shortcuts, but you can achieve the same through the context menus.


Find and Replace

  1. Move the caret to the symbol you wish to rename
  2. Select the word with Ctrl + W
  3. Open Replace dialog with Ctrl + R
  4. Hit Tab and type the new name
  5. Alt + P to replace current occurrence or Alt + A to replace all occurrences

Rename Refactoring tool

  1. Open Rename Refactoring tool with Shift + F6
  2. Type new name
  3. Adjust the filters for Search in comments and strings and for Search for text occurrences (on by default)
  4. Preview the refactoring (Alt + P)
  5. The Find Refactoring Preview pane will show up (Alt + 3 to focus), listing all the occurrences found
  6. In this list, you can select in which files the refactoring will take place; for instance, you can exclude all files by pressing Delete in the parent group, and then pressing Insert only in the target file

In this (stupid) example I am renaming require to require2. Several occurrences are found. I excluded all of them by excluding the main group, then just included one file. I could have excluded the remaining groups as well, or selected all with Ctrl + A and then Delete to exclude.

refactor rename example


See also

  • Limit Refactoring Scope in Webstorm
  • Is there any way to tell IntelliJ IDEA not to look at files during a search/replace or during refactorings?
like image 147
iled Avatar answered Nov 16 '22 01:11

iled