Skip to content

Commit 4196ad5

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 2bad5e7 commit 4196ad5

File tree

9 files changed

+446
-262
lines changed

9 files changed

+446
-262
lines changed

Cargo.lock

+59-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base-db/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ syntax.workspace = true
2727
test-utils.workspace = true
2828
tt.workspace = true
2929
vfs.workspace = true
30+
serde.workspace = true

crates/base-db/src/input.rs

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::{fmt, mem, ops, panic::RefUnwindSafe, str::FromStr, sync};
1111
use cfg::CfgOptions;
1212
use la_arena::{Arena, Idx};
1313
use rustc_hash::{FxHashMap, FxHashSet};
14+
use serde::Serialize;
1415
use syntax::SmolStr;
1516
use triomphe::Arc;
1617
use tt::token_id::Subtree;
@@ -39,6 +40,10 @@ pub struct SourceRoot {
3940
/// optimize salsa's query structure
4041
pub is_library: bool,
4142
cargo_file_id: Option<FileId>,
43+
/// FIXME : @alibektas We know that this is wrong.
44+
/// base-db must stay as a level of abstraction
45+
/// that has no knowledge of such specific files
46+
/// so this should be moved somewhere else.
4247
ratoml_file_id: Option<FileId>,
4348
file_set: FileSet,
4449
}
@@ -116,6 +121,15 @@ pub type CrateId = Idx<CrateData>;
116121
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
117122
pub struct CrateName(SmolStr);
118123

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

crates/project-model/src/cfg_flag.rs

+2-1
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, Edition};
5353
use la_arena::RawIdx;
5454
use paths::{AbsPath, AbsPathBuf};
5555
use rustc_hash::FxHashMap;
56-
use serde::{de, Deserialize};
56+
use serde::{de, Deserialize, Serialize};
5757
use std::path::PathBuf;
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<PathBuf>,
180180
sysroot_src: Option<PathBuf>,
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: PathBuf,
@@ -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")]
@@ -224,7 +224,7 @@ impl From<EditionData> for Edition {
224224
}
225225
}
226226

227-
#[derive(Deserialize, Debug, Clone)]
227+
#[derive(Serialize, Deserialize, Debug, Clone)]
228228
struct DepData {
229229
/// Identifies a crate by position in the crates array.
230230
#[serde(rename = "crate")]
@@ -233,7 +233,7 @@ struct DepData {
233233
name: CrateName,
234234
}
235235

236-
#[derive(Deserialize, Debug, Clone)]
236+
#[derive(Serialize, Deserialize, Debug, Clone)]
237237
struct CrateSource {
238238
include_dirs: Vec<PathBuf>,
239239
exclude_dirs: Vec<PathBuf>,

crates/rust-analyzer/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ tracing-subscriber = { version = "0.3.16", default-features = false, features =
4444
tracing-log = "0.1.3"
4545
tracing-tree = "0.2.1"
4646
triomphe.workspace = true
47+
toml = "0.8.8"
4748
nohash-hasher.workspace = true
4849
always-assert = "0.1.2"
4950

0 commit comments

Comments
 (0)