Skip to content

Commit 1d8b151

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 a016555 commit 1d8b151

File tree

16 files changed

+1181
-743
lines changed

16 files changed

+1181
-743
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
@@ -17,6 +17,7 @@ salsa.workspace = true
1717
rustc-hash.workspace = true
1818
triomphe.workspace = true
1919
semver.workspace = true
20+
serde.workspace = true
2021
tracing.workspace = true
2122

2223
# 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
@@ -12,40 +12,49 @@ use cfg::CfgOptions;
1212
use la_arena::{Arena, Idx, RawIdx};
1313
use rustc_hash::{FxHashMap, FxHashSet};
1414
use semver::Version;
15+
use serde::Serialize;
1516
use syntax::SmolStr;
1617
use triomphe::Arc;
1718
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
1819

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, DependencyKind,
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;
@@ -175,14 +175,14 @@ impl ProjectJson {
175175
}
176176
}
177177

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

185-
#[derive(Deserialize, Debug, Clone)]
185+
#[derive(Serialize, Deserialize, Debug, Clone)]
186186
struct CrateData {
187187
display_name: Option<String>,
188188
root_module: PathBuf,
@@ -204,7 +204,7 @@ struct CrateData {
204204
repository: Option<String>,
205205
}
206206

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

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

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

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)