43 releases

0.9.4 May 3, 2024
0.9.2 Mar 18, 2024
0.8.16 Dec 24, 2023
0.8.11 Nov 2, 2023
0.3.0 Mar 19, 2023

#803 in Magic Beans

Used in ink-lsp-server


41K SLoC

icon ink! Analyzer

A library for semantic analysis of ink! smart contracts.

It implements utilities for performing semantic analysis of ink! smart contract code. It therefore implements the core functionality of ink! analyzer at a high level.

It currently implements an Analysis entry point that accepts a string representation (&str) of ink! smart contract code as input and defines associated methods that compute:

  • diagnostics - errors and warnings based on ink! semantic rules.
  • quickfixes - suggested edits/code actions for diagnostic errors and warnings.
  • completions - completion suggestions for ink! attribute macros, arguments and entities/items.
  • code/intent actions - contextual assists for:
    • adding relevant ink! attribute macros, arguments and entities/items
    • migrating ink! projects to newer versions of ink! (e.g. ink! 4.x to 5.0)
    • extracting ink! entities (e.g. ink! 5.0 events) into standalone packages
    • and more!
  • hover content - descriptive/informational text for ink! attribute macros and arguments.
  • inlay hints - inline type and format information for ink! attribute arguments values (e.g. u32 | _ | @ for ink! message selectors).
  • signature help - popup information for valid ink! attribute arguments for the current context/cursor position.


Run the following Cargo command in your project directory

cargo add ink-analyzer



Analyzing ink! smart contract code.

use ink_analyzer::{Analysis, TextSize, TextRange, Version};

fn do_analysis() {
    // Smart contract code.
    let code = r#"
        mod my_contract {

            pub struct MyContract {
                value: bool,

            // --snip--

    // Creates analysis snapshot.
    let analysis = Analysis::new(code, Version::V4);

    // Computes diagnostics.
    let diagnostics = analysis.diagnostics();

    // Sets the cursor position.
    let position = TextSize::from(9);

    // Computes completions.
    let completions = analysis.completions(position);

    // Sets the focus range.
    let range = TextRange::new(position, TextSize::from(25));

    // Computes code/intent actions.
    let actions = analysis.actions(range);

    // Gets hover content.
    let hover = analysis.hover(range);

    // Computes inlay hints.
    let inlay_hints = analysis.inlay_hints(None);

    // Computes signature help.
    let signature_help = analysis.signature_help(TextSize::from(71));

fn project_code_stubs() {
    // Generates ink! project code stubs/snippets.
    let project = ink_analyzer::new_project(String::from("hello_world"), Version::V5);



Or you can access documentation locally by running the following command from the project root

cargo doc -p ink-analyzer --open


You can run unit and integration tests for all the core functionality by running the following command from the project root

cargo test -p ink-analyzer


Licensed under either MIT or Apache-2.0 license at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~225K SLoC