Render alias text for use imports
* removes one method breaking the flow
This commit is contained in:
parent
b4515d987f
commit
33ee157f3b
@ -78,14 +78,6 @@ fn add_opt(&mut self, item: Option<CompletionItem>) {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn add_all<I>(&mut self, items: I)
|
||||
where
|
||||
I: IntoIterator,
|
||||
I::Item: Into<CompletionItem>,
|
||||
{
|
||||
items.into_iter().for_each(|item| self.add(item.into()))
|
||||
}
|
||||
|
||||
pub(crate) fn add_keyword(&mut self, ctx: &CompletionContext<'_>, keyword: &'static str) {
|
||||
let item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), keyword);
|
||||
item.add_to(self);
|
||||
|
@ -88,7 +88,13 @@ pub(crate) fn complete_expr_path(
|
||||
let module_scope = module.scope(ctx.db, Some(ctx.module));
|
||||
for (name, def) in module_scope {
|
||||
if scope_def_applicable(def) {
|
||||
acc.add_path_resolution(ctx, path_ctx, name, def, ctx.doc_aliases_in_scope(def));
|
||||
acc.add_path_resolution(
|
||||
ctx,
|
||||
path_ctx,
|
||||
name,
|
||||
def,
|
||||
ctx.doc_aliases_in_scope(def),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,13 +257,8 @@ fn import_on_the_fly(
|
||||
};
|
||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||
|
||||
acc.add_all(
|
||||
import_assets
|
||||
.search_for_imports(
|
||||
&ctx.sema,
|
||||
ctx.config.insert_use.prefix_kind,
|
||||
ctx.config.prefer_no_std,
|
||||
)
|
||||
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
||||
.into_iter()
|
||||
.filter(ns_filter)
|
||||
.filter(|import| {
|
||||
@ -271,16 +266,13 @@ fn import_on_the_fly(
|
||||
&& !ctx.is_item_hidden(&import.original_item)
|
||||
})
|
||||
.sorted_by_key(|located_import| {
|
||||
compute_fuzzy_completion_order_key(
|
||||
&located_import.import_path,
|
||||
&user_input_lowercased,
|
||||
)
|
||||
compute_fuzzy_completion_order_key(&located_import.import_path, &user_input_lowercased)
|
||||
})
|
||||
.filter_map(|import| {
|
||||
render_resolution_with_import(RenderContext::new(ctx), path_ctx, import)
|
||||
})
|
||||
.map(|builder| builder.build()),
|
||||
);
|
||||
.map(|builder| builder.build())
|
||||
.for_each(|item| acc.add(item));
|
||||
Some(())
|
||||
}
|
||||
|
||||
@ -305,13 +297,8 @@ fn import_on_the_fly_pat_(
|
||||
};
|
||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||
|
||||
acc.add_all(
|
||||
import_assets
|
||||
.search_for_imports(
|
||||
&ctx.sema,
|
||||
ctx.config.insert_use.prefix_kind,
|
||||
ctx.config.prefer_no_std,
|
||||
)
|
||||
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
||||
.into_iter()
|
||||
.filter(ns_filter)
|
||||
.filter(|import| {
|
||||
@ -319,16 +306,13 @@ fn import_on_the_fly_pat_(
|
||||
&& !ctx.is_item_hidden(&import.original_item)
|
||||
})
|
||||
.sorted_by_key(|located_import| {
|
||||
compute_fuzzy_completion_order_key(
|
||||
&located_import.import_path,
|
||||
&user_input_lowercased,
|
||||
)
|
||||
compute_fuzzy_completion_order_key(&located_import.import_path, &user_input_lowercased)
|
||||
})
|
||||
.filter_map(|import| {
|
||||
render_resolution_with_import_pat(RenderContext::new(ctx), pattern_ctx, import)
|
||||
})
|
||||
.map(|builder| builder.build()),
|
||||
);
|
||||
.map(|builder| builder.build())
|
||||
.for_each(|item| acc.add(item));
|
||||
Some(())
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,12 @@ pub(crate) fn from_resolution(
|
||||
resolution: hir::ScopeDef,
|
||||
) -> Self {
|
||||
let doc_aliases = ctx.doc_aliases_in_scope(resolution);
|
||||
render_path_resolution(RenderContext::new(ctx).doc_aliases(doc_aliases), path_ctx, local_name, resolution)
|
||||
render_path_resolution(
|
||||
RenderContext::new(ctx).doc_aliases(doc_aliases),
|
||||
path_ctx,
|
||||
local_name,
|
||||
resolution,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn build(self) -> CompletionItem {
|
||||
|
@ -14,7 +14,6 @@
|
||||
use ide_db::{
|
||||
helpers::item_name, imports::import_assets::LocatedImport, RootDatabase, SnippetCap, SymbolKind,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use syntax::{AstNode, SmolStr, SyntaxKind, TextRange};
|
||||
|
||||
use crate::{
|
||||
@ -210,7 +209,9 @@ pub(crate) fn render_resolution_with_import(
|
||||
) -> Option<Builder> {
|
||||
let resolution = ScopeDef::from(import_edit.original_item);
|
||||
let local_name = scope_def_to_name(resolution, &ctx, &import_edit)?;
|
||||
|
||||
//this now just renders the alias text, but we need to find the aliases earlier and call this with the alias instead
|
||||
let doc_aliases = ctx.completion.doc_aliases_in_scope(resolution);
|
||||
let ctx = ctx.doc_aliases(doc_aliases);
|
||||
Some(render_resolution_path(ctx, path_ctx, local_name, Some(import_edit), resolution))
|
||||
}
|
||||
|
||||
|
@ -1189,3 +1189,38 @@ fn here_we_go() {
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completes_flyimport_with_doc_alias_in_another_mod() {
|
||||
check(
|
||||
r#"
|
||||
mod foo {
|
||||
#[doc(alias = "Qux")]
|
||||
pub struct Bar();
|
||||
}
|
||||
|
||||
fn here_we_go() {
|
||||
let foo = Bar$0
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
fn here_we_go() fn()
|
||||
md foo
|
||||
st Bar (alias Qux) (use foo::Bar)
|
||||
bt u32
|
||||
kw crate::
|
||||
kw false
|
||||
kw for
|
||||
kw if
|
||||
kw if let
|
||||
kw loop
|
||||
kw match
|
||||
kw return
|
||||
kw self::
|
||||
kw true
|
||||
kw unsafe
|
||||
kw while
|
||||
kw while let
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user