66//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
77//! actual IO is done and lowered to input.
88
9+ use std:: error:: Error ;
910use std:: hash:: BuildHasherDefault ;
1011use std:: { fmt, mem, ops} ;
1112
@@ -22,7 +23,49 @@ use vfs::{AbsPathBuf, AnchoredPath, FileId, VfsPath, file_set::FileSet};
2223
2324use crate :: { CrateWorkspaceData , EditionedFileId , FxIndexSet , RootQueryDb } ;
2425
25- pub type ProcMacroPaths = FxHashMap < CrateBuilderId , Result < ( String , AbsPathBuf ) , String > > ;
26+ pub type ProcMacroPaths =
27+ FxHashMap < CrateBuilderId , Result < ( String , AbsPathBuf ) , ProcMacroLoadingError > > ;
28+
29+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
30+ pub enum ProcMacroLoadingError {
31+ Disabled ,
32+ FailedToBuild ,
33+ MissingDylibPath ,
34+ NotYetBuilt ,
35+ NoProcMacros ,
36+ ProcMacroSrvError ( Box < str > ) ,
37+ }
38+ impl ProcMacroLoadingError {
39+ pub fn is_hard_error ( & self ) -> bool {
40+ match self {
41+ ProcMacroLoadingError :: Disabled | ProcMacroLoadingError :: NotYetBuilt => false ,
42+ ProcMacroLoadingError :: FailedToBuild
43+ | ProcMacroLoadingError :: MissingDylibPath
44+ | ProcMacroLoadingError :: NoProcMacros
45+ | ProcMacroLoadingError :: ProcMacroSrvError ( _) => true ,
46+ }
47+ }
48+ }
49+
50+ impl Error for ProcMacroLoadingError { }
51+ impl fmt:: Display for ProcMacroLoadingError {
52+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
53+ match self {
54+ ProcMacroLoadingError :: Disabled => write ! ( f, "proc-macro expansion is disabled" ) ,
55+ ProcMacroLoadingError :: FailedToBuild => write ! ( f, "proc-macro failed to build" ) ,
56+ ProcMacroLoadingError :: MissingDylibPath => {
57+ write ! ( f, "proc-macro crate build data is missing a dylib path" )
58+ }
59+ ProcMacroLoadingError :: NotYetBuilt => write ! ( f, "proc-macro not yet built" ) ,
60+ ProcMacroLoadingError :: NoProcMacros => {
61+ write ! ( f, "proc macro library has no proc macros" )
62+ }
63+ ProcMacroLoadingError :: ProcMacroSrvError ( msg) => {
64+ write ! ( f, "proc macro server error: {msg}" )
65+ }
66+ }
67+ }
68+ }
2669
2770#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
2871pub struct SourceRootId ( pub u32 ) ;
0 commit comments