mod actions;
mod completions;
mod diagnostics;
mod hover;
mod inlay_hints;
mod signature_help;
mod text_edit;
mod utils;
use crate::Version;
use ink_analyzer_ir::syntax::{TextRange, TextSize};
use ink_analyzer_ir::InkFile;
use itertools::Itertools;
pub use actions::{Action, ActionKind};
pub use completions::Completion;
pub use diagnostics::{Diagnostic, Severity};
pub use hover::Hover;
pub use inlay_hints::InlayHint;
pub use signature_help::SignatureHelp;
pub use text_edit::TextEdit;
#[derive(Debug)]
pub struct Analysis {
file: InkFile,
version: Version,
}
impl Analysis {
pub fn new(code: &str, version: Version) -> Self {
Self {
file: InkFile::parse(code),
version,
}
}
pub fn file(&self) -> &InkFile {
&self.file
}
pub fn diagnostics(&self) -> Vec<Diagnostic> {
diagnostics::diagnostics(&self.file, self.version)
}
pub fn completions(&self, position: TextSize) -> Vec<Completion> {
completions::completions(&self.file, position, self.version)
}
pub fn actions(&self, range: TextRange) -> Vec<Action> {
diagnostics::diagnostics(&self.file, self.version)
.into_iter()
.filter_map(|it| it.quickfixes)
.flatten()
.filter(|action| {
range.contains_range(action.range) || action.range.contains_range(range)
})
.chain(actions::actions(&self.file, range, self.version))
.unique_by(|item| item.edits.clone())
.collect()
}
pub fn hover(&self, range: TextRange) -> Option<Hover> {
hover::hover(&self.file, range, self.version)
}
pub fn inlay_hints(&self, range: Option<TextRange>) -> Vec<InlayHint> {
inlay_hints::inlay_hints(&self.file, range, self.version)
}
pub fn signature_help(&self, position: TextSize) -> Vec<SignatureHelp> {
signature_help::signature_help(&self.file, position, self.version)
}
}