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.
- Semantic Analyzer (source code, crates.io, docs.rs).
- Language Server (source code, binary/executable releases, crates.io, docs.rs).
- Visual Studio Code Extension (source code, VS Code Marketplace listing, VSIX releases).
Problem
While ink! developers can leverage Rust tooling and excellent IDE/code editor support via rust-analyzer and IntelliJ Rust because "ink! is just standard Rust in a well-defined "contract format" with specialized #[ink(…)]
attribute macros",
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)]
) because macro expansion/name resolution and trait resolution are hard problems for generic IDE/code editor tools (see also https://rust-analyzer.github.io/blog/2021/11/21/ides-and-macros.html). - 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! built on a resilient and lossless parser.
- 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.
ink! analyzer 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 most of the major platforms/architectures,
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
To learn more about ink! analyzer, read the introductory blog post and/or check out the ink! analyzer organization on GitHub for source code, technical documentation, installation and usage instructions, and links to useful resources.
Issues, bug reports, PRs and feature requests are welcome at the respective GitHub repositories 🙂.