Skip to content

Latest commit

 

History

History
4227 lines (3728 loc) · 160 KB

README.md

File metadata and controls

4227 lines (3728 loc) · 160 KB

Table of Contents generated with DocToc

Elixir plugin

Build Status

This is a plugin that adds support for Elixir to JetBrains IDEs.

The plugin works both in the rich IDEs that allow alternative language SDK selection and small IDEs that are language specific. The rich IDEs work best for IntelliJ Elixir because only in the rich IDEs can have an Elixir SDK set as the Project SDK. In all small IDEs, the native language SDK is always there, which makes anything that uses the SDK, such as running elixir, erl, or mix more complicated both internally and externally in the configuration you have to setup.

IDEs

The plugin is free to use in all JetBrains IDEs. The Cost column in the below table is what JetBrains charges for the IDE itself. IntelliJ Elixir is maintained by @KronicDeth who does not get any of the subscription money. If you want to support the plugin itself, make a donation.

IDE Rich/Small Languages Cost Trial License Source
IntelliJ IDEA Community Edition Rich Java Free N/A Apache 2.0 JetBrains/intellij-community
IntelliJ IDEA Ultimate Edition Rich Java Subscription 30-days Commercial N/A
AppCode Small Objective-C Subscription 30-days Commercial N/A
CLion Small C/C++ Subscription 30-days Commercial N/A
DataGrip Small SQL Subscription 30-days Commercial N/A
Gogland Small Go Free N/A Early Access Preview N/A
PHPStorm Small PHP Subscription 30-days Commercial N/A
PyCharm Community Edition Small Python Free N/A Apache 2.0 JetBrains/intellij-community subdirectory
PyCharm Professional Edition Small Python Subscription N/A Commercial N/A
Rider Small .NET Subcription N/A Commercial N/A
RubyMine Small Ruby Subscription 30-days (90-day for whole team) Commercial N/A
WebStorm Small JavaScript Subscription 30-days Commercial N/A

Once you have your IDE of choice installed, you can install this plugin

Features

Feature Rich Small Alternative
Project Yes No 1. Open directory
2. Elixir SDK Path in External Elixir Tools
Project Structure Automatic Manual
Project Settings Yes No
Module Settings Yes No
New Elixir File Yes Yes
Syntax Highlighting and Semantic Annotation Yes Yes
Grammar Parsing Yes Yes
Inspections Yes Yes
Quick Fixes Yes Yes
Code Folding Yes Yes
Commenter Yes Yes
Debugger Yes Yes
Delimiters Yes Yes
Embedded Elixir (EEx) Templates Yes Yes
Building/Compiling Yes No Build/compile as part mix run configurations only
Live Templates Yes Yes
Run Configurations Yes Yes
Completion Yes Yes
Decompilation Yes Yes
Go To Declaration Yes Yes
Formatting Yes Yes
Go To Symbol Yes Yes
Go To Test Yes Yes
Go To Test Subject Yes Yes
Find Usage Yes Yes
Refactor Yes Yes
SDK Yes No Elixir SDK Path in External Elixir Tools
Structure Yes Yes

Project

NOTE: This feature only works in Rich IDEs as it depends on an extension point unavailable in Small IDEs. To setup a project in a Small IDE
  1. Open Directory of the project
  2. Setup the Elixir SDK Path in External Elixir Tools

From Existing Sources

Import project from external model

If you've already created a mix project, you can load it as an Elixir project into the plugin.

  1. File > New > Project From Existing Sources...
  2. Select the root directory of your project.
  3. Select "Import project from external model"
  4. Select Mix File > New Project > From Existing Sources > Import project from external model > Mix
  5. Click Next
  6. The "Mix project root" will be filled in with the selected directory.
  7. (Optional) Uncheck "Fetch dependencies with mix" if you don't want to run mix deps.get when importing the project
    • If "Fetch dependencies with mix" is checked both mix local.hex --force and mix deps.get will be run.
  8. Ensure the correct "Mix Path" is detected. On Windows, the mix.bat, such as C:\Program Files (x86)\Elixir\bin\mix.bat should be used instead of the mix file without the extension.
  9. Ensure the "Mix Version" is as expected. The number in parentheses should match the Elixir version.
  10. Click Next
  11. All directories with mix.exs files will be selected as "Mix projects to import". To import just the main project and not its dependencies, click Unselect All.
  12. Check the box next to the project root to use only its mix.exs. (It will likely be the first checkbox at the top.)
  13. Click Next
  14. Select a Project SDK directory by clicking Configure.
  15. The plugin will automatically find the newest version of Elixir installed. (NOTE: SDK detection only works for Linux, homebrew installs on OSX, and Windows. Open an issue with information about Elixir install locations on your operating system and package manager to have SDK detection added for it.)
  16. If the automatic detection doesn't find your Elixir SDK or you want to use an older version, manually select select the directory above the bin directory containing elixir, elixirc, iex, and mix. (On Windows it is the directory containing elixir.bat, elixirc.bat, iex.bat, and mix.bat.)
  17. Click Finish after you select SDK name from the Project SDK list.
Create project from existing sources

If you've already created a (non-mix) project, you can load it as an Elixir project into the plugin.

  1. File > New > Project From Existing Sources...
  2. Select the root directory of your project.
  3. Leave the default selection, "Create project from existing sources"
  4. Click Next
  5. Project name will be filled with the basename of the root directory. Customize it if you like.
  6. Project location will be the root directory.
  7. Click Next.
  8. If you previously opened the directory in IntelliJ or another JetBrains IDE, you'll be prompted to overwrite the .idea directory. Click Yes.
  9. You'll be prompted with a list of detected Elixir project roots to add to the project. Each root contains a mix.exs. Uncheck any project roots that you don't want added.
  10. Click Next.
  11. Select a Project SDK directory by clicking Configure.
  12. The plugin will automatically find the newest version of Elixir installed. (NOTE: SDK detection only works for Linux, homebrew installs on OSX, and Windows. Open an issue with information about Elixir install locations on your operating system and package manager to have SDK detection added for it.)
  13. If the automatic detection doesn't find your Elixir SDK or you want to use an older version, manually select select the directory above the bin directory containing elixir, elixirc, iex, and mix.
  14. Click Next after you select SDK name from the Project SDK list.
  15. Click Finish on the framework page. (No framework detection is implemented yet for Elixir.)
  16. Choose whether to open in a New Window or in This Window.

New

If you want to create a basic (non-mix) Elixir project with a lib directory, perform the following steps.

  1. File > New > Project File > New > Project
  2. Select Elixir from the project type menu on the left
  3. Click Next File > New > Project > Elixir
  4. Select a Project SDK directory by clicking Configure. Project SDK
  5. Select a Project SDK directory by clicking Configure.
  6. The plugin will automatically find the newest version of Elixir installed.
    • macOS / OSX
      • Homebrew (/usr/local/Cellar/elixir)
      • Nix (/nix/store)
    • Linux
      • /usr/local/lib/elixir
      • Nix and NixOS (/nix/store)
    • Windows
      • 32-bit (C:\Program Files\Elixir)
      • 64-bit (C:\Program Files (x86)\Elixir)
      • (NOTE: SDK detection only works for Open an issue with information about Elixir install locations on your operating system and package manager to have SDK detection added for it.)
  7. If the automatic detection doesn't find your Elixir SDK or you want to use an older version, manually select select the directory above the bin directory containing elixir, elixirc, iex, and mix. If the bin, lib, or src directory is incorrectly selected, it will be corrected to the parent directory.
  8. Click Next after you select SDK name from the Project SDK list.
  9. Change the Project name to the name your want for the project File > New > Project > Settings
  10. (Optionally) change the Project location if the directory does not match what you want
  11. (Optionally) expand More Settings to change the Module name, Content root, Module file location, and/or Project format. The defaults derived from the Project name and Project location should work for most projects.
  12. Click Finish
  13. Choose whether to open in a New Window or in This Window. File > New > Project > Window

Project Structure

Project View

  • Excluded
    • _build (Output from mix)
    • rel (Output from exrm)
  • Sources
    • lib
  • Test Sources
    • test

Project Settings

Project Settings

The Project Settings include

  • Project Name
  • Project SDK

Module Settings

Sources

Module Settings > Sources

The Module Settings include Marking directories as

  • Excluded
  • Sources
  • Tests

Paths

Module Settings > Paths

Module paths list the output directories when compiling code in the module. There is a an "Output path" for dev MIX_ENV and "Test output path" for the test MIX_ENV.

Dependencies

Module Settings > Dependencies

Module dependencies are currently just the SDK and the sources for the module. Dependencies in deps are not automatically detected at this time.

New Elixir File

  1. Right-click a directory (such as lib or test in the standard mix new layout)
  2. Select New > Elixir File. New > Elixir File
  3. Enter an Alias for the Module name, such as MyModule or MyNamespace.MyModule.
  4. Select a Kind of Elixir File to use a different template. New > Elixir File > Kind

Empty module

An underscored file will be created in an underscored directory lib/my_namespace/my_module.ex) with the given module name with be created:

defmodule MyNamespace.MyModule do
  @moduledoc false

end

Elixir Application

An underscored file will be created in an underscored directory lib/my_namespace/my_module.ex) with the given module name with be created. It will have a start/2 function that calls MyNamespace.MyModule.Supervisor.start_link/0.

defmodule MyNamespace.MyModule do
  @moduledoc false

  use Application

  def start(_type, _args) do
    MyNamespace.MyModule.Supervisor.start_link()
  end
end

Elixir Supervisor

An underscored file will be created in an underscored directory lib/my_namespace/my_module.ex) with the given module name with be created. It will have a start_link/1 function that calls Supervisor.start_link/0 and init/1 that sets up the child specs. It assumes a MyWorker child that should be supervised :one_for_one.

defmodule MyNamespace.MyModule.Supervisor do
  @moduledoc false

  use Supervisor

  def start_link(arg) do
    Supervisor.start_link(__MODULE__, arg)
  end

  def init(arg) do
    children = [
      worker(MyWorker, [arg], restart: :temporary)
    ]

    supervise(children, strategy: :one_for_one)
  end
end

Elixir GenServer

An underscored file will be created in an underscored directory lib/my_namespace/my_module.ex) with the given module name with be created. It will have a start_link/2 function that calls GenServer.start_link/3 and the minimal callback implementations for init/1, handle_call/3, and handle_cast/2.

The Elixir use GenServer supplies these callbacks, so this template is for when you want to change the callbacks, but would like the stubs to get started without having to look them up in the documentation.

defmodule MyNamespace.MyModule do
  @moduledoc false

  use GenServer

  def start_link(state, opts) do
    GenServer.start_link(__MODULE__, state, opts)
  end

  def init(_opts) do
    {:ok, %{}}
  end

  def handle_call(_msg, _from, state) do
    {:reply, :ok, state}
  end

  def handle_cast(_msg, state) do
    {:noreply, state}
  end
end

Elixir GenEvent

An underscored file will be created in an underscored directory lib/my_namespace/my_module.ex) with the given module name with be created. The minimal callback implementations for init/1, handle_event/2, and handle_call/2, handle_info/2.

The Elixir use GenEvent supplies these callbacks, so this template is for when you want to change the callbacks, but would like the stubs to get started without having to look them up in the documentation.

defmodule MyNamespace.MyModule do
  @moduledoc false

  use GenEvent

  # Callbacks

  def init(_opts) do
    {:ok, %{}}
  end

  def handle_event(_msg, state) do
    {:ok, state}
  end

  def handle_call(_msg, state) do
    {:ok, :ok, state}
  end

  def handle_info(_msg, state) do
    {:ok, state}
  end
end

Syntax Highlighting and Semantic Annotation

Syntax highlighting of lexer tokens and semantic annotating of parser elements can be customized in in the Color Settings page for Elixir (Preferences > Editor > Color & Fonts > Elixir).

Text Attribute Key Display Name Tokens/Elements Scheme
Default Darcula
Alias String
Atom
  • :one
  • <<>>:
Braces and Operators Bit
  • <<
  • >>
Braces and Operators Braces
  • {
  • }
Braces and Operators Brackets
  • [
  • ]
Braces and Operators Character Token ?
Braces and Operators Comma ,
Braces and Operators Dot .
Braces and Operators Interpolation
  • #{
  • }
Braces and Operators Maps and Structs Maps
  • %{
  • }
Braces and Operators Maps and Structs Maps
  • %
  • {
  • }
Braces and Operators Operation Sign
  • =
  • +
  • *
  • ==
  • !
  • &&
  • ||
  • |>
  • ^
Braces and Operators Parentheses
  • (
  • )
Braces and Operators Semicolon ;
Calls Function inspect *Only the Italic attribute *Only the Italic attribute
Calls Macro inspect *Only the Bold and Italic attributes *Only the Bold and Italic attributes
Calls Predefined
  • Kernel
      • functions
      • macros
    • Kernel.SpecialForms
      • macros
*Only the Foreground attribute *Only the Foreground attribute
Comment # Numbers
Keywords end
Module Attributes @custom_attr
Module Attributes Documentation @doc
Module Attributes Documentation Text Simple module docstring
Module Attributes Types Callback func
Module Attributes Types Specification func
Module Attributes Types Type parameterized
Module Attributes Types Type Parameter type_parameter
Numbers Base Prefix Non-Decimal
  • 0b
  • 0x
  • 0o
Numbers Base Prefix Obsolete Non-Decimal
  • 0B
  • 0X
Numbers Decimal Exponent, Mark, and Separator
  • e
  • .
  • _
Numbers Digits Invalid
  • 2
  • o
  • r
  • 888
Numbers Digits Valid
  • 1234
  • 1A
  • beef
  • 123
Textual Character List 'This is a list'
Textual Escape Sequence \x{12}
Textual Sigil
  • ~r//
  • ~R''
  • ~w()
  • ~W()
Textual String "Hello world"
Variables Ignored _
Variables Parameter
  • a
  • b
  </td>
  <td>
    <img src="screenshots/preferences/editor/colors_and_fonts/default/Variables/Parameter.png?raw=true"/>
  </td>
  <td>
    <img src="screenshots/preferences/editor/colors_and_fonts/darcula/Variables/Parameter.png?raw=true"/>
  </td>
</tr>
<tr>
  <td>Variables</td>
  <td>Variable</td>
  <td></td>
  <td>
    <code>pid</code>
  </td>
  <td>
    <img src="screenshots/preferences/editor/colors_and_fonts/default/Variables/Variable.png?raw=true"/>
  </td>
  <td>
    <img src="screenshots/preferences/editor/colors_and_fonts/darcula/Variables/Variable.png?raw=true"/>
  </td>
</tr>

Grammar parsing

Built on top of highlighted tokens above, the parser understands the following parts of Elixir grammar as valid or allows the grammar because they contain correctable errors:

  • Empty Parentheses (())
  • Keyword Lists
    • Keyword Keys - Aliases, identifiers, quotes, or operators when followed immediately by a colon and horizontal or vertical space.
    • Keyword Values - Empty parentheses (()) and matched expressions.
  • Matched Expressions, in other words, unary and binary operations on variable, function, and macro names and values (numbers, strings, char lists, sigils, heredocs, true, false, and nil).
  • No Parentheses expressions, which are function calls with neither parentheses nor do blocks that have either (1) a positional argument and keyword arguments OR (2) two or more positional arguments with optional keyword arguments.
  • Anonymous function calls .() with either no arguments; a no parentheses arguments expression as an argument; keywords as an argument; positional argument(s); or positional arguments followed by keywords as arguments.
  • Remote function calls (Alias.function, :atom.function, etc) and local function calls (function) with...
    • No Parentheses with...
      • No Arguments (Alias.function)
      • Keywords (Alias.function key: value)
      • Nested No Parentheses Call (Alias.function Inner.function positional, key: value)
      • Positional and Keyword arguments (Alias.function positional, key: value)
      • Matched Expression (Alias.function 1 + 2)
    • Parentheses with...
      • No arguments (Alias.function())
      • No Parentheses Call (Alias.function(Inner.function positional, key: value)
      • Keywords (Alias.function(key: value))
      • Positional and Keyword arguments (Alias.function(positional, key: value))
      • Trailing parentheses for quoting (def unquote(variable)(positional))
  • Bracket expression (variable[key])
  • Block expressions (function do end)
  • Unmatched expressions, in other words combinations of block expressions and matched expressions.

Inspections

Inspections mark sections of code with warnings and errors. They can be customized from the Preferences > Inspections > Elixir.

Elixir Inspections

Ambiguous nested calls

Detects when compiler will throw unexpected comma. Parentheses are required to solve ambiguity in nested calls. Function calls with multiple arguments without parentheses cannot take as arguments functions with multiple arguments without parentheses because which functional gets which arguments is unclear as in the following example:

outer_function first_outer_argument,
               # second argument is another function call without parentheses, but with multiple arguments
               inner_function first_inner_argument,
               ambiguous_keyword_key: ambiguous_keyword_value

To fix the ambiguity if first_inner_keyword_key: first_inner_keyword_value should be associated, add parentheses around the inner function's arguments:

# keywords are for inner function
outer_function first_outer_argument
               inner_function(
                 first_inner_argument
                 ambiguous_keyword_key: ambiguous_keyword_value
               )

# keywords are for outer function
outer_function first_outer_argument
               inner_function(
                 first_inner_argument
               ),
               ambiguous_keyword_key: ambiguous_keyword_value

Ambiguous nested calls preferences


Preferences > Inspections > Elixir > Ambiguous nested calls

Ambiguous nested calls error


Ambiguous nested call inspection marks the error on the comma that causes the ambiguity.

Ambiguous nested calls inspection


Mousing over the comma marked as an error in red (or over the red square in the right gutter) will show the inspection describing the error.

Ambiguous parentheses

Detects when compiler will throw unexpected parenthesis. If you are making a function call, do not insert spaces in between the function name and the opening parentheses. Function calls with space between the function name and the parentheses cannot distinguish between function calls with parentheses, but with an accidental space before the ( and function calls without parentheses where the first positional argument is in parentheses.

Empty Parentheses
function ()

To fix the ambiguity remove the space or add outer parentheses without the space if the first argument should be ():

# extra space, no arguments to function
function()

# first argument is `()`
function(())
Keywords in Parentheses
function (key: value)

Keywords inside parentheses is not valid, so the only way to fix this is to remove the space

function(key: value)
Positional arguments in Parentheses
function (first_positional, second_positional)

A list of positional arguments in parenthenses is not valid, so the only way to fix this is to remove the space

function(first_positional, second_positional)

Ambiguous parentheses preferences


Preferences > Inspections > Elixir > Ambiguous parentheses

Ambiguous parentheses error


Ambiguous parentheses inspection marks the error on the parenthetical group surrounded by the parentheses that are ambiguous due to the preceding space.

Ambiguous parentheses


Mousing over the parenthetical group marked as an error in red (or over the red square in the right gutter) will show the inspection describing the error.

Keyword pair colon (:) used in type spec instead of type operator (::)

Type specifications separate the name from the definition using ::.

@type name: definition

Replace the : with ::

@type name :: definition

Keywords appear before the end of list.

one.(
  one,
  two positional, key: value,
  three
)

Keywords can only appear at the end of an argument list, so either surround the no parentheses expression argument with parentheses, or move the the keywords to the end of the list if it wasn't meant to be a no parentheses expression.

one.(
  one
  two(positional, key: value),
  three
)

OR

one.(
  one,
  two,
  three,
  key: value
)

Keywords Not At End


Preferences > Inspections > Elixir > Keywords Not At End

Keywords Not At End error


Keywords Not At End inspection marks the error over the keywords that need to be surrounded by parentheses or moved to the end of the list.

Keywords Not At End inspection


Mousing over the keywords marked as an error in red (or over the red square in the right gutter) will show the inspection describing the error.

Match operator (=) used in type spec instead of type operator (::)

Type specifications separate the name from the definition using ::.

@type name = definition

Replace the = with ::

@type name :: definition

Quick Fixes

Quick Fixes are actions IntelliJ can take to change your code to correct errors (accessed with Alt+Enter by default).

Convert : to :: in type specs

If a type specification uses a single : instead of ::, then hit Alt+Enter on the : to change it to :: and fix the type spec.

Convert = to :: in type specs

If a type specification uses = instead of ::, then hit Alt+Enter on the = to change it to :: and fix the type spec.

Remove space in front of ambiguous parentheses

If a set of parentheses is marked as ambiguous then the space before it can be removed to disambiguate the parentheses with Alt+Enter. (Will vary based on keymap.)

Remove spaces before ambiguous parentheses


Hitting Alt+Enter on ambiguous parentheses error will bring up the Local Quick Fix, "Remove spaces between function name and parentheses". Hit Enter to accept and remove the space.

Code Folding

You can collapse (fold) pre-defined regions of your Elixir code to make it easier to quickly scroll through files or hide details you don't care about right now.

Controls

Collapsing
  1. Position cursor between lines with with downward facing - arrow and upward facing - arrow.
  2. Cmd+-
Expanding
  1. Position cursor on the collapsed line with the square +
  2. Cmd++

Regions

Expanded Collapsed Folded By Default?
do end do: ... No
-> and right operand -> ... No
@doc VALUE @doc "..." No
@moduledoc VALUE @moduledoc "..." No
@typedoc VALUE @typedoc "..." No
alias ALIAS1
alias ALIAS1
alias ... Yes
import ALIAS1
import ALIAS2
import ... Yes
require ALIAS1
require ALIAS2
require ... Yes
use ALIAS1
use ALIAS2
use ALIAS1 Yes
@for FOR in defimpl PROTOCOL, for: FOR Yes
@protocol PROTOCOL in defimpl PROTOCOL, for: FOR Yes
@MODULE_ATTRIBUTE VALUE in @MODULE_ATTRIBUTE VALUE No

Commenter

You can comment or uncomment the current line or selected block of source. By selecting a block of source first you can quickly comment out and entire function if you're trying to track down a compiling or testing error that's not giving a helpful line number.

Using the menus

  1. Highlight one or more lines
  2. Comment (or Uncomment) with one of the following: a. Code > Comment with Line Comment b. On OSX the key binding is normally Cmd+/.

Credo

Annotator

If credo is not installed as a project dependency, nothing will happen, but if it is installed, mix credo PATH will be called on any files after updates have quieted. Any credo check failures will show up as warning annotations

Warning Annotations

Individual check failures will show the explanation (from mix credo PATH:LINE(:COLUMN)) if you hover over the annotation

Explanation

You can hover over the explanation and click the embedded links to jump to the line (and column) where the failure occurred.

Inspection

Batch Mode

If you'd like to run the mix credo external annotator when it is disabled, you can run it using the inspection name.

  1. Analyze > Run Inspection By Name... (⌥⇧⌘I)
  2. Type "Credo"
  3. Select "Credo" from the shortened list
  4. Hit Enter.

You'll be presented with a "Run 'Credo'" dialog

Run 'Credo'

  1. Change the "Inspection scope" from "Whole project", which would include the deps to "Custom scope"
  2. Select "Project Production Files" from the "Custom scope" dropdown
  3. Click "OK"

The Inspections Result Tool Pane will open and show results as each file is processed.

  1. Click the ▶ to expand the Credo section to show all warnings

    Individual Entry

  2. Click an entry for the details of an individual warning with a code highlighting.

    Code Highlighting

    The view will show the parts of the file that aren't annotated as collapsed with the discontinuous line number indicating the jumps.

    If you click on + collapse markers, you can expand the collapsed sections to see the full context

    Expansion

    Or you can hover over the collapsed section to see a tooltip preview of the expansion

    Expansion Preview

Configuration

Preferences > Editor > Inspections Preferences > Editor > Inspections > Credo Editor Inspections
Elixir > Credo Include Explanation Highlight Message Explanation in tooltip mix credo Runs Highlight Message mix credo Runs Action
Per File Per Issue Working Directory Inspect Code Run Inspection By Name
Yes Yes Yes 1 1 Yes Yes 1 Yes Yes
Yes Yes No 1 0 Yes Yes 1 Yes Yes
ⁿ/ₐ No No No 0 0 Yes Yes 1 No Yes

If you want to limit the performance impact of the credo annotator because mix credo spikes your CPU, you can limit the number of mix credo runs to 1 per open file by disabling the Explanation tooltip

  1. Preferences > Editor > Inspections > Credo
  2. Uncheck "Include Explanation"

If you don't want the annotator to run at all on open editors, then you can disable the paired inspection

  1. Preferences > Editor > Inspections
  2. Uncheck Elixir > Credo

Once the annotator is disabled, you can still run the inspection in batch mode

Debugger

IntelliJ Elixir allows for graphical debugging of *.ex files using line breakpoints.

Line breakpoints for debugger can be set in gutter of editor tab.


Line breakpoints can added by clicking in the left-hand gutter of an editor tab. A red dot will appear marking the breakpoint. When a Run Configuration is Run with the Debug (bug) instead of Run (arrow) button, execution will stop at the breakpoint and you can view the local variables (with Erlang names) and the stackframes.

Steps

  1. Define a run/debug configuration
  2. Create breakpoints in the *.ex files
  3. Launch a debugging session
  4. During the debugger session, step through the breakpoints, examine suspended program, and explore frames.

Basics

After you have configured a run configuration for your project, you can launch it in debug mode by pressing Ctrl+D.

Keyboard Shortcuts
Action Keyword Shortcut
Toggle Breakpoint Cmd+F8
Resume Program Alt+Cmd+R
Step Over F8
Step Into F7
View breakpoint details/all breakpoints Shift+Cmd+F8
Environment Variables
Variable Example Description
INTELLIJ_ELIXIR_DEBUG_BLACKLIST iconv,some Excluding modules from debugger

Notice: If you want non Elixir. module in blacklist, write it with: :. This rule applies only to module atoms.

Breakpoints

When a breakpoint is set, the editor displays a breakpoint icon in the gutter area to the left of the affected source code. A breakpoint icon denotes status of a breakpoint, and provides useful information about its type, location, and action.

The icons serve as convenient shortcuts for managing breakpoints. Clicking an icon removes the breakpoint. Successive use of Alt - click on an icon toggles its state between enabled and disabled. The settings of a breakpoint are shown in a tooltip when a mouse pointer hovers over a breakpoint icon in the gutter area of the editor.

Status Icon Description
Enabled Red dot Indicates the debugger will stop at this line when the breakpoint is hit.
Disabled Red dot with green dot in center Indicates that nothing happens when the breakpoint is hit.
Conditionally Disabled Red dot with green dot in top-left corner This state is assigned to breakpoints when they depend on another breakpoint to be activated.

When the button Red dot surrounded by crossed-out circle is pressed in the toolbar of the Debug tool window, all the breakpoints in a project are muted, and their icons become grey: Grey dot.

Accessing Breakpoint Properties
Viewing all breakpoints

To view the list of all breakpoints and their properties, do one of the following:

  • Run > View Breakpoints
  • Shift+Cmd+F8
  • Click the Two red dots layered vertically on top of each other with smaller grey rings to right of the red dots
  • Breakpoints are visible in the Favorites tool window.
Viewing a single breakpoint

To view properties of a single breakpoint

  • Right-Click a breakpoint icon in the left gutter of the editor.
Configuring Breakpoints

To configure actions, suspend policy and dependencies of a breakpoint

  1. Open the Breakpoint Properties
    • Right-click a breakpoint in the left gutter, then click the More link or press Shift+Cmd+F8
    • Open the Breakpoints dialog box and select the breakpoint from the list
    • In the Favorites tool window, select the desired breakpoint, and click the pencil icon.
  2. Define the actions to be performed by IntelliJ IDEA on hitting breakpoint:
    • To notify about the reaching of a breakpoint with a text message in the debugging console, check the "Log message to console" check box. A message of the format *DBG* 'Elixir.IntellijElixir.DebugServer' got cast {breakpoint_reached, PID} will appear in the console.
    • To set a breakpoint the current one depends on, select it from the "Disabled until selected breakpoint hit" drop-down list. Once dependency has been set, the current breakpoint is disabled until selected one is hit.
      • Choose the "Disable again" radio button to disable the current breakpoint after selected breakpoint was hit.
      • Choose the "Leave enabled" radio button to keep the current breakpoint enabled after selected breakpoint was hit.
    • Enable suspending an application upon reaching a breakpoint by checking the "Suspend" check box.
Creating Line Breakpoints

A line breakpoint is a breakpoint assigned to a specific line in the source code.

Line breakpoints can be set on executable lines. Comments, declarations and empty lines are not valid locations for the line breakpoints.

  1. Place the caret on the desired line of the source code.
  2. Do one of the following:
    • Click the left gutter area at a line where you want to toggle a breakpoint
    • Run > Toggle Line Breakpoint
    • Cmd+F8
Describing Line Breakpoints
  1. Open the Breakpoints dialog
  2. Right-click the breakpoint you want to describe
  3. Select "Edit description" from the context menu
  4. In the "Edit Description" dialog box, type the desired description.
Searching for Line Breakpoints
  1. Open the Breakpoints dialog
  2. Start typing the description of the desired breakpoint
Jump to Breakpoint Source
  • To view the selected breakpoint without closing the dialog box, use the preview pane.
  • To open the file with the selected breakpoint for editing, double-click the desired breakpoint.
  • To close Breakpoints dialog, press Cmd+Down. The caret will be placed at the line marked with the breakpoint in question.
Disabling Line Breakpoints

When you temporarily disable or enable a breakpoint, its icon changes from to and vice versa.

  1. Place the caret at the desired line with a breakpoint.
  2. Do one of the following:
    • Run > Toggle Breakpoint Enable
    • Right-click the desired breakpoint icon, select or deselect the enabled check box, and then click Done.
    • Alt-click the breakpoint icon
Deleting Line Breakpoints

Do one of he following:

  • In the Breakpoints dialog box, select the desired line breakpoint, and click the red minus sign.
  • In the editor, locate the line with the line breakpoint to be deleted, and click its icon in the left gutter.
  • Place caret on the desired line and press Cmd+F8.

Starting the Debugger Session

  1. Select the run/debug configuration to execute
  2. Do one of the following
    • Click Bug on the toolbar
    • Run > Debug
    • Ctrl+D

OR

Debug quick menu

  1. Ctrl+Alt+D
  2. Select the configuration from the pop-up menu
  3. Hit Enter

Examining Suspended Program

Processes


The "Thread" drop-down lists the current processes in the local node. Only the current process is suspended. The rest of the processes are still running.
Frames


The Frames for the current process can be navigated up and down using the arrow keys or clicking on the frame.
  • Press Up or Down to change frames
  • Click the frame from the list
Jump to Current Execution Point

When changing frames or jumping to definitions, you can lose track of where the debugger is paused. To get back to the current execution point, do one of the following:

  1. Run > Show Execution Point.
  2. Alt+F10
  3. Click on the stepping toolbar of the Debug tool window.
Variables

While Elixir allows rebinding variable names, Erlang does not, so when viewed in the Variables pane, variables will have an @VERSION after their name indicating which rebinding of a the variable is. Even if there is no variable reuse, the first variable will still have @1 in its name.

Stepping

Action Icon Shortcut Description
Show Execution Point Alt+F10 Click this button to highlight the current execution point in the editor and show the corresponding stack frame in the Frames pane.
Step Over F8 Click this button to execute the program until the next line in the current function or file, skipping the function referenced at the current execution point (if any). If the current line is the last one in the function, execution steps to the line executed right after this function.
Step Into F7 Click this button to have the debugger step into the function called at the current execution point.
Step Out Shift+F8 Click this button to have the debugger step out of the current function, to the line executed right after it.

Delimiters

Auto-inserting

The right-delimiter will be automatically inserted when the left delimiter is typed. In some cases, to prevent false positives, the the delimiter is only completed if when used for sigils.

Preceded By Left Right
do end
fn end
[ ]
{ }
( )
' '
''' '''
" "
""" """
<< >>
~<sigil-name> < >
~<sigil-name> / /
~<sigil-name> ` `

Matching

All delimiters that are auto-inserted are also matched for highlighting

Left Right
do end
fn end
[ ]
{ }
( )
' '
''' '''
" "
""" """
<< >>
< >
/ /
` `

Embedded Elixir (EEx) Templates

Any file with .eex as the final extension will be treated as Embedded Elixir (EEx) templates. To determine the Template Data Language, the .eex extension will be stripped and any remaining extension will be looked up to get the File Type and its associated Language. For example, *.txt.eex will be EEx with Plain Text (.txt) as the Data Template Language. Likewise, *.html.eex will be EEx with HTML as the Data Template Language. There's no need to register *.txt.eex or *.html.eex or any other *.DATA_TEMPLATE_LANGUAGE_EXTENSION.eex pattern explicitly: the nested extension will be looked up using the normal extension setup.

Form Template

Parameter Usage in Form Template

Advanced configuration

If you need more file-by-file configuration of the Template Data Language than can be achieved with a file extension/pattern, IntelliJ IDEA (Community or Ultimate Edition) has support for setting the Template Data Language on a specific path.

  1. Preferences > Languages and Frameworks > Template Data Languages

See JetBrains Documentation for more details.

Building/Compiling

Settings

Build, Execution, Deployment > Compiler > Elixir Compiler

  • Compile project with mix (use mix compile instead of elixirc directly)
  • Attach docs (don't use --no-docs elixirc flag)
  • Attach debug info (don't use --no-debug-info elixirc flag)
  • Ignore module conflict (use --ignore-module-conflict elixirc flag)

Individual File

  1. Have a file selected in Project view with the Project view in focus OR have an Editor tab in focus
  2. Build > Compile 'FILE_NAME'
  3. Build results will be shown
    • If compilation is successful, you'll see "Compilation completed successfully" in the Event Log
    • If compilation had errors, you'll see "Compilation completed with N errors and M warnings" in the Event Log and the Messages Compile tab will open showing a list of Errors Messages Compile

Project

  1. Build > Make Project
  2. Build results will be shown
    • If compilation is successful, you'll see "Compilation completed successfully" in the Event Log
    • If compilation had errors, you'll see "Compilation completed with N errors and M warnings" in the Event Log and the Messages Compile tab will open showing a list of Errors Messages Compile

Live Templates

Live Templates are snippets of code that can be inserted quickly and have placeholder locations that the cursor will automatically jump to when using the template. Whenever you start typing, Live Templates will start matching against the shortcuts. A template can be selected with Tab.

Live Templates can be customized in Preferences > Editor > Live Templates > Elixir.

Metasyntactic variables are locations where the cursor will jump to. END is the final location of the cursor.
Shortcut Code
@doc

@doc """
ONE
"""
END
case

case ONE do
  TWO -> END
end
cond

cond do
  END
end
def

def NAME do
  END
end
def,

def NAME, do: END
defi

defimpl PROTOCOL, for: TYPE do
  END
end
defm

defmodule ALIAS do
  END
end
defmac

defmacro MACRO_NAME do
  END
end
defmacp

defmacrop MACRO_NAME do
  END
end
defover

defoverridable [NAME: END]
defp

defp NAME do
  END
end
defpro

defprotocol PROTOCOL do
  END
end
defs

defstruct [END]
do

do
  END
end
doc

@doc """
ONE
"""
END
fn

fn ARGS -> END end
for

for A <- B do
  END
end
if

if TRUE do
  END
end
ife

if TRUE do
  OK
else
  END
end
ii

IO.inspect(END)
mdoc

@moduledoc """
ONE
"""
END
rec

receive do
  ONE -> END
end
test

test "TESTDESC" do
  END
end
try

try do
  ONE
rescue
  TWO -> END

Run Configurations

Mix Tasks

Much like rake tasks in Rubymine, this plugin can run mix tasks.

  1. Run > Edit Configurations... Edit Run Configurations
  2. Click +
  3. Select "Elixir Mix" Add New Elixir Mix
  4. Fill in the "Program arguments" starting with the name of the mix task followed by any arguments to that task
  5. Fill in the "Working directory"
  • Type the absolute path to the directory.
  • Select the path using directory picker by clicking the ... button
  1. (Optionally) click the ... button on the "Environment variables" line to add environment variables.
  2. Click "OK" to save the Run Configuration and close the dialog
  3. Click the Run arrow in the Toolbar to run the mix task Run
  4. The Run pane will open, showing the results of the mix task.
    • If there is an error with a FILE:LINE stack frame, it will be a clickable link that will take you to that location Error link

mix test

The mix test task gets a special type of Run Configuration, Elixir Mix ExUnit. Using this Run Configuration type instead, of the basic Elixir Mix Run Configuration will cause the IDE to attach a special formatter to mix test, so that you get the standard graphical tree of Test Results

The Run pane will show Test Results. If there is a compilation error before or during mix test, it will be shown as a test failure. If the compilation failure is in a _test.exs file can it can be inferred from the stacktrace, the compilation error will show up as a test failure in that specific module.

doctest names are rearranged to emphasize the function being tested: "test doc at MODULE.FUNCTION/ARITY (COUNT)" becomes "MODULE.FUNCTION/ARITY doc (COUNT)". If MODULE is the same as the test case without the Test suffix, then MODULE is stripped too and the test name becomes only FUNCTION/ARITY doc (COUNT).

Creating mix test Run Configurations Manually
  1. Run > Edit Configurations... Edit Run Configurations
  2. Click +
  3. Select "Elixir Mix ExUnit" Add New Elixir Mix ExUnit
  4. Fill in the "Program arguments" with the argument(s) to pass to mix test. Normally, this will be a directory like test, relative to the "Working directory"
  5. Fill in the "Working directory"
  • Type the absolute path to the directory.
  • Select the path using directory picker by clicking the ... button
  1. (Optionally) click the ... button on the "Environment variables" line to add environment variables.
  2. Click "OK" to save the Run Configuration and close the dialog
  3. Click the RUn arrow in the Toolbar to run the mix test task
  4. The Run pane will open showing the Test Results Test Results

While you can create Elixir Mix ExUnit run configurations manually using the Run > Edit Configurations... menu, it is probably more convenient to use the context menu.

Creating mix test Run Configurations from context

The context menu must know that the the directory, file, or line you are right-clicking is a test. It does this by checking if the current directory or an ancestor is marked as a Test Sources Root.

  1. In the Project pane, ensure your OTP application's test directory is marked as a Test Sources Root
  2. Check if the test directory is green. If it is, it is likely a Test Sources Root. This color may differ in different themes, so to be sure you can check the context menu
  3. Right-click the test directory.
  4. Hover over "Mark Directory As >" * If "Unmark as Test Sources Root" is shown, then the directory is already configured correctly, and create from context will work. Mark Directory As > Unmark as Test Sources Root * If "Test Sources Root" is shown, then the directory need to be configured by clicking that entry Mark Directory As > Test Sources Root
Creating/Running mix test Run Configurations from directory
  1. Right-click the directory in the Project pane
  2. Click "Run Mix ExUnit", which will both create the Run Configuration and Run it. Run Mix ExUnit
  • If you want to only create the Run Configuration, select "Create Mix ExUnit" instead

Alternatively, you can use keyboard shortcuts

  1. Select the directory in the Project pane.
  2. Ctrl+Shift+R will create the Run Configuration and Run it.
Creating/Running mix test Run Configurations from file
  1. Right-click the file in the Project pane
  2. Click "Run Mix ExUnit", which will both create the Run Configuration and Run it.
  • If you want to only create the Run Configuration, select "Create Mix ExUnit" instead

Alternatively, you can use keyboard shortcuts

  1. Select the directory in the Project pane.
  2. Ctrl+Shift+R will create the Run Configuration and Run it.

Finally, you can use the editor tabs

  1. Right-click the editor tab for the test file you want to run Run Mix ExUnit
  2. Click "Run Mix ExUnit", which will both create the Run Configuration and Run it.
  • If you want to only create the Run Configuration, select "Create Mix ExUnit" instead
Creating/Running mix test Run Configurations from line

If you want to be able to run a single test, you can create a Run Configuration for a line in that test

  1. Right-click a line in the test file Run Mix ExUnit
  2. Click "Run Mix ExUnit", which will both create the Run Configuration and Run it.
  • If you want to only create the Run Configuration, select "Create Mix ExUnit" instead

Alternatively, you can use keyboard shortcuts

  1. Place the cursor on the line you want to test
  2. Ctrl+Shift+R will create the Run Configuration and Run it.

Completion

Aliases and Modules

When you start typing an Alias, completion will look in three locations:

  1. alias aliased names in the current file
    1. Suffix for alias Prefix.Suffix
    2. MultipleAliasA or MultipleAliasB for alias Prefix.{MultipleAliasA, MultipleAliasB}
    3. As for alias Prefix.Suffix, as: As
  2. Indexed module names (as available from Go To Symbol)
    1. Prefix.Suffix from defmodule Prefix.Suffix
    2. MyProtocol from defprotocol MyProtocol
    3. MyProtocol.MyStruct
      1. defimpl MyProtocol, for: MyStruct
      2. defimpl MyProtocol nested under defmodule MyStruct
  3. Nested modules under aliased names
    1. Suffix.Nested for alias Prefix.Suffix where Prefix.Suffix.Nested is an indexed module, implementation or protocol name.
    2. MultipleAliasA.Nested for alias Prefix.{MultipleAliasA, MultipleAliasB} where Prefix.MultipleAliasA.Nested alias Prefix.{MultipleAliasA, MultipleAliasB} is an indexed module, implementation or protocol name.
    3. As.Nested for alias Prefix.Suffix, as: As where Prefix.Suffix.Nested is an indexed module, implementation, or protocol name.
Aliases inside { }

When you start typing inside { } for alias Prefix.{} or import Prefix.{}, completion will look for nested modules under Prefix and then remove the Prefix., so completion will look like Suffix.

Function and Macro Calls

Completion uses the same presentation as Structure, so you can tell whether the name is function/macro (Time), whether it is public/private (Visibility) and the Module where it is defined. Between the icons and the Modules is the name itself, which is highlighted in bold, the parameters for the call definition follow, so that you can preview the patterns required for the different clauses.

Function and Macro Calls Completion

Qualified

Qualified functions and macro calls will complete using those functions and macros defined in the qualifying Module (defmodule), Implementation (defimpl) or Protocol (defprotocol). Completion starts as shown as . is typed after a qualifying Alias.

Unqualified

Function and macro calls that are unqualified are completed from the index of all function and macro definitions, both public and private. (The index contains only those Elixir functions and macro defined in parsable source, such as those in the project or its dependencies. Erlang functions and Elixir functions only in compiled .beam files, such as the standard library will not complete.) Private function and macros are shown, so you can choose them and then make the chosen function or macro public if it is a remote call.

Module Attributes

Module attributes declared earlier in the file can be completed whenever you type @ and some letter. If you want to see all module attributes, you can type @a, wait for the completions to appear, then delete the @ to remove the filtering to a.

Parameters and Variables

Parameter and variable usages can be completed whenever typing an identifier. The completions will include all variables know up from that part of the file. It can include variables from outside macros, like quote blocks.

Decompilation

.beam files, such as those in the Elixir SDK, the Elixir SDK's Internal Erlang SDK, and in your project's build directory will be decompiled to equivalent def and defmacro calls. The bodies will not be decompiled, only the call definition head and placeholder parameters. These decompiled call definition heads are enough to allow Go To Declaration, the Structure pane, and Completion to work with the decompiled .beam files.

.beam files are not detected purely by their file extension: the BEAM file format starts with a magic number, FOR1, that is checked for before decompiling.

Decompression

If the .beam module was compiled with the compressed compiler directive, which in Erlang looks like

-compile([compressed])

and in Elixir looks like

@compile [:compressed]

then the outer file format is GZip (which is detected by checking for the gzip magic number, 1f 8b, at the start of the file) and the .beam will be (stream) decompressed before the .beam header is checked and the chunks decoded.

Call definition macros

It turns out that in the .beam binary format there are no macros. This makes sense since the BEAM format was made for Erlang, which does not have macros, and only has functions. Elixir marks its macros in the compiled .beam by prefixing them with MACRO-.

There are 2 chunks in the BEAM format for function references: ExpT, which is for exports (because in Erlang module they are from -export), which are the public functions and macros; and LocT, which is for locals (anything not exported in Erlang), which are private functions and macros.

BEAM Chunk Atom Prefix Macro
ExpT MACRO- defmacro
ExpT N/A def
LocT MACRO- defmacrop
LocT N/A defp
defp with / in name

Much like there are no macros in BEAM, there are no anonymous functions either. Any anonymous function (using fn in Elixir or fun in Erlang) ends up being a named function in the LocT chunk. Anonymous functions names start with -, then the parent function's name, a / and a unique number for that scope.

As an example, Kernel has

defp unquote(:"-MACRO-binding/2-fun-0-")(p0, p1, p2, p3) do
  # body not decompiled
end

which is generated from the for in

 defmacro binding(context \\ nil) do
    in_match? = Macro.Env.in_match?(__CALLER__)
    for {v, c} <- __CALLER__.vars, c == context do
      {v, wrap_binding(in_match?, {v, [generated: true], c})}
    end
  end

-- Kernel.binding/1

Special handling of call definition names

Functions and macros can have names that aren't valid identifier names, so the decompiler has special handlers to detect these invalid identifiers and escape them to make decompiled code that is parsable as valid Elixir.

Handler Name/Arity Decompiled Reason
Infix Operator !=/2 left != right Infix operators are defined in infix position
!==/2 left !== right
&&/2 left && right
&&&/2 left &&& right
*/2 left * right
=+/2 left + right
=++/2 left ++ right
-/2 left - right
--/2 left -- right
->/2 left -> right
../2 left .. right
//2 left / right
::/2 left :: right
</2 left < right
<-/2 left <- right
<<</2 left <<< right
<<~/2 left <<~ right
<=/2 left <= right
<>/2 left <> right
<|>/2 left <|> right
<~/2 left <~ right
<~>/2 left <~> right
=/2 left = right
==/2 left == right
===/2 left === right
=>/2 left => right
=~/2 left =~ right
>/2 left > right
>=/2 left >= right
>>>/2 left >>> right
\\/2 left \\\\ right
^/2 left ^ right
^^^/2 left ^^^ right
and/2 left and right
in/2 left in right
or/2 left or right
|>/2 left |> right
||/2 left || right
|||/2 left ||| right
~=/2 left ~= right
~>/2 left ~> right
~>>/2 left ~>> right
Prefix Operator +/1 (+value) To prevent precedence errors, unary prefix operators, which also have binary infix operators of the same name need to be defined inside parentheses
-/1 (-value)
Unquoted %/2 unquote(:%)(p0, p1) Special forms need to defined as atom passed to unquote, as special forms are handled before macros defining the calls are applied
%{}/1 unquote(:%{})(p0)
&/1 unquote(:&)(p0)
./2 unquote(:.)(p0, p1)
<<>>/1 unquote(:<<>>)(p0)
do/n unquote(:do)(p0, ...) Keywords need to be escaped
fn/1 unquote(:fn)(p0) Special forms need to defined as atom passed to unquote, as special forms are handled before macros defining the calls are applied
unquote/1 unquote(:unquote)(p0)
unquote_splicing/1 unquote(:unquote_splicing)(p0)
{}/n unquote(:{})(p0, ...)
Capitalized/n unquote(:Capitalized)(p0, ...) Part of the Corba libraries in OTP have functions starting with a capital letter, which would be parsed as an Alias in Elixir if not unquoted.
#text#/1 unquote(:"#text#")(p0)
Part of the XML libraries in OTP have functions that start with or contain `#`, which would parse as a comment in Elixir if not unquoted in a double quoted atom.
Default name/n name(p0, ...) If no specialized handler is required, functions and macros are defined normally with pN for each parameter in the Nth position

Go To Declaration

Go To Declaration is a feature of JetBrains IDEs that allows you to jump from the usage of a symbol, such as a Module Alias, to its declaration, such as the defmodule call.

Alias

  1. Place the cursor over an Alias with an aliased name setup by alias
    1. Suffix if alias Prefix.Suffix called
    2. MultipleAliasA if alias Prefix.{MultipleAliasA, MultipleAliasB} called
    3. As if alias Prefix.Suffix, as: As
  2. Activate the Go To Declaration action with one of the following:
    1. Cmd+B
    2. Select Navigate > Declaration from the menu.
    3. Cmd+Click
  3. A Go To Declaration lookup menu will appear, allowing you to jump either the alias that setup the aliased name or jumping directly to defmodule of the unaliased name. Select which declaration you want
    1. Use arrow keys to select and hit Enter
    2. Click

Function or Macro

You'll know if function or macro usage is resolved and Go To Declaration will work if the call is annotated, which in the default themes will show up as italics.

Imported Functions or Macros
  1. Place the cursor over name of the function or macro call.
  2. Activate the Go to Declaration action with one of the following:
    1. Cmd+B
    2. Select Navigate > Declaration from the menu.
    3. Cmd+Click
  3. A Go To Declaration lookup menu will appear, allowing you to jump to either the import that imported the function or macro or jumping directly to the function or macro definition clause. Select which declaration you want.
    1. Use arrow keys to select and hit Enter
    2. Click
Local Functions or Macros
  1. Place the cursor over name of the function or macro call.
  2. Activate the Go to Declaration action with one of the following:
    1. Cmd+B
    2. Select Navigate > Declaration from the menu.
    3. Cmd+Click
  3. Whether a lookup a Go To Declaration lookup menu appears depends on the number of clauses in the function or macro definition:
    1. If there is only one clause in the function or macro definition, you'll jump immediately to that clause
    2. If there is more than one clause in the function or macro definition, a Go To Declaration lookup menu will appear, allowing you to jump to either the import that imported the function or macro or jumping directly to the function or macro definition clause. Select which declaration you want.
      1. Use arrow keys to select and hit Enter
      2. Click
Remote Functions or Macros
  1. Place the cursor over name of the function or macro call that is qualified by an Alias.
  2. Activate the Go to Declaration action with one of the following:
    1. Cmd+B
    2. Select Navigate > Declaration from the menu.
    3. Cmd+Click
    1. If there is only one clause in the function or macro definition, you'll jump immediately to that clause
    2. If there is more than one clause in the function or macro definition, a Go To Declaration lookup menu will appear, allowing you to jump to either the import that imported the function or macro or jumping directly to the function or macro definition clause. Select which declaration you want.
      1. Use arrow keys to select and hit Enter
      2. Click

Module

  1. Place the cursor over a fully-qualified Alias
    1. A.B in A.B.func()
    2. A.B in alias A.B
    3. B in alias A.{B, C}
  2. Activate the Go To Declaration action with one of the following:
    1. Cmd+B
    2. Select Navigate > Declaration from the menu.
    3. Cmd+Click

If you hold Cmd and hover over the Alias before clicking, the target declaration will be shown.

Go To Declaration Demonstration

Module Attribute

  1. Place the cursor over a @module_attribute
  2. Activate the Go To Declaration action with one of the following:
    1. Cmd+B
    2. Select Navigate > Declaration from the menu.
    3. Cmd+Click

If you hold Cmd and hover over the @module_attribute before clicking, the target declaration will be shown.

Parameters and Variables

  1. Place the cursor over a parameter or variable usage
  2. Active the Go To Declaration action with one of the following:
    1. Cmd+B
    2. Select Navigate > Declaration from the menu.
    3. Cmd+Click

If you hold Cmd and hover over the variable before clicking, it will say parameter or variable, which matches the annotation color.

Formatting

IntelliJ Elixir can reformat code to follow a consistent style.

  • do block lines are indented
  • do blocks end as the last argument of a no parentheses call unindents to the start of the call
  • If one clause of a multi-clause anonymous function wraps, all clauses wrap.
  • Indent after else
  • Indent map and struct keys
  • All keys wrap if any key wraps
  • No spaces around...
    • .
  • Spaces around...
    • and
    • in
    • or
    • when
  • Configure spaces around...
    • =
    • <- and \\
    • !=, ==, =~, !==, and ===
    • <, <=, >=, and >
    • + and -
    • * and /
    • Unary +, -, !, ^, and ~~~
    • ->
    • ::
    • |
    • || and |||
    • && and &&&
    • <~, |>, ~>, <<<, <<~, <|>, <~>, >>>, and ~>>
    • ..
    • ^^^
    • ++, --, .., <>
    • =>
  • Configure spaces before...
    • ,
  • No space after...
    • @
  • Spaces after...
    • not
    • fn
    • after
    • catch
    • rescue
    • key:
  • Configure space after...
    • &
    • ,
  • Configure spaces within...
    • { }
    • << >>
    • [ ]
    • ( )
  • No space around / in &NAME/ARITY and &QUALIFIER.NAME/ARITY
  • when wraps when its right operand wraps, so that guards start with when on a newline when they are too long.
  • Align |> at start of indented line for pipelines
  • Align end with start of call instead of start of line for do blocks in pipelines
  • Indent list elements when wrapped
  • Indent tuple elements when wrapped
  • Align type definition to right of ::
  • Align guard to right of when when guards span multiple lines
  • Align two operator (++, --, .., <>) operands, so that <> binaries are multiple lines align their starts instead of using continuation indent and being indented relative to first operand.
  • Align pipe | operands, so that alternates in types and specs are aligned instead of continuation indented relative to the first operand.
  • Comments in spec (that is above operands to | align with the operands
  • Remove newlines from pipelines, so that all pipelines start with an initial value or call and each |> is the start of a successive line.
  • Key exclusivity: if an association operation or keyword key is already on a line, the container value automatically has it's elements wrapped if there is nested associations or keyword pairs, so that two levels of keys are not on the same line.
  • Indent bit string (<< >>) elements when wrapped

Directory

All files in a directory can be reformatted.

Using context menu:

  1. Open the Project pane
  2. Right-click the directory
  3. Select Reformat Code
  4. Set the desired options in the Reformat Code dialog
  5. Click Run

Using keyboard shortcuts:

  1. Open the Project pane
  2. Select the directory
  3. Alt+Cmd+L
  4. Set the desired options in the Reformat Code dialog
  5. Click Run

File

Other File

All lines in a file can be reformatted.

Using context menu:

  1. Open the Project pane
  2. Right-click the file
  3. Select Reformat Code
  4. Set the desired options in the Reformat Code dialog
  5. Click OK

Using keyboard shortcuts:

  1. Open the Project pane
  2. Select the file
  3. Alt+Cmd+L
  4. Set the desired options in the Reformat Code dialog
  5. Click OK
Current File

All the lines in the current editor tab file can be reformatted with the current settings.

  • Code > Reformat
  • Alt+Cmd+L
    • Alt+Shift+Cmd+L to get the Reformat Code dialog.

Selection

A subset of a file can be reformatted.

  1. Highlight the selection
  2. Use the Reformat Code action
    • Code > Reformat Code
    • Alt+Shift+Cmd+L

Go To Symbol

Go To Symbol is a way to search for any of the following by name:

  • Call definition clauses (def, defp, defmacro, and defmacrop)
  • Callbacks (@callback and @macrocallback)
  • Call definition specifications (@spec)
  • Call definition heads (foo(bar)) for delegation (defdelegate foo(bar), to: BAZ)
  • Implementations (defimpl)
  • Protocols (defprotocol)

You can bring up Go To Symbol with the keyboard shortcut (⌥⌘O on OSX) or using the menus (Navigate > Symbol...).

Go To Test

Go to Test allows you to jump from the a Source Module to its corresponding Test Module

  1. Have the cursor in the body of a Module
  2. Active the Go To Test action with one of the following:
    1. Shift+Cmd+T
    2. Select Navigate &gt Test from the menu.

Go To Test Subject

Go to Test Subject allows you to jump from the a Test Module to its corresponding Source Module

  1. Have the cursor in the body of a Test Module
  2. Active the Go To Test Subject action with one of the following:
    1. Shift+Cmd+T
    2. Select Navigate &gt Test Subject from the menu.

Find Usage

Find Usage is a feature of JetBrains IDEs that allows you to find all the places a declared symbol, such a Module Alias in a defmodule, is used, including in strings and comments.

Module

  1. Place cursor over an defmodule Alias.
  2. Activate the Find Usage action with one of the following: a. i. Right-click the Alias ii. Select "Find Usages" from the context menu b. Select Edit > Find > Find Usages from the menu c. Alt+F7

Find Module Usage Demonstration

Module Attribute

  1. Place cursor over the @module_attribute part of the declaration @module_attribute value.
  2. Activate the Find Usage action with one of the following: 1. 1. Right-click the module attribute 2. Select "Find Usages" from the context menu 2. Select Edit > Find > Find Usages from the menu 3. Alt+F7

Parameters and Variables

  1. Place cursor over the parameter or variable declaration.
  2. Active the Find Usage action with one of the following: 1. 1. Right-click the Alias 2. Select "Find Usages" from the context menu 2. Select Edit > Find > Find Usages from the menu 3. Alt+F7

Refactor

Rename

Module Attribute
  1. Place the cursor over the @module_attribute usage or declaration.
  2. Active the Rename Refactoring action with one of the following: 1. 1. Right-click the module attribute 2. Select Refactoring from the context menu 3. Select "Rename..." from the Refactoring submenu 2. Shift+F6
  3. Edit the name inline and have the declaration and usages update.
Parameters and Variables
  1. Place the cursor over the parameter or variable usage or declaration
  2. Active the Rename Refactoring action with one of the following: 1. 1. Right-click the module attribute 2. Select Refactoring from the context menu 3. Select "Rename..." from the Refactoring submenu 2. Shift+F6
  3. Edit the name inline and have the declaration and usages update.

SDK

NOTE: These instructions only apply to Rich IDEs, for a Small IDE use Elixir SDK Path

Because Elixir is built on top of Erlang, Elixir command line commands don't have OS native binaries, instead the OS native binaries from Erlang are used. In order to reliably find the Erlang OS native binaries, like erl and erl.exe, the path to BOTH the Erlang SDK and the Elixir SDK must be configured. This allows you to install Erlang and Elixir with completely different package managers too: you can install Erlang with kerl and Elixir with kiex and you don't have to worry about IntelliJ not seeing the environment variables set by kerl when launching IntelliJ from an application launchers instead of a terminal.

Since JetBrains' OpenAPI only supports one SDK per Project or Module, to support Elixir and Erlang SDK at the same time, the Elixir SDK keeps track of an Internal Erlang SDK. When setting up your first Elixir SDK, you will be prompted to create an Erlang SDK (if you have the intellij-erlang plugin installed) or and Erlang for Elixir SDK (if you don't have intellij-erlang installed and you need to use the minimal Erlang for Elixir SDK supplied by this plugin).

With the Elixir SDK setup with an Internal Erlang SDK, you can see the Elixir SDK name and the home path, but unlike other SDKs, there's a dropdown for changing the Internal Erlang SDK.

Internal Erlang SDK

You'll notice there is a mix of two different parent paths in Class Paths:

  1. Those from the Elixir SDK Home Directory, which are the lib/APP/ebin for the APPs that ships with Elixir: eex, elixir, ex_unit, iex, logger, and mix.

    Elixir SDK Home Directory Class Paths.png

  2. Those from the Internal Erlang SDK Home Directory, which are the lib/APP-VERSION/ebin for the APPs that ship with OTP.

    Erlang SDK Home Directory Class Paths.png

The Class Paths are combined from the two SDKs because OpenAPI doesn't allow to dynamically delegate to the Internal Erlang SDK when checking for Class Paths to scan for completion and running. If you change the Internal Erlang SDK in the dropdown, the Class Paths will be updated to remove the old Internal Erlang SDK Class Paths and add the new Internal Erlang SDK Class Paths.

These Class Paths are not just for code completion and search anymore, all paths listed as passed with -pa flag to erl or erl.exe when running mix, so that you can mix different versions of OTP applications shipped with different version of OTP, so you can take advantage of the independently updatable OTP apps in the release notes for OTP. Code Paths.png

Default SDK

  1. The default SDK for new projects can we set from the Configure menu on Welcome Screen

  2. Hover over "Project Defaults" to see its submenu

    Project Defaults

  3. Select "Project Structure" from the submenu

    Project Structure

  4. IntelliJ will start out with no default SDK. To make the default SDK, an Elixir SDK, Click New

    No SDK

  5. Select "Elixir SDK"

    Elixir SDK

  6. You'll get "Cannot Create SDK" message because there are no Erlang SDKs for the Elixir SDK to use as an Internal Erlang SDK. Click OK to create the Erlang SDK first.

    Cannot Create SDK

  7. You'll be actually prompted to Select Home Directory for the Erlang SDK

    • If you have the intellij-erlang plugin installed, you'll create an Erlang SDK from it.

      Erlang SDK

      NOTE: Erlang SDK's default Home Directory favors the oldest version of Erlang installed. You probably want the newest version. To manually select the Home Directory, it is the directory that contains the bin, erts-VERSION, and lib subdirectories. For Homebrew, the path looks like /usr/local/Cellar/erlang/VERSION/lib/erlang. It is important to select the lib/erlang directory and not the VERSION directory for intellij-erlang to accept it as a Home Directory.

    • If you don't have intellij-erlang installed, then you'll create and Erlang for Elixir SDK, which is supplied by this plugin.

  8. With an Erlang SDK available to use as the Internal Erlang SDK, you'll be prompted for the Home Directory for the Elixir SDK.

    Elixir SDK Home Directory

Elixir External Tools

Elixir External Tools in Rich IDEs

In a Rich IDE, like IntelliJ IDEA, only the path to mix is configured as an external tool. This mix path is only used when creating new projects, so when opening a pre-existing project with Import project from external model, this doesn't even need to be set.

Elixir External Tools in Small IDEs

Elixir SDK Path

NOTE: To setup the SDK in a Rich IDE use Import project from external model or SDK

In a Small IDE, like Rubymine, the Project SDK is always a Ruby SDK, so to support a pseudo-Elixir-SDK in a Small IDE, the Elixir SDK Path can be set.

  1. Open Preferences > Other Settings > Elixir External Tools
  2. Set the Elixir SDK Path
  • Paste the path to an Elixir SDK
  • Click the ... to select the directory

The pattern for the Elixir SDK Path varies based on the OS and package manager you used to install Elixir

OS Package Manager Elixir SDK Path
OSX/macOS Homebrew /usr/local/Cellar/elixir/VERSION
OSX/macOS/Linux Nix /nix/store/HASH-elixir-VERSION
Windows 32-bit Erlang Solutions C:\Program Files\Elixir
Windows 64-bit Erlang Solutions C:\Program Files (x86)\Elixir
Linux Default /usr/local/lib/elixir

Structure

You can view the structure of the currently open editor tab using the Structure tool window.

Viewing Structure

  • View > Tool Windows > Structure
  • Click the Structure Button (normally in the left tool buttons)
    1. If you can't see the Tool Buttons, they can be enabled with View > Tool Buttons
  • Cmd+7

Buttons

Structure Buttons

The buttons in the Structure tool are broken into 4 categories:

Sorters

Structure Sorter Buttons

Icon Tooltip Description
Sort by Time Sort by Time When the defined callable is usable:
  1. Compile time
  2. Both or None
  3. Runtime
Macros are compile time while functions are runtime.
Sort by Visibility Sort by Visibility Whether the element visible outside its defining module:
  1. Public
  2. Private
Sort Alphabetically Sort Alphabetically Sort by name

NOTE: When any combination of sorters is turned on, they are sorted from left to right (as shown in the button bar), so with all 3 sorters on, the elements are first grouped by Time, then inside each Time group, they are sorted by Visibility, then in each Visibility group, they are sorted by name.

Providers

Structure Provider Buttons

The providers add nodes not in the text of the file, but that will appear in the compiled Module.

Icon Tooltip Description
Show Used Show Used In Modules that `use ` or `use , arg`, the elements from the last `quote` block in the `__using__/1` for `` are injected.
Expanders

Structure Expander Buttons

The expanders expand or collapse all the elements in the Structure tool window.

Icon Tooltip Description
Expand All Expand All Expand All Elements in the Structure tool window
Expand All Collapse All Collapse All Elements in the Structure tool window
Autoscrollers

Structure Autoscroller Buttons

The autoscrollers link together the editor tab's location and the Structure tool windows selected element.

Icon Tooltip Description
Autoscroll to Source Autoscroll to Source Clicking an element in the Structure tool window will scroll the editor window to the location of the corresponding source.
Autoscroll from Source Autoscroll from Source When moving the cursor in the editor window, the selected element in the Structure tool window will change to the corresponding element.

Elements

Icons
Time

The Time icons indicate whether the element is usable at compile time or runtime.

Icon Tooltip Description
Compile Time Compile Time The element is used or checked at compile time and (may) not even be accessible at run time, such as macros.
Runtime Runtime The element is usable at runtime, such as a function.
Visibility

The Visibility icons indicated whether the element is usable outside its defining Module.

Icon Tooltip Description
Public Public Public elements are accessible outside their defining Module.
Private Private Private elements are only accessible in their defining Module. The macros that define private elements usually end in p.
Call to Element
Call Icons Text Description
Macro Type Time Visibility Function Module Local Overridable Override
def Runtime Public Function NAME/ARITY Groups together def with the same name and arity.
Runtime Public Function Module Local NAME[(][ARGUMENTS][)][when ...] The function head for function clause, including the name, arguments, and when if present
defdelegate Runtime Module Local defdelegate append_first: false|true, to: ALIAS|ATOM Groups together all the delegated functions for a single defdelegate call.
defdelegate func(arg), to: ALIAS Runtime Public Function NAME/ARITY Groups together implied def and any explicit @spec for the given function head (func(arg))
defdelegate func(arg), to: ALIAS Runtime Public Function Module Local func(arg) The function head implied by the defdelegate list of function heads.
defexception Exception RELATIVE_ALIAS The exception has the same name as the parent Module, but will display with only the relative name (the last Alias without a .) with its location as the qualifying Alias.
defexception Struct %RELATIVE_ALIAS{} Exceptions are defined as structs, so any defexception also defines a struct with the same name.
defexception list_or_keywords Field NAME: DEFAULT_VALUE The fields and default values (or nil if a list is used instead of a keyword list) for the struct as passed in the first argument to defexception.
defimpl PROTOCOL, for: MODULE Protocol Override MODULE (PROTOCOL) defimpl defines a protocol implementation that defines a Module that concatenates the PROTOCOL name and the MODULE name. If no :for is given, then the outer Module is used.
defmacro Compile Time Public Function NAME/ARITY Groups together defmacro with the same name and arity.
Compile Time Public Function Module Local NAME[(][ARGUMENTS][)][when ...] The macro head for macro clause, including the name, arguments, and when if present
defmacrop Compile Time Private Function NAME/ARITY Groups together defmacrop with the same name and arity.
Compile Time Private Function Module Local NAME[(][ARGUMENTS][)][when ...] The macro head for macro clause, including the name, arguments, and when if present
defmacro AND defmacrop Compile Time Unknown Function NAME/ARITY Groups together defmacro AND defmacrop with the same name and arity. This will be a compile error, but is represented with Unknown Unknown for the Visibility until corrected.
defmodule ALIAS Module RELATIVE_ALIAS (QUALIFIER) Top-level Modules show only the ALIAS with no location, while qualified Aliases or nested Modules show the RELATIVE_ALIAS and the QUALIFIER as the location.
defoverridable Overridable Mark previously declared functions as overridable. Overridable functions are listed as children of this element.
defoverridable NAME: ARITY, ... Runtime Public Function Overridable NAME/ARITY The NAME and ARITY of the function that is overridable. Matches the icon and text for def, but with the addition of Overridable Overridable
defp Runtime Private Function NAME/ARITY Groups together def with the same name and arity.
Runtime Private Function Module Local NAME[(][ARGUMENTS][)][when ...] The function head for function clause, including the name, arguments, and when if present
def AND defp Runtime Unknown Function NAME/ARITY Groups together def AND defp with the same name and arity. This will be a compile error, but is represented with Unknown Unknown for the Visibility until corrected.
defprotocol PROTOCOL Protocol Overridable PROTOCOL The protocol name. Functions required by the protocol are children of this element.
defstruct Struct %RELATIVE_ALIAS{} Structs have the same RELATIVE_ALIAS as their parent Module.
defstruct NAME: DEFAULT_VALUE, ... Field NAME: DEFAULT_VALUE The fields and default values (or nil if a list is used instead of a keyword list) for the struct.

Installation

Inside IDE using JetBrains repository

  1. Preferences
  2. Plugins
  3. Browse Repositories
  4. Select Elixir
  5. Install plugin
  6. Apply
  7. Restart the IDE

Inside IDE using Github releases

In browser

  1. Go to releases.
  2. Download the lastest zip.

In IDE

  1. Preferences
  2. Plugins
  3. Install plugin from disk...
  4. Select the downloaded zip.
  5. Apply
  6. Restart the IDE.

Screenshots

Color Settings New Elixir File

Error reporting

If the plugin encounters an error, there is a custom error handler registered, so you can open a pre-populated issue in your browser.

  1. Click the red error notification in bottom right corner of the IDE window. Fatal IDE Errors
  2. Fill in a description of what you were doing when the error occurred.
  3. Click "Open Issue against https://github.com/KronicDeth/intellij-elixir"
  4. The IDE will open your browser to https://github.com/KronicDeth/intellij-elixir/issues/new Write New Issue
  5. The title will be filled as [auto-generated], but if you can summarize the issue, change the title.
  6. If the "Fatal IDE Errors" dialog has Attachments, copy their contents to the Attachments section of the issue body.
  7. Review for IP disclosures. This will be public, so use your best judgement of how much of your code to post in the issue.
  8. Click the "Preview" tab to ensure the Markdown formatting looks correct.
  9. Click "Submit new issue".

Donations

If you would like to make a donation you can use Paypal:

Donate

If you'd like to use a different donation mechanism (such as Patreon), please open an issue.

Work Time

As part of the DockYard's commitment to open source libraries and tools, it allows employees on DockYard Days (most Fridays) to work on those libraries and tools during normal work hours. As part of my (@KronicDeth's) DockYard Days, I've been able to spend the concentrated time I needed to get EEx support and performance improvements into IntelliJ Elixir that benefits both DockYard's usage of the tool on client projects, but also the community of users as a whole. The more rapid cadence of releases would not have been possible without DockYard Days.

If you're a developer of open source libraries or tools for the Ember or Elixir communities that can benefit DockYard and its client and would like to get the opportunity to help DockYard and its client with your open source and have your own DockYard Days, let them know

Donors

I'd like to thank those who have donated to help support this project.