Skip to content

Commit a29fb57

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 657b33b commit a29fb57

File tree

15 files changed

+1159
-738
lines changed

15 files changed

+1159
-738
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
use base_db::{CrateDisplayName, CrateName};
5353
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
5454
use rustc_hash::FxHashMap;
55-
use serde::{de, Deserialize};
55+
use serde::{de, Deserialize, Serialize};
5656
use span::Edition;
5757

5858
use crate::cfg_flag::CfgFlag;
@@ -161,14 +161,14 @@ impl ProjectJson {
161161
}
162162
}
163163

164-
#[derive(Deserialize, Debug, Clone)]
164+
#[derive(Serialize, Deserialize, Debug, Clone)]
165165
pub struct ProjectJsonData {
166166
sysroot: Option<Utf8PathBuf>,
167167
sysroot_src: Option<Utf8PathBuf>,
168168
crates: Vec<CrateData>,
169169
}
170170

171-
#[derive(Deserialize, Debug, Clone)]
171+
#[derive(Serialize, Deserialize, Debug, Clone)]
172172
struct CrateData {
173173
display_name: Option<String>,
174174
root_module: Utf8PathBuf,
@@ -190,7 +190,7 @@ struct CrateData {
190190
repository: Option<String>,
191191
}
192192

193-
#[derive(Deserialize, Debug, Clone)]
193+
#[derive(Serialize, Deserialize, Debug, Clone)]
194194
#[serde(rename = "edition")]
195195
enum EditionData {
196196
#[serde(rename = "2015")]
@@ -231,7 +231,7 @@ pub(crate) struct Dep {
231231
pub(crate) name: CrateName,
232232
}
233233

234-
#[derive(Deserialize, Debug, Clone)]
234+
#[derive(Serialize, Deserialize, Debug, Clone)]
235235
struct CrateSource {
236236
include_dirs: Vec<Utf8PathBuf>,
237237
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)