Repository navigation
Compilation Server
The Haxe compilation server is a Haxe compiler that keeps running in the background. The plugin uses it to make builds faster and to give the editor answers that only the real compiler knows, such as code that macros generate. This page explains how the plugin runs the server, how to configure it and which features depend on it.
Note
Beta. The compilation server features work and are supported, but may still change.
When you start Haxe with --server-listen <port>, or --wait <port> in Haxe 3, it does not compile anything. It
waits for requests and keeps the files it has parsed and the modules it has typed in memory. A build started with
--connect <port> sends its arguments to that process instead of compiling from scratch, so only what changed is
compiled again. The Haxe manual describes this in
Completion server.
The same process also answers questions from an IDE, such as completion, diagnostics, references and definitions. Because these answers come from the compiler itself, they include everything your macros add to the program.
The server is enabled by default. The plugin starts it the first time something needs it:
- a build that compiles through the server (see Builds through the server),
- an editor feature that asks the compiler (see Features that use the server),
- a custom action that uses
${serverPort}(see Building and Running).
The editor features that ask the compiler are off by default, so with the default settings only builds and custom actions start the server. Once you turn such a feature on, the server starts in the background as soon as the feature needs it. Some requests, such as the lookup of macro-generated members, first need the whole build typed in the server's cache. With Haxe 4.3.5 or later, the plugin types it with a diagnostics request, which types every module but generates nothing, so the build's generation steps, such as the tools a custom target runs, do not run. Older compilers compile the build without writing output files, which runs those steps.
The plugin runs one server for each Haxe executable. If your modules use different Haxe SDKs, each SDK gets its own
server, because a server's cache belongs to one compiler version. A server starts with --server-listen <port>, or
with --wait <port> for a Haxe 3 SDK, as Haxe 5 does not accept --wait. The plugin takes the Haxe version from the
SDK; for an SDK whose version it does not know, it asks the Haxe executable once (haxe -version). The servers run on
your machine and stop when you close the project.
flowchart LR
subgraph ide["IntelliJ IDEA"]
builds["Builds, and custom actions<br/>that use ${serverPort}"]
editor["Editor features: diagnostics,<br/>completion, navigation, type hints"]
end
subgraph sdk["For each Haxe SDK"]
server[("Compilation server<br/>cache shared with builds")]
display[("Display process<br/>cache of its own")]
end
builds -->|"haxe --connect"| server
editor -->|"default connection mode"| display
editor -.->|"other connection mode"| server
Builds always use the compilation server. How the editor features reach the compiler is set in Settings | Build, Execution, Deployment | Compiler | Haxe Compiler, once for Haxe 4 and later and once for Haxe 3. Each value applies to every SDK of those versions:
| Setting | Default | Other value |
|---|---|---|
| Connection mode (Haxe 4 and later): | --server-connect (host:port) | --server-listen (host:port) |
| Connection mode (Haxe 3): | --wait stdio | --wait host:port |
The defaults start a second Haxe process for each SDK, a display process, that answers only the editor. It keeps its connection open, so it answers without the delay of about 50 ms that each new connection to the compilation server costs, and builds do not hold up its answers. It has a cache of its own, so each build is typed in it once more. With --wait stdio, the process talks to the IDE through its standard input and error output and listens on no port.
The other values, --server-listen (host:port) and --wait host:port, send the editor's requests to the server your builds use. They share its cache, but each request opens a new connection and waits while a build runs.
If a display process cannot start, the editor's requests go to the compilation server. Switching to one of the other values stops the display processes. A display process runs only while the compilation server is enabled, and it gets the same Server arguments:.
A build command connects to the server with --connect <port> when the server is enabled for the project and the
module, and the command is one of:
- a direct
haxecompile, such ashaxe build.hxml, - a Lime, OpenFL or NME build.
Other commands cannot compile through the server. The editor features still use the server for these modules. Builds that produce a Flash SWF compile through it like any other build; see A rebuilt SWF fails at load.
Open Settings | Build, Execution, Deployment | Build Tools | Haxe and find the Compilation Server section. You can also open this page from the Haxe tool window toolbar: Haxe Settings | Build Tool Settings….
| Option | Default | What it does |
|---|---|---|
| Enable compilation server | On | Turns the server on or off for the whole project. When it is off, builds compile without the server and no compiler-backed editor feature works. |
| Server port: | Empty | Leave it empty to let the plugin pick a free port. If you enter a port, the first server uses it; servers for other SDKs pick free ports. |
| Server arguments: | Empty | Extra arguments for the server process and the display processes, for example -v for verbose output. They are placed before the server flags, such as --server-listen <port> or --server-connect. |
When you change one of these options or the Haxe SDK: on the same page, the plugin stops the running servers and display processes. The next build or editor request starts them again with the new settings.
In the Haxe tool window, every module has a Compilation group with a Compilation server row. Click the row's value to turn the server on or off for that module. While the server is off for a module, its builds compile without it and the editor does not ask the compiler about the module's files.
The row shows the current state:
| Row text | Meaning |
|---|---|
| on (port n) | The server for this module's SDK is running on port n. |
| on (idle) | The server is enabled but not running. It starts with the next build or editor request. |
| off | You turned the server off for this module. |
| on (not connectable) | The module builds nothing, or its build command cannot compile through the server (see Builds through the server). |
| disabled (enable in Build Tools settings) | The server is off for the whole project. Clicking the value opens the settings. |
| project not trusted — compiler evaluation disabled | The project is not trusted; see Project trust. |
The Connection mode row below it shows how the editor reaches the compiler of the module's SDK; see Where editor requests go. Click its value to choose the mode for every Haxe 3 SDK, or for every SDK of Haxe 4 and later. The row reads off while the Compilation server row reads neither on (port n) nor on (idle).
See The Haxe Tool Window for the rest of the Compilation group.
The server keeps one cache per set of defines, and inside it one entry per module path. Two builds with the same
target and defines that both compile a Main — two Lime projects of one target, say — share one cached Main, and
the second build can receive the first build's program. A module can run a compilation server of its own instead of
its SDK's shared one: in the Haxe tool window, click the value of the module's Server instance row and pick
dedicated. The module's builds, its custom actions with ${serverPort} and the editor's requests for its files
then go to that server, which has a cache of its own; with a display process connection
mode the module gets a display process of its own as well. The Haxe Compilation Server tool window shows the
instance as a tab named after the SDK and the module.
flowchart LR
a["Module A<br/>Server instance: shared"] --> shared[("The compilation server<br/>of the SDK")]
b["Module B<br/>Server instance: shared"] --> shared
c["Module C<br/>Server instance: dedicated"] --> own[("A compilation server<br/>for module C only")]
Picking shared again stops the dedicated server and removes its tab.
A dedicated server separates the module from other modules only. Two builds of the same module with the same target and defines but different class paths (a mock class path swapped in without a define, say) still share its cache: give one of them a define, split them into modules, or restart the server between them.
The editor features that use the server are switched on and off on the compiler settings page: Settings | Build, Execution, Deployment | Compiler | Haxe Compiler. The Haxe tool window opens it too: Haxe Settings | Compiler Settings….
| Feature | Setting on the Haxe Compiler page | Default | Details |
|---|---|---|---|
| Macro-generated members resolve instead of being reported as unresolved | Use compiler for IDE features (beta) | Off | Refactoring and Navigation |
| Macro-generated types and members in completion and Go to Class | Completion under it, with Completion sources: set to IDE + compiler (adds generated symbols) or Compiler only (the compilation server answers every completion) | Off | Code Completion |
| Completion answered only by the compiler | Completion under it, with Completion sources: set to Compiler only (the compilation server answers every completion) | Off | Code Completion |
| Type hints from the compiler | Type inlays under it | Off | Editor Extras |
| Find Usages answered by the compiler | Find usages under it | Off | Refactoring and Navigation |
| Go to Declaration or Usages answered by the compiler, and the preview of macro-generated code it opens | Navigation under it | Off | Refactoring and Navigation |
| Show Post-Macro File | None | On | Refactoring and Navigation |
| Compiler errors and warnings in the editor, with quick fixes | Use compiler diagnostics (beta) | Off | Diagnostics and Inspections |
| Faster builds | Enable compilation server on the Build Tools | Haxe page | On | Builds through the server |
The options under Use compiler for IDE features (beta) are Type inlays, Find usages, Navigation and Completion. They are selected by default, but take effect only while Use compiler for IDE features (beta) is selected, and that option is off by default. While either it or Completion is cleared, completion uses only the plugin's own analysis.
Every feature in this table also needs the server to be enabled for the project and for the module.
The compiler can only answer questions about a file if it gets the same arguments as a build. The plugin takes them from the build file the file is analyzed under, its resolve context: usually the build whose class paths contain the file. Questions about a whole module, such as the classes Go to Class offers, use the module's default build: the project's active build file if this module owns it, otherwise the build file of the module's build command.
| Build file | Where the arguments come from |
|---|---|
| hxml | The file itself. For an hxml file that chains several compilations with --next, only the selected section is used (see Targets and Sections). |
Lime or OpenFL project.xml, HXP project script |
The plugin runs haxelib run lime display (or openfl) for the selected target, against an empty export folder, so Lime evaluates the project fresh instead of printing a build file it cached earlier. Reload Haxe Project and Purge Caches run it again, so edits to included project files and to a library's include.xml reach the compiler without a build. |
NME .nmml
|
The arguments NME generates when the plugin prepares the project. |
| Plain HXP build script | None. Compiler-backed features do not work for modules that only have such a script. |
The build file's IDE overrides are applied to these arguments: defines you set are added and defines you removed are
dropped, so the compiler sees the same #if branches as the editor. A custom target is added as
--custom-target <name> when the build selects no target of its own and the compiler is Haxe 5 or later. See
Defines and Custom Targets.
Compiler-only completion, the type hints from the compiler, the compiler-backed Find Usages and Go to Declaration or Usages, and Show Post-Macro File work the same way; they need no build command. While the server is off for the module, completion and navigation show a notification instead, the type hints stay empty and Show Post-Macro File is not offered.
When the plugin connects to a server, it asks which requests the compiler supports and uses only those. Older Haxe releases therefore support fewer features:
| Feature | Needs |
|---|---|
| Compiler diagnostics | Haxe 4.3.5 or later, or Haxe 3.4.7. Among Haxe 4 releases, the diagnostics request the plugin uses arrived in 4.3.5 (see the Haxe 4.3.5 release notes). |
| Macro-generated members, preview of macro-generated code, Show Post-Macro File | Haxe 4.3 or later. |
Haxe 3.4.7 is the one Haxe 3 release the plugin supports here. It has none of Haxe 4's display requests, so the plugin uses its older display interface instead, which gives compiler diagnostics, completion, Go to Declaration and Find Usages; Find Usages lists direct usages only. Haxe 3 offers none of the following: macro-generated types and members, the preview of macro-generated code and Show Post-Macro File, and the metadata that libraries register with the compiler.
Use Haxe 4.3.5 or later to get every compiler-backed feature. See Supported Versions for the versions the rest of the plugin needs.
Every compile through the server runs your project's macros, which is project code. The server therefore never starts in a project you have not trusted, and the compiler-backed editor features stay off.
In an untrusted project, the plugin shows the notification Haxe: Project Is Not Trusted once, with a Trust Project… action. If you start the server yourself from the Haxe Compilation Server tool window, a Trust Project? dialog asks first. Choose Trust Project to trust the project and continue. See Your First Project for the trust prompt when a project opens.
The Haxe Compilation Server tool window shows one tab for each server, named after its SDK (and the module, for a server for one module), and one tab for each display process, named the same way followed by (display). Each tab has:
- the process's console output, starting with the command line it was started with; a compiler request that fails prints a red line there with its method, how long it took and the reason,
- a status view with the modules whose compiler requests fail, request statistics and Refresh Server Stats, which shows how much memory the server's cache uses; a Haxe 3 server prints its report to the console instead,
- a toolbar with Start Compilation Server, Restart Compilation Server and Stop Compilation Server, or Start Display Process, Restart Display Process and Stop Display Process on a display process's tab.

A compilation server's tab, with the toolbar (1), the command line the server was started with (2) and the status view (3)
The request statistics count the requests the editor features sent to the process: how many there were and how many failed, how long the last one and the average one took, and how many are still waiting for an answer. The handshake the plugin sends to a freshly started process is not counted. A tab's icon turns red while compiler requests fail.
Before any server has started, the tool window shows a short message and a Start Compilation Server button.
- Restart Compilation Server starts the server with an empty cache. The plugin also forgets everything it learned from the old server and highlights your files again. Restart Display Process does the same for a display process.
- Stop Compilation Server and Stop Display Process stop the process, but the next build or editor request that needs it starts it again. To keep the server off, turn it off in the settings or for the module.
- Closing a tab stops its process and removes the tab.
Tip
The plugin does not notice when you edit a file that a macro reads, such as a layout file a build macro turns into fields. Use Restart Compilation Server to see the new generated members, or Restart Display Process while the editor's requests go to a display process.
When the same Flash or AIR build (-swf) is compiled a second time through the same compilation server, the SWF can
be broken: the app fails at start with VerifyError #1053. This is a bug in the Haxe compiler since Haxe 4.1, Haxe 5
included. The first build after the server starts is correct.
To get a clean build:
- In the Haxe Compilation Server tool window, use Restart Compilation Server, then build again. The first build after a restart is correct.
- Or turn the server off for the module: in the Haxe tool window, click the value of the module's Compilation server row, then build. The module then builds without the server until you turn it back on.
When the compiler cannot answer for a module, the Compilation server row in the Haxe tool window adds a red (compiler requests failing). Any compiler-backed request can set it: diagnostics, completion, navigation and the lookup of generated members. Hover over the row to read the reason, or click the red text to open the Haxe Compilation Server tool window, where the status view shows the full error.
A common reason is that the build itself does not compile, for example because a define override breaks a library. The error then starts with Build context does not compile — fix these errors: and lists the compiler errors. Fix the build or the override; the plugin tries again with the next request.
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