6
6
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
7
7
//! actual IO is done and lowered to input.
8
8
9
+ use std:: error:: Error ;
9
10
use std:: hash:: BuildHasherDefault ;
10
11
use std:: { fmt, mem, ops} ;
11
12
@@ -22,7 +23,49 @@ use vfs::{AbsPathBuf, AnchoredPath, FileId, VfsPath, file_set::FileSet};
22
23
23
24
use crate :: { CrateWorkspaceData , EditionedFileId , FxIndexSet , RootQueryDb } ;
24
25
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
+ }
26
69
27
70
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
28
71
pub struct SourceRootId ( pub u32 ) ;
0 commit comments