mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Use stateless completion resolve
This commit is contained in:
parent
93bc009a59
commit
deda74edd8
6 changed files with 123 additions and 70 deletions
|
@ -11,8 +11,11 @@ mod render;
|
|||
|
||||
mod completions;
|
||||
|
||||
use ide_db::base_db::FilePosition;
|
||||
use ide_db::RootDatabase;
|
||||
use ide_db::{
|
||||
base_db::FilePosition, helpers::insert_use::ImportScope, imports_locator, RootDatabase,
|
||||
};
|
||||
use syntax::AstNode;
|
||||
use text_edit::TextEdit;
|
||||
|
||||
use crate::{completions::Completions, context::CompletionContext, item::CompletionKind};
|
||||
|
||||
|
@ -131,6 +134,31 @@ pub fn completions(
|
|||
Some(acc)
|
||||
}
|
||||
|
||||
/// Resolves additional completion data at the position given.
|
||||
pub fn resolve_completion_edits(
|
||||
db: &RootDatabase,
|
||||
config: &CompletionConfig,
|
||||
position: FilePosition,
|
||||
full_import_path: &str,
|
||||
imported_name: &str,
|
||||
) -> Option<TextEdit> {
|
||||
let ctx = CompletionContext::new(db, position, config)?;
|
||||
let anchor = ctx.name_ref_syntax.as_ref()?;
|
||||
let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
|
||||
|
||||
let current_module = ctx.sema.scope(anchor.syntax()).module()?;
|
||||
let current_crate = current_module.krate();
|
||||
|
||||
let import_path = imports_locator::find_exact_imports(&ctx.sema, current_crate, imported_name)
|
||||
.filter_map(|candidate| {
|
||||
let item: hir::ItemInNs = candidate.either(Into::into, Into::into);
|
||||
current_module.find_use_path(db, item)
|
||||
})
|
||||
.find(|mod_path| mod_path.to_string() == full_import_path)?;
|
||||
|
||||
ImportEdit { import_path, import_scope, merge_behaviour: config.merge }.to_text_edit()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::config::CompletionConfig;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue