1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
//! Types and abstractions for performing semantic analysis of ink! smart contract code.
use ink_analyzer_ir::syntax::{TextRange, TextSize};
use ink_analyzer_ir::InkFile;
pub use actions::Action;
pub use completions::Completion;
pub use diagnostics::{Diagnostic, Severity};
pub use hover::Hover;
mod actions;
mod completions;
mod diagnostics;
mod hover;
mod utils;
/// Entry point for asking for semantic information about ink! smart contract code.
#[derive(Debug)]
pub struct Analysis {
/// The ink! smart contract code being analyzed.
file: InkFile,
}
impl Analysis {
/// Creates an analysis instance from smart contract code.
pub fn new(code: &str) -> Self {
Self {
file: InkFile::parse(code),
}
}
/// Returns the intermediate representation (IR) of the smart contract code.
pub fn file(&self) -> &InkFile {
&self.file
}
/// Runs diagnostics for the smart contract code.
pub fn diagnostics(&self) -> Vec<Diagnostic> {
diagnostics::diagnostics(&self.file)
}
/// Computes ink! attribute completions at the given position.
pub fn completions(&self, position: TextSize) -> Vec<Completion> {
completions::completions(&self.file, position)
}
/// Computes ink! attribute code/intent actions for the given position.
pub fn actions(&self, position: TextSize) -> Vec<Action> {
actions::actions(&self.file, position)
}
/// Returns descriptive/informational text for the ink! attribute at the given position (if any).
pub fn hover(&self, range: TextRange) -> Option<Hover> {
hover::hover(&self.file, range)
}
}