mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Move path completion to descriptors
This commit is contained in:
parent
11f19b7849
commit
7ffc7d3308
3 changed files with 36 additions and 18 deletions
|
@ -220,6 +220,20 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_completion_self_path() {
|
||||
check_scope_completion(
|
||||
r"
|
||||
use self::m::B<|>;
|
||||
|
||||
mod m {
|
||||
struct Bar;
|
||||
}
|
||||
",
|
||||
r#"[CompletionItem { label: "Bar", lookup: None, snippet: None }]"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_completion_mod_scope_nested() {
|
||||
check_scope_completion(
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
|||
descriptors::{
|
||||
module::{ModuleDescriptor},
|
||||
function::FnScopes,
|
||||
Path, PathKind,
|
||||
Path,
|
||||
},
|
||||
Cancelable
|
||||
};
|
||||
|
@ -148,9 +148,13 @@ fn complete_path(
|
|||
acc: &mut Vec<CompletionItem>,
|
||||
db: &RootDatabase,
|
||||
module: &ModuleDescriptor,
|
||||
path: Path,
|
||||
mut path: Path,
|
||||
) -> Cancelable<()> {
|
||||
let target_module = match find_target_module(module, path) {
|
||||
if path.segments.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
path.segments.pop();
|
||||
let target_module = match module.resolve_path(path) {
|
||||
None => return Ok(()),
|
||||
Some(it) => it,
|
||||
};
|
||||
|
@ -167,19 +171,6 @@ fn complete_path(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn find_target_module(module: &ModuleDescriptor, path: Path) -> Option<ModuleDescriptor> {
|
||||
if path.kind != PathKind::Crate {
|
||||
return None;
|
||||
}
|
||||
let mut segments = path.segments;
|
||||
segments.pop();
|
||||
let mut target_module = module.crate_root();
|
||||
for name in segments {
|
||||
target_module = target_module.child(&name)?;
|
||||
}
|
||||
Some(target_module)
|
||||
}
|
||||
|
||||
fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) {
|
||||
acc.push(CompletionItem {
|
||||
label: "tfn".to_string(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue