ink_analyzer/lib.rs
1//! # ink! analyzer
2//! A library for semantic analysis of [ink!] smart contracts.
3//!
4//! [ink!]: https://use.ink/
5//!
6//! # Example
7//! Analyzing ink! smart contract code.
8//!
9//! ```
10//! use ink_analyzer::{Analysis, TextSize, TextRange, Version};
11//!
12//! fn do_analysis() {
13//! // Smart contract code.
14//! let code = r#"
15//! #[ink::contract]
16//! mod my_contract {
17//!
18//! #[ink(storage)]
19//! pub struct MyContract {
20//! value: bool,
21//! }
22//!
23//! // --snip--
24//! }
25//! "#;
26//!
27//! // Creates analysis snapshot.
28//! let analysis = Analysis::new(code, Version::V6);
29//!
30//! // Computes diagnostics.
31//! let diagnostics = analysis.diagnostics();
32//! dbg!(&diagnostics);
33//!
34//! // Sets the cursor position.
35//! let position = TextSize::from(9);
36//!
37//! // Computes completions.
38//! let completions = analysis.completions(position);
39//! dbg!(&completions);
40//!
41//! // Sets the focus range.
42//! let range = TextRange::new(position, TextSize::from(25));
43//!
44//! // Computes code/intent actions.
45//! let actions = analysis.actions(range);
46//! dbg!(&actions);
47//!
48//! // Gets hover content.
49//! let hover = analysis.hover(range);
50//! dbg!(&hover);
51//!
52//! // Computes inlay hints.
53//! let inlay_hints = analysis.inlay_hints(None);
54//! dbg!(&inlay_hints);
55//!
56//! // Computes signature help.
57//! let signature_help = analysis.signature_help(TextSize::from(71));
58//! dbg!(&signature_help);
59//! }
60//!
61//! fn project_code_stubs() {
62//! // Generates ink! project code stubs/snippets.
63//! let project = ink_analyzer::new_project(String::from("hello_world"), Version::V6);
64//! dbg!(&project);
65//! }
66//! ```
67
68#[macro_use]
69mod test_utils;
70
71mod analysis;
72mod codegen;
73mod resolution;
74mod utils;
75
76pub use self::{
77 analysis::{
78 Action, ActionKind, Analysis, Completion, CompletionKind, Diagnostic, Hover, InlayHint,
79 Severity, SignatureHelp, TextEdit,
80 },
81 codegen::{new_project, Error, Project, ProjectFile},
82};
83pub use ink_analyzer_ir::{
84 syntax::{TextRange, TextSize},
85 MinorVersion, Version,
86};