mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Fix some tests
This commit is contained in:
parent
582cee2cdf
commit
d386481fac
4 changed files with 143 additions and 49 deletions
|
@ -97,7 +97,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
|
|||
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind)
|
||||
.into_iter()
|
||||
.map(|import| {
|
||||
let proposed_def = match import.item_to_import() {
|
||||
let proposed_def = match import.item_to_display() {
|
||||
hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()),
|
||||
hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()),
|
||||
hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()),
|
||||
|
@ -809,7 +809,7 @@ fn main() {
|
|||
#[test]
|
||||
fn unresolved_assoc_item_container() {
|
||||
check_edit(
|
||||
"Item",
|
||||
"TEST_ASSOC",
|
||||
r#"
|
||||
mod foo {
|
||||
pub struct Item;
|
||||
|
@ -820,7 +820,7 @@ mod foo {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
Item::TEST_A$0;
|
||||
Item::TEST_A$0
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
|
@ -844,7 +844,7 @@ fn main() {
|
|||
#[test]
|
||||
fn unresolved_assoc_item_container_with_path() {
|
||||
check_edit(
|
||||
"Item",
|
||||
"TEST_ASSOC",
|
||||
r#"
|
||||
mod foo {
|
||||
pub mod bar {
|
||||
|
@ -857,7 +857,7 @@ mod foo {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
bar::Item::TEST_A$0;
|
||||
bar::Item::TEST_A$0
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
|
@ -876,6 +876,61 @@ mod foo {
|
|||
fn main() {
|
||||
bar::Item::TEST_ASSOC
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unresolved_assoc_item_container_and_trait_with_path() {
|
||||
check_edit(
|
||||
"TEST_ASSOC",
|
||||
r#"
|
||||
mod foo {
|
||||
pub mod bar {
|
||||
pub trait SomeTrait {
|
||||
const TEST_ASSOC: usize;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod baz {
|
||||
use super::bar::SomeTrait;
|
||||
|
||||
pub struct Item;
|
||||
|
||||
impl SomeTrait for Item {
|
||||
const TEST_ASSOC: usize = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
baz::Item::TEST_A$0
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
use foo::{bar::SomeTrait, baz};
|
||||
|
||||
mod foo {
|
||||
pub mod bar {
|
||||
pub trait SomeTrait {
|
||||
const TEST_ASSOC: usize;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod baz {
|
||||
use super::bar::SomeTrait;
|
||||
|
||||
pub struct Item;
|
||||
|
||||
impl SomeTrait for Item {
|
||||
const TEST_ASSOC: usize = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
baz::Item::TEST_ASSOC
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,10 @@ mod builder_ext;
|
|||
use hir::{
|
||||
AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type,
|
||||
};
|
||||
use ide_db::{helpers::SnippetCap, RootDatabase, SymbolKind};
|
||||
use ide_db::{
|
||||
helpers::{item_name, SnippetCap},
|
||||
RootDatabase, SymbolKind,
|
||||
};
|
||||
use syntax::TextRange;
|
||||
|
||||
use crate::{
|
||||
|
@ -56,7 +59,7 @@ pub(crate) fn render_resolution_with_import<'a>(
|
|||
ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(),
|
||||
ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(),
|
||||
ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(),
|
||||
_ => import_edit.import.display_path().segments().last()?.to_string(),
|
||||
_ => item_name(ctx.db(), import_edit.import.item_to_display())?.to_string(),
|
||||
};
|
||||
Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| {
|
||||
item.completion_kind = CompletionKind::Magic;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue