@@ -15,7 +15,9 @@ use ruff_db::{Db as SourceDb, Upcast};
15
15
mod changes;
16
16
17
17
#[ salsa:: db]
18
- pub trait Db : SemanticDb + Upcast < dyn SemanticDb > { }
18
+ pub trait Db : SemanticDb + Upcast < dyn SemanticDb > {
19
+ fn workspace ( & self ) -> Workspace ;
20
+ }
19
21
20
22
#[ salsa:: db]
21
23
pub struct RootDatabase {
@@ -38,39 +40,13 @@ impl RootDatabase {
38
40
} ;
39
41
40
42
// Initialize the `Program` singleton
41
-
42
- // TODO: Reasoning: We need to know the target version at this point to
43
- // load the correct persistent cache so that running knot with
44
- // different target versions doesn't result in 0 cache-reuse.
45
- // But this does complicate things a bit because we need to have the
46
- // resolved workspace settings at this point.
47
- // But resolving the settings fits well into the workspace's responsibility.
48
- // Should `Workspace` initialize the Program -> No, because we then need to create
49
- // the program first.
50
-
51
- // Metadata: Plain description of the workspace and the exact configuration (without doing any resolution)
52
- // Workspace: Resolved workspace with all members, merged settings.
53
- // Middle ground -> `metadata.resolve_settings(configuration)` returns the resolved
54
- // `.workspace` configuration but it doesn't resolve any of the members configuration.
55
- // The problem with this is that it makes the single project use case awkward. We should just
56
- // resolve the program settings and defer everything else to later? But how does this work with
57
- // with target versions that are inherited from the workspace?
58
- // So this is somewhat awkward too :(
59
- // The other option is that `WorkspaceMetadata` keeps working as it is today where it stores the
60
- // resolved settings instead of the unresolved. I do thik that this would require another intermediate representation
61
- // to not be awkward.
62
43
Program :: from_settings ( & db, workspace. settings ( ) . program ( ) ) ?;
63
44
64
45
db. workspace = Some ( Workspace :: from_metadata ( & db, workspace) ) ;
65
46
66
47
Ok ( db)
67
48
}
68
49
69
- pub fn workspace ( & self ) -> Workspace {
70
- // SAFETY: The workspace is always initialized in `new`.
71
- self . workspace . unwrap ( )
72
- }
73
-
74
50
/// Checks all open files in the workspace and its dependencies.
75
51
pub fn check ( & self ) -> Result < Vec < Box < dyn Diagnostic > > , Cancelled > {
76
52
self . with_db ( |db| db. workspace ( ) . check ( db) )
@@ -174,7 +150,11 @@ impl salsa::Database for RootDatabase {
174
150
}
175
151
176
152
#[ salsa:: db]
177
- impl Db for RootDatabase { }
153
+ impl Db for RootDatabase {
154
+ fn workspace ( & self ) -> Workspace {
155
+ self . workspace . unwrap ( )
156
+ }
157
+ }
178
158
179
159
#[ cfg( test) ]
180
160
pub ( crate ) mod tests {
@@ -189,6 +169,7 @@ pub(crate) mod tests {
189
169
use ruff_db:: { Db as SourceDb , Upcast } ;
190
170
191
171
use crate :: db:: Db ;
172
+ use crate :: workspace:: Workspace ;
192
173
193
174
#[ salsa:: db]
194
175
pub ( crate ) struct TestDb {
@@ -275,7 +256,11 @@ pub(crate) mod tests {
275
256
}
276
257
277
258
#[ salsa:: db]
278
- impl Db for TestDb { }
259
+ impl Db for TestDb {
260
+ fn workspace ( & self ) -> Workspace {
261
+ todo ! ( )
262
+ }
263
+ }
279
264
280
265
#[ salsa:: db]
281
266
impl salsa:: Database for TestDb {
0 commit comments