1use std::fmt;
2use std::io;
3use syn::Error as SynError;
4use ra_ap_ide_assists::Assist;
5
6#[derive(Debug)]
7pub enum ExtractionError {
8 Io(io::Error),
9 Parse(SynError),
10 InvalidManifest,
11 InvalidStartIdx,
12 InvalidEndIdx,
13 SameIdx,
14 InvalidIdxPair,
15 NoExtractFunction(Vec<Assist>),
16 CommentNotApplicable,
17 BracesNotApplicable,
18 ParentMethodNotFound,
19}
20
21impl fmt::Display for ExtractionError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 ExtractionError::Io(e) => write!(f, "I/O error: {}", e),
25 ExtractionError::Parse(e) => write!(f, "Parse error: {}", e),
26 ExtractionError::InvalidManifest => write!(f, "Could not find a manifest file for the given path"),
27 ExtractionError::InvalidStartIdx => write!(f, "Invalid start index"),
28 ExtractionError::InvalidEndIdx => write!(f, "Invalid end index"),
29 ExtractionError::SameIdx => write!(f, "Start and end indices are the same"),
30 ExtractionError::InvalidIdxPair => write!(f, "Invalid pair of start and end indices"),
31 ExtractionError::NoExtractFunction(assists) => write!(f, "No Extract Function Assist found for the given selection of assists {:?}", assists),
32 ExtractionError::CommentNotApplicable => write!(f, "Extraction not applicable for comment"),
33 ExtractionError::BracesNotApplicable => write!(f, "Extraction not applicable for braces"),
34 ExtractionError::ParentMethodNotFound => write!(f, "Parent method not found"),
35 }
36 }
37}
38
39impl From<io::Error> for ExtractionError {
40 fn from(error: io::Error) -> Self {
41 ExtractionError::Io(error)
42 }
43}
44
45impl From<SynError> for ExtractionError {
46 fn from(error: SynError) -> Self {
47 ExtractionError::Parse(error)
48 }
49}