mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Omit modules during autocompletion
This commit is contained in:
parent
46514448b7
commit
3b0fc4d7f2
2 changed files with 119 additions and 68 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
use assists::utils::{insert_use, mod_path_to_ast, ImportScope};
|
||||
use either::Either;
|
||||
use hir::ScopeDef;
|
||||
use hir::{ModuleDef, ScopeDef};
|
||||
use ide_db::imports_locator;
|
||||
use syntax::{algo, AstNode};
|
||||
|
||||
|
@ -13,7 +13,6 @@ use crate::{
|
|||
|
||||
use super::Completions;
|
||||
|
||||
// TODO kb reuse auto_import assist approach to add trait completion
|
||||
// TODO kb add a setting toggle for this feature?
|
||||
pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||
if !(ctx.is_trivial_path || ctx.is_pat_binding_or_const) {
|
||||
|
@ -28,17 +27,18 @@ pub(crate) fn complete_magic(acc: &mut Completions, ctx: &CompletionContext) ->
|
|||
|
||||
let possible_imports =
|
||||
imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, 400)
|
||||
.filter_map(|import_candidate| {
|
||||
Some(match import_candidate {
|
||||
Either::Left(module_def) => (
|
||||
current_module.find_use_path(ctx.db, module_def)?,
|
||||
ScopeDef::ModuleDef(module_def),
|
||||
),
|
||||
Either::Right(macro_def) => (
|
||||
current_module.find_use_path(ctx.db, macro_def)?,
|
||||
ScopeDef::MacroDef(macro_def),
|
||||
),
|
||||
})
|
||||
.filter_map(|import_candidate| match import_candidate {
|
||||
// when completing outside the use declaration, modules are pretty useless
|
||||
// and tend to bloat the completion suggestions a lot
|
||||
Either::Left(ModuleDef::Module(_)) => None,
|
||||
Either::Left(module_def) => Some((
|
||||
current_module.find_use_path(ctx.db, module_def)?,
|
||||
ScopeDef::ModuleDef(module_def),
|
||||
)),
|
||||
Either::Right(macro_def) => Some((
|
||||
current_module.find_use_path(ctx.db, macro_def)?,
|
||||
ScopeDef::MacroDef(macro_def),
|
||||
)),
|
||||
})
|
||||
.filter_map(|(mod_path, definition)| {
|
||||
let mut resolution_with_missing_import = render_resolution(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue