Skip to content

Commit 08ea0e0

Browse files
committed
Make ConfigData Ser and TOML De
In order to achieve this, I had to virtually rewrite ConfigData's default values to their typed versions. It ended up looking not so well. I will think of something to fix this. In addition to this, some default value have been hastily modified but config manual generation will be a stay as a reminder to fix this.
1 parent 7ef7f44 commit 08ea0e0

File tree

15 files changed

+1178
-744
lines changed

15 files changed

+1178
-744
lines changed

Cargo.lock

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base-db/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ salsa.workspace = true
1919
rustc-hash.workspace = true
2020
triomphe.workspace = true
2121
semver.workspace = true
22+
serde.workspace = true
2223
tracing.workspace = true
2324

2425
# local deps

crates/base-db/src/change.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ 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.len());
27+
d.field("files_changed", &self.files_changed);
28+
// d.field("files_changed", &self.files_changed.len());
2829
}
2930
if self.crate_graph.is_some() {
3031
d.field("crate_graph", &self.crate_graph);

crates/base-db/src/input.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::{fmt, mem, ops};
1111
use cfg::CfgOptions;
1212
use la_arena::{Arena, Idx, RawIdx};
1313
use rustc_hash::{FxHashMap, FxHashSet};
14+
use serde::Serialize;
1415
use span::Edition;
1516
use syntax::SmolStr;
1617
use triomphe::Arc;
@@ -19,33 +20,41 @@ use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
1920
// Map from crate id to the name of the crate and path of the proc-macro. If the value is `None`,
2021
// then the crate for the proc-macro hasn't been build yet as the build data is missing.
2122
pub type ProcMacroPaths = FxHashMap<CrateId, Result<(Option<String>, AbsPathBuf), String>>;
23+
24+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
25+
pub struct SourceRootId(pub u32);
26+
2227
/// Files are grouped into source roots. A source root is a directory on the
2328
/// file systems which is watched for changes. Typically it corresponds to a
2429
/// Rust crate. Source roots *might* be nested: in this case, a file belongs to
2530
/// the nearest enclosing source root. Paths to files are always relative to a
2631
/// source root, and the analyzer does not know the root path of the source root at
2732
/// all. So, a file from one source root can't refer to a file in another source
2833
/// root by path.
29-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
30-
pub struct SourceRootId(pub u32);
31-
3234
#[derive(Clone, Debug, PartialEq, Eq)]
3335
pub struct SourceRoot {
3436
/// Sysroot or crates.io library.
3537
///
3638
/// Libraries are considered mostly immutable, this assumption is used to
3739
/// optimize salsa's query structure
3840
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>,
3947
file_set: FileSet,
4048
}
4149

4250
impl SourceRoot {
4351
pub fn new_local(file_set: FileSet) -> SourceRoot {
44-
SourceRoot { is_library: false, file_set }
52+
eprintln!("{:#?}", file_set);
53+
SourceRoot { is_library: false, file_set, cargo_file_id: None, ratoml_file_id: None }
4554
}
4655

4756
pub fn new_library(file_set: FileSet) -> SourceRoot {
48-
SourceRoot { is_library: true, file_set }
57+
SourceRoot { is_library: true, file_set, cargo_file_id: None, ratoml_file_id: None }
4958
}
5059

5160
pub fn path_for_file(&self, file: &FileId) -> Option<&VfsPath> {
@@ -63,6 +72,16 @@ impl SourceRoot {
6372
pub fn iter(&self) -> impl Iterator<Item = FileId> + '_ {
6473
self.file_set.iter()
6574
}
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+
}
6685
}
6786

6887
/// `CrateGraph` is a bit of information which turns a set of text files into a
@@ -101,6 +120,15 @@ pub type CrateId = Idx<CrateData>;
101120
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
102121
pub struct CrateName(SmolStr);
103122

123+
impl Serialize for CrateName {
124+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
125+
where
126+
S: serde::Serializer,
127+
{
128+
serializer.serialize_str(self)
129+
}
130+
}
131+
104132
impl CrateName {
105133
/// Creates a crate name, checking for dashes in the string provided.
106134
/// Dashes are not allowed in the crate names,

crates/project-model/src/cfg_flag.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use std::{fmt, str::FromStr};
55

66
use cfg::CfgOptions;
7+
use serde::Serialize;
78

8-
#[derive(Clone, Eq, PartialEq, Debug)]
9+
#[derive(Clone, Eq, PartialEq, Debug, Serialize)]
910
pub enum CfgFlag {
1011
Atom(String),
1112
KeyValue { key: String, value: String },

crates/project-model/src/project_json.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use base_db::{CrateDisplayName, CrateId, CrateName, Dependency};
5353
use la_arena::RawIdx;
5454
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
5555
use rustc_hash::FxHashMap;
56-
use serde::{de, Deserialize};
56+
use serde::{de, Deserialize, Serialize};
5757
use span::Edition;
5858

5959
use crate::cfg_flag::CfgFlag;
@@ -174,14 +174,14 @@ impl ProjectJson {
174174
}
175175
}
176176

177-
#[derive(Deserialize, Debug, Clone)]
177+
#[derive(Serialize, Deserialize, Debug, Clone)]
178178
pub struct ProjectJsonData {
179179
sysroot: Option<Utf8PathBuf>,
180180
sysroot_src: Option<Utf8PathBuf>,
181181
crates: Vec<CrateData>,
182182
}
183183

184-
#[derive(Deserialize, Debug, Clone)]
184+
#[derive(Serialize, Deserialize, Debug, Clone)]
185185
struct CrateData {
186186
display_name: Option<String>,
187187
root_module: Utf8PathBuf,
@@ -203,7 +203,7 @@ struct CrateData {
203203
repository: Option<String>,
204204
}
205205

206-
#[derive(Deserialize, Debug, Clone)]
206+
#[derive(Serialize, Deserialize, Debug, Clone)]
207207
#[serde(rename = "edition")]
208208
enum EditionData {
209209
#[serde(rename = "2015")]
@@ -227,7 +227,7 @@ impl From<EditionData> for Edition {
227227
}
228228
}
229229

230-
#[derive(Deserialize, Debug, Clone)]
230+
#[derive(Serialize, Deserialize, Debug, Clone)]
231231
struct DepData {
232232
/// Identifies a crate by position in the crates array.
233233
#[serde(rename = "crate")]
@@ -236,7 +236,7 @@ struct DepData {
236236
name: CrateName,
237237
}
238238

239-
#[derive(Deserialize, Debug, Clone)]
239+
#[derive(Serialize, Deserialize, Debug, Clone)]
240240
struct CrateSource {
241241
include_dirs: Vec<Utf8PathBuf>,
242242
exclude_dirs: Vec<Utf8PathBuf>,

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ tracing.workspace = true
3939
tracing-subscriber.workspace = true
4040
tracing-tree.workspace = true
4141
triomphe.workspace = true
42+
toml = "0.8.8"
4243
nohash-hasher.workspace = true
4344
always-assert = "0.2.0"
4445
walkdir = "2.3.2"

0 commit comments

Comments
 (0)