Introducing ink! Analyzer

ink! analyzer is a collection of modular and reusable libraries and tools for semantic analysis of ink! smart contract code.

ink! analyzer aims to improve ink! language support in integrated development environments (IDEs), source code editors and other development tools by providing modular and reusable building blocks for implementing language features (e.g. diagnostic errors, quick fixes, code completion suggestions, code/intent actions and hover content e.t.c) for the ink! programming language which is used for writing smart contracts for blockchains built on Substrate.

Problem

ink! is an Embedded Domain Specific Language (eDSL) that you can use to write WebAssembly based smart contracts in the Rust programming language.
In fact, “ink! is just standard Rust in a well-defined “contract format” with specialized #[ink(…)] attribute macros”.

This allows ink! developers to leverage Rust tooling like clippy, cargo and excellent IDE/code editor support via rust-analyzer and IntelliJ Rust.

However, relying on only generic Rust language support in IDEs, code editors and other development tools has some significant limitations for the developer experience including:

  • No language support (e.g. diagnostic errors/warnings and quick fixes) for ink!'s domain specific semantic rules for smart contracts (e.g. exactly one #[ink(storage)] struct, at least one #[ink(message)] method and the same for #[ink(constructor)], ink! attributes should be applied to items of the correct type e.t.c).
  • Inconsistent editor experience with issues like no code completion and/or hover content for some ink! attribute arguments (e.g #[ink(payable)]) macro expansion/name resolution and trait resolution are hard problems for generic IDE/code editor tools.
  • No language support (e.g. go to definition, find references and rename/refactor) for ink! specific syntax like paths in ink! attribute argument values (e.g. env values).

Solution

To solve the above challenges and improve ink! language support in IDEs, code editors and other development tools, ink! analyzer creates two main components:

  • A modular domain-specific semantic analysis library for ink!.
  • A Language Server Protocol (LSP) implementation built on top of the aforementioned semantic analysis library.

These two components can be reused to add ink! language support to multiple IDEs, code editors and other development tools.

In particular, a large number of IDEs and code editors support LSP servers either via configurable LSP clients or robust LSP client libraries/APIs/modules, including Visual Studio Code, Visual Studio, Vim / Neovim, Emacs, Atom, Sublime Text, Acme, Lapce, Eclipse and many more.

This project makes it relatively easy for:

  • Users to enable ink! language support for their IDE, code editor or other development tool if it has either a native/built-in or third-party LSP client that can be configured to launch an LSP server using an executable command (i.e. the path to an installed ink! Language Server binary) and can use stdio (standard in/standard out) as the message transport.
  • Developers to either build extensions/plugins/integrations that add ink! language support to any tool with robust LSP client libraries/APIs/modules, or add first-class ink! language support to an existing LSP client (e.g. an open-source extension/plugin/integration).

In addition to distributing compiled ink! Language Server (ink-lsp-server) binaries for a few platforms,
ink! analyzer additionally distributes a Visual Studio Code extension that ships with a bundled ink! Language Server as a showcase and reference implementation for the latter use case.

Diving Deeper

You can read more about ink! analyzer in the full introductory blog post (including links to all resources mentioned above that I can’t share here because of forum rules that limit the number of links I can share in this post :slightly_smiling_face:) and/or checkout the ink! analyzer organization on GitHub for source code, technical documentation, and installation and usage instructions, links to useful resources (including distributable releases of the ink! Language Server and VS Code extensions for most of the major platforms/architectures).

Issues, bug reports, PRs and feature requests are welcome at the respective GitHub repositories :slightly_smiling_face:.

7 Likes

This is super cool, thanks for sharing! Have you looked into something similar for frame::pallet macros as well?

1 Like

@kianenigma thanks for the feedback :slightly_smiling_face:

Have you looked into something similar for frame::pallet macros as well?

Yes I have, likely something I’ll tackle in the future, don’t have a timeline I can share at the moment though :slightly_smiling_face:
Will be sure to ping you when I get to it though!

1 Like