Repository navigation
Refactoring and Navigation
The plugin supports the IntelliJ IDEA refactorings and navigation actions for Haxe code: renaming, extracting and moving code, finding usages, jumping between declarations and implementations, and browsing hierarchies. With the compilation server, some of them can also use the Haxe compiler and show code that macros generate.
You find the refactorings in the Refactor menu and in the Refactor This… popup, and the navigation actions in the Navigate menu. In that menu they appear without the "Go to" prefix; for example, Go to Super Method is Navigate | Super Method. Use Help | Find Action to look up an action by name and see its shortcut.
Use Refactor | Rename… on a declaration or on any reference to it. The plugin renames the declaration and every reference to it in your project.
- Local variables, parameters and local functions are renamed in place: you type the new name directly in the editor, and every occurrence changes as you type.
- Fields, methods, module-level declarations and types are renamed in place too. The current file changes as you type; the other files change when you press Enter. Invoke Rename… a second time to open the rename dialog with more options.
- While you rename a variable, field or parameter, the list of suggested names offers names derived from its initializer and its type. For a parameter of a method that overrides or implements another one, the name of that method's parameter comes first.
If another class, method or field with the new name already exists, the plugin warns you before it renames anything.
- A Haxe file is a module. Its main class is the class with the same name as the file. When you rename the main class and the file declares nothing else, the file is renamed too. If the file contains other types or module-level fields or functions, the Rename Module? dialog asks whether to rename the file and module as well.
- When you rename a
.hxfile in the Project view, the Rename Class? dialog asks whether to rename its main class as well. - When you rename a class, the
-mainlines of hxml files that name it change too, and Find Usages on the class lists them. See Build Files. - A constructor is always named
newand cannot be renamed. If you start a rename onnew Main(), the plugin renames the classMaininstead.
A property declared with get or set, such as var width(get, set):Int, is bound to the methods get_width and
set_width by name. Renaming only one of them breaks the code, so the plugin offers to rename them together.
When you start an in-place rename on such a property or on one of its accessors, a popup asks how far the rename goes:
| Popup | Choices |
|---|---|
| Accessors of name found (rename started on the property) | Rename property and accessors, Rename property only |
| Property name found (rename started on an accessor) | Rename property and accessors, Rename method only |
With Rename property and accessors, the property, its get_ and set_ methods, the same property in supertypes
and implementing classes, and all overrides of the accessors are renamed together. The accessors in the current file
follow the name as you type.
In the rename dialog, the checkbox Rename property accessors does the same. When you confirm the new name, the Rename Property Accessors dialog lists the other members and the names they will get.
class Box {
public var width(get, set):Int; // rename width to size ...
function get_width():Int return 0; // ... and this becomes get_size
function set_width(value:Int):Int return value; // ... and this becomes set_size
}| Refactoring | Where to find it | What it does |
|---|---|---|
| Introduce Variable | Refactor | Extract/Introduce | Turns the selected expression into a local variable. You can replace only this occurrence or all occurrences of the expression. |
| Introduce Constant | Refactor | Extract/Introduce | Turns the selected expression into a public static inline var of the class. |
| Introduce Parameter | Refactor | Extract/Introduce | Turns the selected expression or local variable into a parameter of the enclosing function. A literal becomes the parameter's default value. |
| Extract Method | Refactor | Extract/Introduce | Moves the selected statements into a new method after the current one and calls it from where they were. The new method is static when the code it came from is static. You then type the method's name. |
| Extract Interface, Extract Superclass | Refactor | Extract/Introduce | Creates an interface or a superclass from members of the current class. |
| Pull Members Up | Refactor | Pull Members Up… | Moves members of a class to its superclass or to an interface it implements. A method pulled up into an interface becomes a declaration without a body there. |
| Push Members Down | Refactor | Push Members Down… | Moves members of a class into its direct subclasses. |
| Move | Refactor | Move…, or drag in the Project view | Moves .hx files and packages. The package statements of the moved files and the imports and qualified names that refer to them are updated. |
The plugin does not provide Inline, Change Signature or Introduce Field for Haxe code, and Safe Delete works only on whole files.
| Action | What it does in Haxe code |
|---|---|
| Go to Declaration or Usages | Jumps from a reference to its declaration. On a key of an object literal, it jumps to the matching field of the type the literal is used as. On a declaration, it shows its usages. In an hxml file, it jumps from the class name after -main, -m or --main to that class. |
| Go to Implementation(s) | Lists the classes that extend or implement a class or interface, and the members that override or implement a method or field. For an extern class of the Haxe standard library, it also lists the implementation each target uses. |
| Go to Super Method | Jumps from a method to the method it overrides or implements, or from a class to its supertypes. |
| Go to Test | Jumps between a class Name and its test class NameTest or TestName. |
| Go to Class…, Go to Symbol… | Find types, fields and methods by name. |
| Find Usages | Finds every reference to a declaration and shows whether each one reads or writes it. For a method that overrides or implements another one, the plugin asks whether to search for usages of the base method too. |
| Type Hierarchy, Method Hierarchy, Call Hierarchy | Show the supertypes and subtypes of a class, the overrides of a method, and the callers and callees of a method. A call hierarchy search stops after 20 seconds and shows Call Hierarchy Search Timed Out; the result may then be incomplete. |
| File Structure and the Structure tool window | Show the members of the file, sorted alphabetically or by visibility. Show Fields hides or shows the fields. See Editor Extras. |
Icons in the editor gutter show where a member overrides or implements another one, where a class or member has subclasses or implementations, which typedefs refer to a type and where a method calls itself. Click an icon to navigate.
Class names and file paths in string literals are links too; see Editor Extras.
Note
Beta. Compiler-backed navigation works and is supported, but may still change.
The plugin's own analysis does not see what macros generate. If you select Use compiler for IDE features (beta) in Settings | Build, Execution, Deployment | Compiler | Haxe Compiler, references to members that only macros generate resolve instead of being reported as unresolved, and two of the options below it hand navigation to the Haxe compiler. Both are selected by default:
- Find usages: Find Usages asks the compiler, so usages in generated code are found too. It sends one request for the declaration. For a method, the result includes usages of the base method and of all overrides, except with Haxe 3.4.7, which lists direct usages only. The search scope still applies, and text occurrences are not searched.
- Navigation: Go to Declaration or Usages asks the compiler for the declaration under the caret. If the compiler gives no answer, the IDE resolves the reference itself. A name that neither can place, such as a parameter a build macro introduces, opens the preview of the generated code of the member it is used in. Hovering over a reference with the navigation modifier key pressed also sends a request.
Rename, the highlighting of usages under the caret and the other actions keep using the plugin's own analysis.
This needs the compilation server, switched on for the module. If it is off, a No compiler for IDE features notification appears once. It offers Configure compilation server and Use IDE features, which clears Use compiler for IDE features (beta).
Note
Beta. The preview works and is supported, but may still change. It needs Haxe 4.3 or later, Haxe 5 included.
Some members exist only after macros have run, for example fields a build macro creates from a data file. The plugin can show you the code the compiler generated for a module. There are three ways to open it:
-
Show Post-Macro File: right-click a Haxe file in the editor or in the Project view. The action is there for
a file with a class that a build macro changes: a class with
@:buildmetadata, or one that extends or implements a type with@:autoBuild. Macros called from expressions are not detected. The preview opens at the class and member at the caret, or at the file's first class when you start from the Project view. - Go to Declaration or Usages on a reference to a generated member, or on a name only a macro declares (see Compiler-backed navigation). The preview opens with the caret on that member or name. With Open generated members in the post-macro preview off, Go to Declaration goes instead to the position the macro gave the member, for example the field a getter was generated from.
-
Go to Implementation(s) on an
externclass or one of its members: the list also offers the generated code of the type, as name (generated).
The last two work while Use compiler for IDE features (beta) and its Navigation option are selected in Settings | Build, Execution, Deployment | Compiler | Haxe Compiler; Go to Declaration also needs Open generated members in the post-macro preview, which is on by default. All three need the compilation server.
To open the preview, the plugin saves your files and builds the module once through the compilation server to let the
compiler write out the generated code. A progress dialog Generating compiler dump files… shows the build; you can
cancel it. A read-only file named after the module, such as Main.generated.hx, then opens. A new preview of the same
module replaces the one already open.
Good to know:
- The preview shows the compiler's version of the code after macros ran. It is highlighted, but not checked for errors.
- The preview build writes only into a directory of the IDE, never into your output folder. An
--interpbuild is previewed without running the program; builds that run it with--runor-xcannot produce a preview. - When no preview can be built, the notification Post-macro preview not available says why, for example The dump build reported compiler errors.
- The result is reused until you change code. The next preview after a change builds again.
- An open preview does not follow your edits. Once a Haxe file changes on disk, the preview shows the banner The Haxe sources changed since this preview was generated. Click Regenerate to build again and reopen the preview at the same line.
- Because the build runs your macros, the plugin asks for trust first in an untrusted project (Trust Project?). See Compilation Server.
Getting started
Working with projects
- The Haxe Tool Window
- Build Files
- Targets and Sections
- Resolve Context
- Libraries and Haxelib
- Defines and Custom Targets
- Building and Running
- Run Configurations
- Tools
- Compilation Server
Debugging
Testing
Profiling
Editing code
- Code Completion
- Diagnostics and Inspections
- Refactoring and Navigation
- Formatting and Code Style
- Conditional Compilation
- Editor Extras
Reference