1
1
pub mod db;
2
2
pub mod diagnostics;
3
3
pub mod files;
4
+ mod resolution_handlers;
4
5
use camino:: Utf8PathBuf ;
5
6
use common:: {
6
7
ingot:: { builtin_core, IngotBuilder } ,
@@ -10,127 +11,148 @@ pub use db::DriverDataBase;
10
11
11
12
use clap:: { Parser , Subcommand } ;
12
13
use hir:: hir_def:: TopLevelMod ;
13
- use resolver:: {
14
- ingot:: { config:: Config , source_files:: SourceFiles , Ingot , IngotResolver } ,
15
- Resolver ,
16
- } ;
14
+ use resolution_handlers:: { IngotFilesHandler , IngotGraphHandler } ;
15
+ use resolver:: { files:: FilesResolver , graph:: GraphResolverImpl , Resolver } ;
16
+
17
+ // pub fn run(opts: &Options) {
18
+ // match &opts.command {
19
+ // Command::Build => eprintln!("`fe build` doesn't work at the moment"),
20
+ // Command::Check { path, core } => {
21
+ // let db = DriverDataBase::default();
22
+ // let mut ingot_resolver = IngotResolver::default();
23
+ //
24
+ // let core_ingot = if let Some(core_path) = core {
25
+ // match ingot_resolver.resolve(core_path) {
26
+ // Ok(Ingot::Folder {
27
+ // config:
28
+ // Some(Config {
29
+ // version: Some(version),
30
+ // ..
31
+ // }),
32
+ // source_files:
33
+ // Some(SourceFiles {
34
+ // root: Some(root),
35
+ // files,
36
+ // }),
37
+ // }) => {
38
+ // let diagnostics = ingot_resolver.take_diagnostics();
39
+ // if !diagnostics.is_empty() {
40
+ // eprintln!("an error was encountered while resolving `{core_path}`");
41
+ // for diagnostic in diagnostics {
42
+ // eprintln!("{diagnostic}")
43
+ // }
44
+ // std::process::exit(2)
45
+ // }
46
+ // IngotBuilder::new(&db, "core")
47
+ // .kind(IngotKind::Core)
48
+ // .version(version)
49
+ // .entrypoint(root)
50
+ // .files_from_contents(files)
51
+ // .build()
52
+ // .0
53
+ // }
54
+ // Ok(Ingot::SingleFile { .. }) => {
55
+ // eprintln!("standalone core ingot not supported");
56
+ // std::process::exit(2)
57
+ // }
58
+ // Ok(_) => {
59
+ // eprintln!("an error was encountered while resolving `{core_path}`");
60
+ // for diagnostic in ingot_resolver.take_diagnostics() {
61
+ // eprintln!("{diagnostic}")
62
+ // }
63
+ // std::process::exit(2)
64
+ // }
65
+ // Err(error) => {
66
+ // eprintln!("an error was encountered while resolving `{core_path}`");
67
+ // eprintln!("{error}");
68
+ // std::process::exit(2)
69
+ // }
70
+ // }
71
+ // } else {
72
+ // builtin_core(&db)
73
+ // };
74
+ //
75
+ // let local_ingot = match ingot_resolver.resolve(path) {
76
+ // Ok(Ingot::Folder {
77
+ // config:
78
+ // Some(Config {
79
+ // version: Some(version),
80
+ // ..
81
+ // }),
82
+ // source_files:
83
+ // Some(SourceFiles {
84
+ // root: Some(root),
85
+ // files,
86
+ // }),
87
+ // }) => {
88
+ // let diagnostics = ingot_resolver.take_diagnostics();
89
+ // if !diagnostics.is_empty() {
90
+ // eprintln!("an error was encountered while resolving `{path}`");
91
+ // for diagnostic in diagnostics {
92
+ // eprintln!("{diagnostic}")
93
+ // }
94
+ // std::process::exit(2)
95
+ // }
96
+ // // db.local_ingot(path, &version, &root, files, core_ingot).0
97
+ // IngotBuilder::new(&db, path)
98
+ // .kind(IngotKind::Local)
99
+ // .version(version)
100
+ // .entrypoint(root)
101
+ // .files_from_contents(files)
102
+ // .build()
103
+ // .0
104
+ // }
105
+ // Ok(Ingot::SingleFile { path, content }) => {
106
+ // IngotBuilder::standalone(&db, path, content)
107
+ // .with_core_ingot(core_ingot)
108
+ // .build()
109
+ // .0
110
+ // }
111
+ // Ok(_) => {
112
+ // eprintln!("an error was encountered while resolving `{path}`");
113
+ // for diagnostic in ingot_resolver.take_diagnostics() {
114
+ // eprintln!("{diagnostic}")
115
+ // }
116
+ // std::process::exit(2)
117
+ // }
118
+ // Err(error) => {
119
+ // eprintln!("an error was encountered while resolving `{path}`");
120
+ // eprintln!("{error}");
121
+ // std::process::exit(2)
122
+ // }
123
+ // };
124
+ //
125
+ // let core_diags = db.run_on_ingot(core_ingot);
126
+ // let local_diags = db.run_on_ingot(local_ingot);
127
+ //
128
+ // if !core_diags.is_empty() || !local_diags.is_empty() {
129
+ // core_diags.emit(&db);
130
+ // local_diags.emit(&db);
131
+ // std::process::exit(1);
132
+ // }
133
+ // }
134
+ // Command::New => eprintln!("`fe new` doesn't work at the moment"),
135
+ // }
136
+ // }
17
137
18
138
pub fn run ( opts : & Options ) {
19
139
match & opts. command {
20
140
Command :: Build => eprintln ! ( "`fe build` doesn't work at the moment" ) ,
21
141
Command :: Check { path, core } => {
22
142
let db = DriverDataBase :: default ( ) ;
23
- let mut ingot_resolver = IngotResolver :: default ( ) ;
24
-
25
- let core_ingot = if let Some ( core_path) = core {
26
- match ingot_resolver. resolve ( core_path) {
27
- Ok ( Ingot :: Folder {
28
- config :
29
- Some ( Config {
30
- version : Some ( version) ,
31
- ..
32
- } ) ,
33
- source_files :
34
- Some ( SourceFiles {
35
- root : Some ( root) ,
36
- files,
37
- } ) ,
38
- } ) => {
39
- let diagnostics = ingot_resolver. take_diagnostics ( ) ;
40
- if !diagnostics. is_empty ( ) {
41
- eprintln ! ( "an error was encountered while resolving `{core_path}`" ) ;
42
- for diagnostic in diagnostics {
43
- eprintln ! ( "{diagnostic}" )
44
- }
45
- std:: process:: exit ( 2 )
46
- }
47
- IngotBuilder :: new ( & db, "core" )
48
- . kind ( IngotKind :: Core )
49
- . version ( version)
50
- . entrypoint ( root)
51
- . files_from_contents ( files)
52
- . build ( )
53
- . 0
54
- }
55
- Ok ( Ingot :: SingleFile { .. } ) => {
56
- eprintln ! ( "standalone core ingot not supported" ) ;
57
- std:: process:: exit ( 2 )
58
- }
59
- Ok ( _) => {
60
- eprintln ! ( "an error was encountered while resolving `{core_path}`" ) ;
61
- for diagnostic in ingot_resolver. take_diagnostics ( ) {
62
- eprintln ! ( "{diagnostic}" )
63
- }
64
- std:: process:: exit ( 2 )
65
- }
66
- Err ( error) => {
67
- eprintln ! ( "an error was encountered while resolving `{core_path}`" ) ;
68
- eprintln ! ( "{error}" ) ;
69
- std:: process:: exit ( 2 )
70
- }
71
- }
72
- } else {
73
- builtin_core ( & db)
74
- } ;
75
143
76
- let local_ingot = match ingot_resolver. resolve ( path) {
77
- Ok ( Ingot :: Folder {
78
- config :
79
- Some ( Config {
80
- version : Some ( version) ,
81
- ..
82
- } ) ,
83
- source_files :
84
- Some ( SourceFiles {
85
- root : Some ( root) ,
86
- files,
87
- } ) ,
88
- } ) => {
89
- let diagnostics = ingot_resolver. take_diagnostics ( ) ;
90
- if !diagnostics. is_empty ( ) {
91
- eprintln ! ( "an error was encountered while resolving `{path}`" ) ;
92
- for diagnostic in diagnostics {
93
- eprintln ! ( "{diagnostic}" )
94
- }
95
- std:: process:: exit ( 2 )
96
- }
97
- // db.local_ingot(path, &version, &root, files, core_ingot).0
98
- IngotBuilder :: new ( & db, path)
99
- . kind ( IngotKind :: Local )
100
- . version ( version)
101
- . entrypoint ( root)
102
- . files_from_contents ( files)
103
- . build ( )
104
- . 0
105
- }
106
- Ok ( Ingot :: SingleFile { path, content } ) => {
107
- IngotBuilder :: standalone ( & db, path, content)
108
- . with_core_ingot ( core_ingot)
109
- . build ( )
110
- . 0
111
- }
112
- Ok ( _) => {
113
- eprintln ! ( "an error was encountered while resolving `{path}`" ) ;
114
- for diagnostic in ingot_resolver. take_diagnostics ( ) {
115
- eprintln ! ( "{diagnostic}" )
116
- }
117
- std:: process:: exit ( 2 )
118
- }
119
- Err ( error) => {
120
- eprintln ! ( "an error was encountered while resolving `{path}`" ) ;
121
- eprintln ! ( "{error}" ) ;
122
- std:: process:: exit ( 2 )
123
- }
124
- } ;
144
+ // let mut files_resolver = FilesResolver::with_patterns(&["fe.toml", "src/**/*.fe"]);
145
+ let mut files_resolver = FilesResolver :: default ( ) ;
146
+ let mut files_handler = IngotFilesHandler :: default ( ) ;
147
+ let mut graph_resolver = GraphResolverImpl :: new ( files_resolver, files_handler) ;
148
+ let mut graph_handler = IngotGraphHandler :: default ( ) ;
125
149
126
- let core_diags = db. run_on_ingot ( core_ingot) ;
127
- let local_diags = db. run_on_ingot ( local_ingot) ;
150
+ graph_resolver. resolve ( & mut graph_handler, & path) ;
128
151
129
- if !core_diags. is_empty ( ) || !local_diags. is_empty ( ) {
130
- core_diags. emit ( & db) ;
131
- local_diags. emit ( & db) ;
132
- std:: process:: exit ( 1 ) ;
133
- }
152
+ // the above code could be encapsulated in an `IngotResolver`.
153
+ let ingot_resolver = IngotResolver :: < IngotFilesHandler , IngotGraphHandler > :: default ( ) ;
154
+ let ingot_handler = IngotHandler :: default ( ) ;
155
+ let local_ingot = ingot_resolver. resolve ( & mut ingot_handler, & path) ;
134
156
}
135
157
Command :: New => eprintln ! ( "`fe new` doesn't work at the moment" ) ,
136
158
}
0 commit comments