A library for semantic analysis of ink! smart contract code.
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:
NOTE: 🚧 This project is still work in progress, check back over the next few weeks for regular updates.
Run the following Cargo command in your project directory
shell
cargo add ink-analyzer
Analyzing ink! smart contract code.
```rust use ink_analyzer::{Analysis, TextSize, TextRange};
fn doanalysis() { // Smart contract code. let code = r#" #[ink::contract] mod mycontract {
#[ink(storage)]
pub struct MyContract {
value: bool,
}
// --snip--
}
"#;
// Creates analysis snapshot.
let analysis = Analysis::new(code);
// Computes diagnostics.
let diagnostics = analysis.diagnostics();
dbg!(&diagnostics);
// Sets the cursor position.
let position = TextSize::from(9);
// Computes completions.
let completions = analysis.completions(position);
dbg!(&completions);
// Computes code/intent actions.
let actions = analysis.actions(position);
dbg!(&actions);
// Sets the focus range.
let range = TextRange::new(position, TextSize::from(25));
// Gets hover content.
let hover = analysis.hover(range);
dbg!(&hover);
} ```
https://docs.rs/ink-analyzer/latest/ink_analyzer/
Or you can access documentation locally by running the following command from the project root
shell
cargo doc -p ink-analyzer-ir --open
You can run unit and integration tests for all the core functionality by running the following command from the project root
shell
cargo test -p ink-analyzer-ir
Implementations of the unit tests (and hence a good overview of the current functionality) can be found in the diagnostics submodule of the ink-analyzer crate.
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.