Skip to content

Commit

Permalink
Infra changes for config.rs
Browse files Browse the repository at this point in the history
This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( rust-lang#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 rust-lang#13529 got merged.
  • Loading branch information
alibektas committed Mar 12, 2024
1 parent e26bef6 commit 8cc1bee
Show file tree
Hide file tree
Showing 12 changed files with 565 additions and 669 deletions.
3 changes: 1 addition & 2 deletions crates/base-db/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ impl fmt::Debug for FileChange {
d.field("roots", roots);
}
if !self.files_changed.is_empty() {
d.field("files_changed", &self.files_changed);
// d.field("files_changed", &self.files_changed.len());
d.field("files_changed", &self.files_changed.len());
}
if self.crate_graph.is_some() {
d.field("crate_graph", &self.crate_graph);
Expand Down
21 changes: 2 additions & 19 deletions crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,16 @@ pub struct SourceRoot {
/// Libraries are considered mostly immutable, this assumption is used to
/// optimize salsa's query structure
pub is_library: bool,
cargo_file_id: Option<FileId>,
/// FIXME : @alibektas We know that this is wrong.
/// base-db must stay as a level of abstraction
/// that has no knowledge of such specific files
/// so this should be moved somewhere else.
ratoml_file_id: Option<FileId>,
file_set: FileSet,
}

impl SourceRoot {
pub fn new_local(file_set: FileSet) -> SourceRoot {
eprintln!("{:#?}", file_set);
SourceRoot { is_library: false, file_set, cargo_file_id: None, ratoml_file_id: None }
SourceRoot { is_library: false, file_set }
}

pub fn new_library(file_set: FileSet) -> SourceRoot {
SourceRoot { is_library: true, file_set, cargo_file_id: None, ratoml_file_id: None }
SourceRoot { is_library: true, file_set }
}

pub fn path_for_file(&self, file: &FileId) -> Option<&VfsPath> {
Expand All @@ -71,16 +64,6 @@ impl SourceRoot {
pub fn iter(&self) -> impl Iterator<Item = FileId> + '_ {
self.file_set.iter()
}

/// Get `FileId` of the `Cargo.toml` if one present in `SourceRoot`
pub fn cargo_toml(&self) -> Option<FileId> {
self.cargo_file_id
}

/// Get `FileId` of the `rust-analyzer.toml` if one present in `SourceRoot`
pub fn ratoml(&self) -> Option<FileId> {
self.ratoml_file_id
}
}

/// `CrateGraph` is a bit of information which turns a set of text files into a
Expand Down
9 changes: 6 additions & 3 deletions crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use hir::ChangeWithProcMacros;
use ide_db::{
base_db::{
salsa::{self, ParallelDatabase},
CrateOrigin, Env, FileLoader, FileSet, SourceDatabase, VfsPath,
CrateOrigin, Env, FileLoader, FileSet, SourceDatabase, SourceDatabaseExt, VfsPath,
},
prime_caches, symbol_index, FxHashMap, FxIndexSet, LineIndexDatabase,
};
Expand Down Expand Up @@ -272,6 +272,10 @@ impl Analysis {
self.with_db(|db| status::status(db, file_id))
}

pub fn source_root(&self, file_id: FileId) -> Cancellable<SourceRootId> {
self.with_db(|db| db.file_source_root(file_id))
}

pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
where
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,
Expand All @@ -281,7 +285,7 @@ impl Analysis {

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

/// Gets the syntax tree of the file.
Expand All @@ -291,7 +295,6 @@ impl Analysis {

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

Expand Down

0 comments on commit 8cc1bee

Please sign in to comment.