vim_plugin_metadata/
lib.rs1mod data;
2mod parser;
3
4pub use crate::data::{VimNode, VimPlugin, VimPluginSection};
5pub use crate::parser::VimParser;
6
7use core::fmt;
8use std::{error, io};
9
10#[derive(Debug)]
11pub enum Error {
12 UnknownError(Box<dyn error::Error>),
13 GrammarError(tree_sitter::LanguageError),
14 ParsingFailure,
15 IOError(io::Error),
16}
17
18impl From<tree_sitter::LanguageError> for Error {
19 fn from(e: tree_sitter::LanguageError) -> Self {
20 Self::GrammarError(e)
21 }
22}
23
24impl From<walkdir::Error> for Error {
25 fn from(err: walkdir::Error) -> Self {
26 if err.io_error().is_some() {
27 err.into_io_error().unwrap().into()
28 } else {
29 Self::UnknownError(err.into())
30 }
31 }
32}
33
34impl From<io::Error> for Error {
35 fn from(err: io::Error) -> Self {
36 Self::IOError(err)
37 }
38}
39
40impl fmt::Display for Error {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 match self {
43 Self::UnknownError(err) => write!(f, "Unknown error: {err}"),
44 Self::GrammarError(err) => write!(f, "Error loading grammar: {err}"),
45 Self::ParsingFailure => {
46 write!(f, "General failure from tree-sitter while parsing syntax")
47 }
48 Self::IOError(err) => write!(f, "I/O error: {err}"),
49 }
50 }
51}
52
53impl error::Error for Error {}
54
55type Result<T> = core::result::Result<T, Error>;