⬆️ rust-analyzer

This commit is contained in:
Laurențiu Nicola 2022-10-26 17:40:41 +03:00
parent 26a413e015
commit 8807fc4cc3
64 changed files with 2244 additions and 1607 deletions

View file

@ -4913,22 +4913,6 @@ fn foo() -> NotResult<(), Short> {
```
"#]],
);
check_hover_range(
r#"
//- minicore: try
use core::ops::ControlFlow;
fn foo() -> ControlFlow<()> {
$0ControlFlow::Break(())?$0;
ControlFlow::Continue(())
}
"#,
expect![[r#"
```text
Try Target Type: ControlFlow<(), {unknown}>
Propagated as: ControlFlow<(), ()>
```
"#]],
);
}
#[test]
@ -4944,9 +4928,9 @@ fn foo() -> Option<()> {
}
"#,
expect![[r#"
```rust
i32
```"#]],
```rust
<Option<i32> as Try>::Output
```"#]],
);
}

View file

@ -482,8 +482,18 @@ impl Analysis {
}
/// Returns crates this file belongs too.
pub fn crate_for(&self, file_id: FileId) -> Cancellable<Vec<CrateId>> {
self.with_db(|db| parent_module::crate_for(db, file_id))
pub fn crates_for(&self, file_id: FileId) -> Cancellable<Vec<CrateId>> {
self.with_db(|db| parent_module::crates_for(db, file_id))
}
/// Returns crates this file belongs too.
pub fn transitive_rev_deps(&self, crate_id: CrateId) -> Cancellable<Vec<CrateId>> {
self.with_db(|db| db.crate_graph().transitive_rev_deps(crate_id).collect())
}
/// Returns crates this file *might* belong too.
pub fn relevant_crates_for(&self, file_id: FileId) -> Cancellable<Vec<CrateId>> {
self.with_db(|db| db.relevant_crates(file_id).iter().copied().collect())
}
/// Returns the edition of the given crate.

View file

@ -1,6 +1,6 @@
use hir::Semantics;
use hir::{db::DefDatabase, Semantics};
use ide_db::{
base_db::{CrateId, FileId, FilePosition},
base_db::{CrateId, FileId, FileLoader, FilePosition},
RootDatabase,
};
use itertools::Itertools;
@ -55,9 +55,13 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
}
/// Returns `Vec` for the same reason as `parent_module`
pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
let sema = Semantics::new(db);
sema.to_module_defs(file_id).map(|module| module.krate().into()).unique().collect()
pub(crate) fn crates_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
db.relevant_crates(file_id)
.iter()
.copied()
.filter(|&crate_id| db.crate_def_map(crate_id).modules_for_file(file_id).next().is_some())
.sorted()
.collect()
}
#[cfg(test)]
@ -147,7 +151,7 @@ $0
mod foo;
"#,
);
assert_eq!(analysis.crate_for(file_id).unwrap().len(), 1);
assert_eq!(analysis.crates_for(file_id).unwrap().len(), 1);
}
#[test]
@ -162,6 +166,6 @@ mod baz;
mod baz;
"#,
);
assert_eq!(analysis.crate_for(file_id).unwrap().len(), 2);
assert_eq!(analysis.crates_for(file_id).unwrap().len(), 2);
}
}

View file

@ -210,9 +210,7 @@ fn get_definition(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> Opt
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions_no_ops);
if let Some(&[x]) = def.as_deref() {
return Some(x);
} else {
continue;
};
}
}
None
}

View file

@ -45,7 +45,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
if let Some(file_id) = file_id {
format_to!(buf, "\nFile info:\n");
let crates = crate::parent_module::crate_for(db, file_id);
let crates = crate::parent_module::crates_for(db, file_id);
if crates.is_empty() {
format_to!(buf, "Does not belong to any crate");
}