use std::path::PathBuf;
use vvv_core::{Address, Edit, Position, ReachKind, SourceText, Surgery, Symbol};
use crate::{Notice, NoticeKind};
pub(crate) struct Widen<'a> {
pub symbol: &'a Symbol,
pub source: &'a SourceText,
pub needs: ReachKind,
pub consumer: Address,
pub notice_at: (PathBuf, Position),
}
impl Widen<'_> {
pub fn plan(&self, surgery: &dyn Surgery) -> Result<Edit, Notice> {
match surgery.widen(self.symbol, self.source, self.needs) {
Some(edit) if self.needs != ReachKind::Everyone => Ok(edit),
_ => Err(Notice {
path: self.notice_at.0.clone().into(),
start: self.notice_at.1,
kind: NoticeKind::Unreachable {
item: self.symbol.name.clone(),
from: self.consumer.clone(),
needs: self.needs,
},
}),
}
}
}