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) {
|
pub(crate) fn add_keyword(&mut self, ctx: &CompletionContext<'_>, keyword: &'static str) {
|
||||||
let item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), keyword);
|
let item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), keyword);
|
||||||
item.add_to(self);
|
item.add_to(self);
|
||||||
|
@ -88,7 +88,13 @@ pub(crate) fn complete_expr_path(
|
|||||||
let module_scope = module.scope(ctx.db, Some(ctx.module));
|
let module_scope = module.scope(ctx.db, Some(ctx.module));
|
||||||
for (name, def) in module_scope {
|
for (name, def) in module_scope {
|
||||||
if scope_def_applicable(def) {
|
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,30 +257,22 @@ fn import_on_the_fly(
|
|||||||
};
|
};
|
||||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||||
|
|
||||||
acc.add_all(
|
import_assets
|
||||||
import_assets
|
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
||||||
.search_for_imports(
|
.into_iter()
|
||||||
&ctx.sema,
|
.filter(ns_filter)
|
||||||
ctx.config.insert_use.prefix_kind,
|
.filter(|import| {
|
||||||
ctx.config.prefer_no_std,
|
!ctx.is_item_hidden(&import.item_to_import)
|
||||||
)
|
&& !ctx.is_item_hidden(&import.original_item)
|
||||||
.into_iter()
|
})
|
||||||
.filter(ns_filter)
|
.sorted_by_key(|located_import| {
|
||||||
.filter(|import| {
|
compute_fuzzy_completion_order_key(&located_import.import_path, &user_input_lowercased)
|
||||||
!ctx.is_item_hidden(&import.item_to_import)
|
})
|
||||||
&& !ctx.is_item_hidden(&import.original_item)
|
.filter_map(|import| {
|
||||||
})
|
render_resolution_with_import(RenderContext::new(ctx), path_ctx, import)
|
||||||
.sorted_by_key(|located_import| {
|
})
|
||||||
compute_fuzzy_completion_order_key(
|
.map(|builder| builder.build())
|
||||||
&located_import.import_path,
|
.for_each(|item| acc.add(item));
|
||||||
&user_input_lowercased,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.filter_map(|import| {
|
|
||||||
render_resolution_with_import(RenderContext::new(ctx), path_ctx, import)
|
|
||||||
})
|
|
||||||
.map(|builder| builder.build()),
|
|
||||||
);
|
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,30 +297,22 @@ fn import_on_the_fly_pat_(
|
|||||||
};
|
};
|
||||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||||
|
|
||||||
acc.add_all(
|
import_assets
|
||||||
import_assets
|
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
||||||
.search_for_imports(
|
.into_iter()
|
||||||
&ctx.sema,
|
.filter(ns_filter)
|
||||||
ctx.config.insert_use.prefix_kind,
|
.filter(|import| {
|
||||||
ctx.config.prefer_no_std,
|
!ctx.is_item_hidden(&import.item_to_import)
|
||||||
)
|
&& !ctx.is_item_hidden(&import.original_item)
|
||||||
.into_iter()
|
})
|
||||||
.filter(ns_filter)
|
.sorted_by_key(|located_import| {
|
||||||
.filter(|import| {
|
compute_fuzzy_completion_order_key(&located_import.import_path, &user_input_lowercased)
|
||||||
!ctx.is_item_hidden(&import.item_to_import)
|
})
|
||||||
&& !ctx.is_item_hidden(&import.original_item)
|
.filter_map(|import| {
|
||||||
})
|
render_resolution_with_import_pat(RenderContext::new(ctx), pattern_ctx, import)
|
||||||
.sorted_by_key(|located_import| {
|
})
|
||||||
compute_fuzzy_completion_order_key(
|
.map(|builder| builder.build())
|
||||||
&located_import.import_path,
|
.for_each(|item| acc.add(item));
|
||||||
&user_input_lowercased,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.filter_map(|import| {
|
|
||||||
render_resolution_with_import_pat(RenderContext::new(ctx), pattern_ctx, import)
|
|
||||||
})
|
|
||||||
.map(|builder| builder.build()),
|
|
||||||
);
|
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +410,12 @@ pub(crate) fn from_resolution(
|
|||||||
resolution: hir::ScopeDef,
|
resolution: hir::ScopeDef,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let doc_aliases = ctx.doc_aliases_in_scope(resolution);
|
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 {
|
pub(crate) fn build(self) -> CompletionItem {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
use ide_db::{
|
use ide_db::{
|
||||||
helpers::item_name, imports::import_assets::LocatedImport, RootDatabase, SnippetCap, SymbolKind,
|
helpers::item_name, imports::import_assets::LocatedImport, RootDatabase, SnippetCap, SymbolKind,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
|
||||||
use syntax::{AstNode, SmolStr, SyntaxKind, TextRange};
|
use syntax::{AstNode, SmolStr, SyntaxKind, TextRange};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -210,7 +209,9 @@ pub(crate) fn render_resolution_with_import(
|
|||||||
) -> Option<Builder> {
|
) -> Option<Builder> {
|
||||||
let resolution = ScopeDef::from(import_edit.original_item);
|
let resolution = ScopeDef::from(import_edit.original_item);
|
||||||
let local_name = scope_def_to_name(resolution, &ctx, &import_edit)?;
|
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))
|
Some(render_resolution_path(ctx, path_ctx, local_name, Some(import_edit), resolution))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1188,4 +1188,39 @@ fn here_we_go() {
|
|||||||
st Bar (alias Qux)
|
st Bar (alias Qux)
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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