Tezos and Michelson support
Last updated:

Abstract. The Tezos plugin adds strong support for the Michelson langauge. This is expected to cover more of the Tezos platform.

Michelson file editor in IntelliJ

Introduction

Tezos

Tezos is a new platform for smart contracts and decentralized applications. The following links are helpful if you’d like to learn more about Tezos and the related technologies:

Source code & support

The plugin is available on the central plugin repository at plugins.jetbrains.com.

Source
The source is available at GitHub’s tezos-intellij repository.
License
The Tezos plugin is OpenSource software and is available under the terms of the BSD-3-Clause license.
Issue tracker on GitHub
Report bug and issues you encounter on our issue tracker.
Feature requests
If you notice a missing feature of Tezos plugin, please don’t hesitate to post a new request on our issue tracker. Also, if you’d prefer a discussion via e-mail then contact me using the contact form.

Installation

This plugin is compatible with versions 2016.1 and later. It’s available for all IDEs based on the IntelliJ platform. This includes IntelliJ IDEA Community, IntelliJ IDEA Ultimate, PyCharm Professional, PyCharm Community, WebStorm, RubyMine, GoLand and others.

Detailed information and a list of all available versions of the plugin is available at Tezos on plugins.jetbrains.com.

The plugin is installed using IntelliJ┬« IDEA’s plugin manager, JetBrains offers detailed information how to do this.

The plugin’s name is Tezos.

Support for the Michelson language

Michelson is a programing language used to write smart contracts. See the whitepaper for all the details.

Tezos files contain the definitions of smart contracts. An empty contract looks like this:

1
2
3
parameter unit;
storage unit;
code {}

This contract has correct syntax. But it can’t be executed, as it’s semantically invalid.

The shortest valid contract looks like this:

1
2
3
4
5
6
7
parameter unit;
storage unit;
code {
        CDR;
        NIL operation;
        PAIR;
     }

File types

This plugins maps the pattern *.tz to the new Michelson file type.

File templates

You can create a new file using the built-in functionality:

New file popup with Michelson file type selected

There are basic templates included to create an empty contract:

New file dialog to create a new Michelson smart contract

Syntax highlighting

Syntax errors are highlighted:

  • illegal escape characters used in strings
  • unknown instruction
  • unexpected arguments passed to instructions
  • unexpected number of code blocks passed to instructions, e.g. IF {} {} {} or IF {}
  • comparable type not used where expected
  • unknown types
  • unknown data values
  • unexpected annotations, i.e. highlighting where an annotation wasn’t expected
  • unexpected number of annotations (type, variable and field annotations)

All syntax elements are configurable in the editor’s color scheme settings. Macro and instructions are highlighted differently.

Stack visualization

Instructions of the Michelson language are operating on a stack of values. Each instruction is able to modify the stack. Stack visualization renders this modification in a separate panel inside of the editor.

Prerequisites

You need to configure at least one Tezos client. See below how to to configure this. If there’s more than one client, then the default client configuration will be used to retrieve the needed data.

Visualization

The stack visualization renders the stack for the current position of the text caret in the file. Place the caret on an instruction to see what it’s doing with the data on the stack.

On the left the data is shown as it is before the currently selected instruction was executed. On the right the data is shown as it would appear after the current instruction was executed.

In the screenshot above the instruction UNPAIR is selected. At first the data if of type pair bool bool. This is shown on the left side of the panel. After the instruction is executed the data on the stack is now two items of type bool. This is displayed on the right side of the panel.

Settings

Align stacks
When this setting is enabled then the data on the left and right side will be aligned to the bottom of the stack. This is a bit easier to read.
Highlight changes
Items which do not change are shown in a slightly lighter color. This allows to quickly identify the data which was changed by the current instruction.
Show annotations
Annotations for the data on the stack are not shown by default. Enable this to display annotations where they are available.

Quick documentation

View > Quick Documentation is supported for Michelson files. It provides documentation for instructions, macros, types and constant constructors. Most of the documentation was taken from the official Michelson whitepaper.

Documentation of instructions

Name and description are displayed. If an instruction is available for values of more than one type, then all of the matching descriptions are shown. For example, ADD is available for numbers, timestamps and mutez.

Documentation of macros

Name, desugared form, and a description are shown. The desugared form is the sequence of instructions which is equivalent to the macro. It’s not always possible to compute a static expansion as some macros depend on the type of stack elements. This is not yet supported by the plugin.

For example, the macro CDAAAR is equivalent to CDR; CAR; CAR; CAR.

Documentation of types

Name and description are shown for types.

Documentation of constant constructors

Name and description are shown for constant constructors. For example, (Pair 42 "foo") is a constructor of a Pair.

Code style & formatting

Some of the built-in code style settings are applied to Michelson files. These are:

  • Keep blank lines in code
  • Keep blank lines before right braces
  • Space withing parentheses
  • Space before semicolon
  • Space after semicolon

A few options which are specific to Michelson are available:

  • Align blocks of statements
  • Align line comments in blocks
  • Align types of complex types
  • Align annotations of complex types
  • Warp first block of statements
  • Wrap first type of complex types

Structure view

There’s basic support for structure view of Michelson files.

Code folding

Blocks of instructions are folded into {...} and contracts inside of CREATE_CONTRACT are folded into {CONTRACT ...}.

Live templates

The following live templates are available: - contract: Available at top-level of an michelson file. Insert an empty contract at the position of the caret.

Code completion

Sections

Sections are suggested at the top-level of a Michelson file. All sections are suggested when basic completion is performed. With smart completion only the still missing sections are suggested.

Instructions

The names of instructions are suggested when it’s valid to insert an instruction. This is at the beginning of a block {} (except for list literals) and after a semicolon ;. There’s no smart completion available for instructions.

Types

The names of types are suggested after an instruction and after tags.

Tags

The names of tags are suggested after an instruction.

Settings

You can find the setting of the plugin at File > Settings… > Languages & Frameworks > Tezos.

Tezos client configuration

The plugin uses the Tezos client to show stack visualization of Michelson smart contracts. The following types of clients are supported:

docker scripts alphanet.sh, or mainnet.sh
Scripts which controls docker containers running a certain type of Tezos nodes. Instructions to install the client scripts are available at tezos.gitlab.io. This is the recommended way to use Tezos.
standalone tezos-client
The client program which is started on the local machine. This needs the nodes running on this machine. Overall this is harder to setup than the docker scripts above.

Click on the plus icon to add a new client. A new item will be added to the table. You need to provide the following settings for each client:

Name
The name shown in the user interface when this client is used.
Default client
The default client is used to retrieve the information needed for the stack visualization.
Executable
The executable file to run the client. Enter the path to either tezos-client, alphanet.sh, or mainnet.sh. If the script file isn’t executable, then it will be run with bash, which is expected on the $PATH.

Stack visualization

The settings for Michelson stack visualization allow you to control how it’s shown inside of an editor.

The following settings are available:

Don't show
The stack visualization is hidden. In this case only the plain editor will be shown.
Right of the editor
The stack visualization will be shown at the right side of the text editor component. This is useful for wide screens with a lot of horizontal space.
Below the editor
The stack visualization will be shown below the text editor component.