mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Anchor file-system operations to the file, and not to the source root.
Anchoring to the SourceRoot wont' work if the path is absolute: #[path = "/tmp/foo.rs"] mod foo; Anchoring to a file will. However, we *should* anchor, instead of just producing an abs path. I can imagine a situation where, for example, rust-analyzer processes crates from different machines (or, for example, from in-memory git branch), where the same absolute path in different crates might refer to different files in the end!
This commit is contained in:
parent
da34d630b8
commit
3c72fc0573
8 changed files with 67 additions and 81 deletions
|
@ -11,7 +11,7 @@ use hir::{
|
|||
Semantics,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use ra_db::{RelativePath, SourceDatabase, SourceDatabaseExt};
|
||||
use ra_db::SourceDatabase;
|
||||
use ra_ide_db::RootDatabase;
|
||||
use ra_prof::profile;
|
||||
use ra_syntax::{
|
||||
|
@ -57,14 +57,10 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
|||
})
|
||||
.on::<hir::diagnostics::UnresolvedModule, _>(|d| {
|
||||
let original_file = d.source().file_id.original_file(db);
|
||||
let source_root = db.file_source_root(original_file);
|
||||
let path = db
|
||||
.file_relative_path(original_file)
|
||||
.parent()
|
||||
.unwrap_or_else(|| RelativePath::new(""))
|
||||
.join(&d.candidate);
|
||||
let fix =
|
||||
Fix::new("Create module", FileSystemEdit::CreateFile { source_root, path }.into());
|
||||
let fix = Fix::new(
|
||||
"Create module",
|
||||
FileSystemEdit::CreateFile { anchor: original_file, dst: d.candidate.clone() }.into(),
|
||||
);
|
||||
res.borrow_mut().push(Diagnostic {
|
||||
range: sema.diagnostics_range(d).range,
|
||||
message: d.message(),
|
||||
|
@ -612,10 +608,10 @@ mod tests {
|
|||
source_file_edits: [],
|
||||
file_system_edits: [
|
||||
CreateFile {
|
||||
source_root: SourceRootId(
|
||||
0,
|
||||
anchor: FileId(
|
||||
1,
|
||||
),
|
||||
path: "foo.rs",
|
||||
dst: "foo.rs",
|
||||
},
|
||||
],
|
||||
is_snippet: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue