Skip to content

Commit f11b0da

Browse files
committed
Last commit before issuing a draft
1 parent 3e274f3 commit f11b0da

File tree

8 files changed

+77
-14
lines changed

8 files changed

+77
-14
lines changed

crates/base-db/src/change.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ impl fmt::Debug for Change {
2525
d.field("roots", roots);
2626
}
2727
if !self.files_changed.is_empty() {
28-
d.field("files_changed", &self.files_changed.len());
28+
d.field("files_changed", &self.files_changed);
29+
// d.field("files_changed", &self.files_changed.len());
2930
}
3031
if self.crate_graph.is_some() {
3132
d.field("crate_graph", &self.crate_graph);

crates/base-db/src/input.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,36 @@ use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
2121
pub type ProcMacroPaths = FxHashMap<CrateId, Result<(Option<String>, AbsPathBuf), String>>;
2222
pub type ProcMacros = FxHashMap<CrateId, ProcMacroLoadResult>;
2323

24+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
25+
pub struct SourceRootId(pub u32);
26+
2427
/// Files are grouped into source roots. A source root is a directory on the
2528
/// file systems which is watched for changes. Typically it corresponds to a
2629
/// Rust crate. Source roots *might* be nested: in this case, a file belongs to
2730
/// the nearest enclosing source root. Paths to files are always relative to a
2831
/// source root, and the analyzer does not know the root path of the source root at
2932
/// all. So, a file from one source root can't refer to a file in another source
3033
/// root by path.
31-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
32-
pub struct SourceRootId(pub u32);
33-
3434
#[derive(Clone, Debug, PartialEq, Eq)]
3535
pub struct SourceRoot {
3636
/// Sysroot or crates.io library.
3737
///
3838
/// Libraries are considered mostly immutable, this assumption is used to
3939
/// optimize salsa's query structure
4040
pub is_library: bool,
41+
cargo_file_id: Option<FileId>,
42+
ratoml_file_id: Option<FileId>,
4143
file_set: FileSet,
4244
}
4345

4446
impl SourceRoot {
4547
pub fn new_local(file_set: FileSet) -> SourceRoot {
46-
SourceRoot { is_library: false, file_set }
48+
eprintln!("{:#?}", file_set);
49+
SourceRoot { is_library: false, file_set, cargo_file_id: None, ratoml_file_id: None }
4750
}
4851

4952
pub fn new_library(file_set: FileSet) -> SourceRoot {
50-
SourceRoot { is_library: true, file_set }
53+
SourceRoot { is_library: true, file_set, cargo_file_id: None, ratoml_file_id: None }
5154
}
5255

5356
pub fn path_for_file(&self, file: &FileId) -> Option<&VfsPath> {
@@ -65,6 +68,16 @@ impl SourceRoot {
6568
pub fn iter(&self) -> impl Iterator<Item = FileId> + '_ {
6669
self.file_set.iter()
6770
}
71+
72+
/// Get `FileId` of the `Cargo.toml` if one present in `SourceRoot`
73+
pub fn cargo_toml(&self) -> Option<FileId> {
74+
self.cargo_file_id
75+
}
76+
77+
/// Get `FileId` of the `rust-analyzer.toml` if one present in `SourceRoot`
78+
pub fn ratoml(&self) -> Option<FileId> {
79+
self.ratoml_file_id
80+
}
6881
}
6982

7083
/// `CrateGraph` is a bit of information which turns a set of text files into a

crates/load-cargo/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ impl ProjectFolders {
208208
let entry = {
209209
let mut dirs = vfs::loader::Directories::default();
210210
dirs.extensions.push("rs".into());
211+
dirs.extensions.push("toml".into());
211212
dirs.include.extend(root.include);
212213
dirs.exclude.extend(root.exclude);
213214
for excl in global_excludes {

crates/rust-analyzer/src/global_state.rs

-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ impl GlobalState {
330330
}
331331
(change, changed_files, workspace_structure_change)
332332
};
333-
334333
self.analysis_host.apply_change(change);
335334

336335
{

crates/rust-analyzer/src/main_loop.rs

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl GlobalState {
131131
Event::Lsp(lsp_server::Message::Notification(Notification { method, .. }))
132132
if method == lsp_types::notification::Exit::METHOD
133133
) {
134+
dbg!("EXIT");
134135
return Ok(());
135136
}
136137
self.handle_event(event)?;
@@ -159,6 +160,11 @@ impl GlobalState {
159160
scheme: None,
160161
pattern: Some("**/Cargo.lock".into()),
161162
},
163+
lsp_types::DocumentFilter {
164+
language: None,
165+
scheme: None,
166+
pattern: Some("**/.rust-analyzer.toml".into()),
167+
},
162168
]),
163169
},
164170
};

crates/rust-analyzer/src/reload.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ impl GlobalState {
172172
}
173173
}
174174

175-
if let Err(_) = self.fetch_workspace_error() {
175+
if let Err(k) = self.fetch_workspace_error() {
176+
dbg!(&k);
176177
status.health = lsp_ext::Health::Error;
177178
message.push_str("Failed to load workspaces.\n\n");
178179
}
@@ -414,6 +415,8 @@ impl GlobalState {
414415
format!("{it}/**/*.rs"),
415416
format!("{it}/**/Cargo.toml"),
416417
format!("{it}/**/Cargo.lock"),
418+
// FIXME @alibektas : WS may not have to be local for RATOML to be included.
419+
format!("{it}/**/.rust-analyzer.toml"),
417420
]
418421
})
419422
})
@@ -526,6 +529,7 @@ impl GlobalState {
526529
change.set_crate_graph(crate_graph);
527530
self.analysis_host.apply_change(change);
528531
self.crate_graph_file_dependencies = crate_graph_file_dependencies;
532+
eprintln!("Recreate crate graph");
529533
self.process_changes();
530534

531535
self.reload_flycheck();

crates/rust-analyzer/tests/slow-tests/main.rs

+39
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,42 @@ version = "0.0.0"
11311131

11321132
server.request::<WorkspaceSymbolRequest>(Default::default(), json!([]));
11331133
}
1134+
1135+
#[test]
1136+
fn test_ratoml_exists() {
1137+
if skip_slow_tests() {
1138+
return;
1139+
}
1140+
1141+
let server = Project::with_fixture(
1142+
r#"
1143+
//- /foo/Cargo.toml
1144+
[package]
1145+
name = "foo"
1146+
version = "0.0.0"
1147+
1148+
[dependencies]
1149+
bar.path = "./bar"
1150+
1151+
//- /foo/src/lib.rs
1152+
pub fn foo() {}
1153+
1154+
//- /foo/src/abc/mod.rs
1155+
pub fn bar() {}
1156+
1157+
//- /foo/.rust-analyzer.toml
1158+
ABC
1159+
1160+
//- /foo/bar/Cargo.toml
1161+
[package]
1162+
name = "bar"
1163+
version = "0.0.0"
1164+
1165+
//- /foo/bar/src/lib.rs
1166+
pub fn bar() {}
1167+
"#,
1168+
)
1169+
.root("foo")
1170+
.server()
1171+
.wait_until_workspace_is_loaded();
1172+
}

crates/vfs/src/file_set.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hash::FxHashMap;
1111
use crate::{AnchoredPath, FileId, Vfs, VfsPath};
1212

1313
/// A set of [`VfsPath`]s identified by [`FileId`]s.
14-
#[derive(Default, Clone, Eq, PartialEq)]
14+
#[derive(Default, Debug, Clone, Eq, PartialEq)]
1515
pub struct FileSet {
1616
files: FxHashMap<VfsPath, FileId>,
1717
paths: IntMap<FileId, VfsPath>,
@@ -59,11 +59,11 @@ impl FileSet {
5959
}
6060
}
6161

62-
impl fmt::Debug for FileSet {
63-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64-
f.debug_struct("FileSet").field("n_files", &self.files.len()).finish()
65-
}
66-
}
62+
// impl fmt::Debug for FileSet {
63+
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64+
// f.debug_struct("FileSet").field("n_files", &self.files.len()).finish()
65+
// }
66+
// }
6767

6868
/// This contains path prefixes to partition a [`Vfs`] into [`FileSet`]s.
6969
///

0 commit comments

Comments
 (0)