Skip to content

Commit 9208256

Browse files
committed
Infra changes for config.rs
This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( #13529 ) issue. This means, that 1. We no longer have a single config base. The once single `ConfigData` has been divided into 4 : A tree of `.ratoml` files, a set of configs coming from the client ( this is what was called before the `CrateData` except that now values do not default to anything when they are not defined) , a set of configs that will reflect what the contents of a `ratoml` file defined in user's config directory ( e.g `~/.config/rust-analyzer/.rust-analyzer.toml` and finally a tree root that is populated by default values only. 2. Configs have also been divided into 3 different blocks : `global` , `local` , `client`. The current status of a config may change until #13529 got merged.
1 parent 434f099 commit 9208256

File tree

12 files changed

+565
-671
lines changed

12 files changed

+565
-671
lines changed

crates/base-db/src/change.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ impl fmt::Debug for FileChange {
2424
d.field("roots", roots);
2525
}
2626
if !self.files_changed.is_empty() {
27-
d.field("files_changed", &self.files_changed);
28-
// d.field("files_changed", &self.files_changed.len());
27+
d.field("files_changed", &self.files_changed.len());
2928
}
3029
if self.crate_graph.is_some() {
3130
d.field("crate_graph", &self.crate_graph);

crates/base-db/src/input.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,16 @@ pub struct SourceRoot {
3737
/// Libraries are considered mostly immutable, this assumption is used to
3838
/// optimize salsa's query structure
3939
pub is_library: bool,
40-
cargo_file_id: Option<FileId>,
41-
/// FIXME : @alibektas We know that this is wrong.
42-
/// base-db must stay as a level of abstraction
43-
/// that has no knowledge of such specific files
44-
/// so this should be moved somewhere else.
45-
ratoml_file_id: Option<FileId>,
4640
file_set: FileSet,
4741
}
4842

4943
impl SourceRoot {
5044
pub fn new_local(file_set: FileSet) -> SourceRoot {
51-
eprintln!("{:#?}", file_set);
52-
SourceRoot { is_library: false, file_set, cargo_file_id: None, ratoml_file_id: None }
45+
SourceRoot { is_library: false, file_set }
5346
}
5447

5548
pub fn new_library(file_set: FileSet) -> SourceRoot {
56-
SourceRoot { is_library: true, file_set, cargo_file_id: None, ratoml_file_id: None }
49+
SourceRoot { is_library: true, file_set }
5750
}
5851

5952
pub fn path_for_file(&self, file: &FileId) -> Option<&VfsPath> {
@@ -71,16 +64,6 @@ impl SourceRoot {
7164
pub fn iter(&self) -> impl Iterator<Item = FileId> + '_ {
7265
self.file_set.iter()
7366
}
74-
75-
/// Get `FileId` of the `Cargo.toml` if one present in `SourceRoot`
76-
pub fn cargo_toml(&self) -> Option<FileId> {
77-
self.cargo_file_id
78-
}
79-
80-
/// Get `FileId` of the `rust-analyzer.toml` if one present in `SourceRoot`
81-
pub fn ratoml(&self) -> Option<FileId> {
82-
self.ratoml_file_id
83-
}
8467
}
8568

8669
/// `CrateGraph` is a bit of information which turns a set of text files into a

crates/ide/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use hir::Change;
6666
use ide_db::{
6767
base_db::{
6868
salsa::{self, ParallelDatabase},
69-
CrateOrigin, Env, FileLoader, FileSet, SourceDatabase, VfsPath,
69+
CrateOrigin, Env, FileLoader, FileSet, SourceDatabase, SourceDatabaseExt, VfsPath,
7070
},
7171
symbol_index, FxHashMap, FxIndexSet, LineIndexDatabase,
7272
};
@@ -267,6 +267,10 @@ impl Analysis {
267267
self.with_db(|db| status::status(db, file_id))
268268
}
269269

270+
pub fn source_root(&self, file_id: FileId) -> Cancellable<SourceRootId> {
271+
self.with_db(|db| db.file_source_root(file_id))
272+
}
273+
270274
pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
271275
where
272276
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,
@@ -276,7 +280,7 @@ impl Analysis {
276280

277281
/// Gets the text of the source file.
278282
pub fn file_text(&self, file_id: FileId) -> Cancellable<Arc<str>> {
279-
self.with_db(|db| db.file_text(file_id))
283+
self.with_db(|db| SourceDatabaseExt::file_text(db, file_id))
280284
}
281285

282286
/// Gets the syntax tree of the file.
@@ -286,7 +290,6 @@ impl Analysis {
286290

287291
/// Returns true if this file belongs to an immutable library.
288292
pub fn is_library_file(&self, file_id: FileId) -> Cancellable<bool> {
289-
use ide_db::base_db::SourceDatabaseExt;
290293
self.with_db(|db| db.source_root(db.file_source_root(file_id)).is_library)
291294
}
292295

0 commit comments

Comments
 (0)