Skip to content

Commit 6db7040

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 aad1ef2 commit 6db7040

File tree

12 files changed

+566
-673
lines changed

12 files changed

+566
-673
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
@@ -38,23 +38,16 @@ pub struct SourceRoot {
3838
/// Libraries are considered mostly immutable, this assumption is used to
3939
/// optimize salsa's query structure
4040
pub is_library: bool,
41-
cargo_file_id: Option<FileId>,
42-
/// FIXME : @alibektas We know that this is wrong.
43-
/// base-db must stay as a level of abstraction
44-
/// that has no knowledge of such specific files
45-
/// so this should be moved somewhere else.
46-
ratoml_file_id: Option<FileId>,
4741
file_set: FileSet,
4842
}
4943

5044
impl SourceRoot {
5145
pub fn new_local(file_set: FileSet) -> SourceRoot {
52-
eprintln!("{:#?}", file_set);
53-
SourceRoot { is_library: false, file_set, cargo_file_id: None, ratoml_file_id: None }
46+
SourceRoot { is_library: false, file_set }
5447
}
5548

5649
pub fn new_library(file_set: FileSet) -> SourceRoot {
57-
SourceRoot { is_library: true, file_set, cargo_file_id: None, ratoml_file_id: None }
50+
SourceRoot { is_library: true, file_set }
5851
}
5952

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

8770
/// `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)