Support trait aliases in IDE where type support isn't needed
This commit is contained in:
parent
29c957f973
commit
f8eac19b33
@ -149,6 +149,7 @@ fn collapse_ws(node: &SyntaxNode, output: &mut String) {
|
||||
ast::Enum(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Enum)),
|
||||
ast::Variant(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Variant)),
|
||||
ast::Trait(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Trait)),
|
||||
ast::TraitAlias(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::TraitAlias)),
|
||||
ast::Module(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Module)),
|
||||
ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::TypeAlias)),
|
||||
ast::RecordField(it) => decl_with_type_ref(&it, it.ty(), StructureNodeKind::SymbolKind(SymbolKind::Field)),
|
||||
@ -262,6 +263,8 @@ enum E { X, Y(i32) }
|
||||
type T = ();
|
||||
static S: i32 = 92;
|
||||
const C: i32 = 92;
|
||||
trait Tr {}
|
||||
trait Alias = Tr;
|
||||
|
||||
impl E {}
|
||||
|
||||
@ -457,11 +460,33 @@ fn g() {}
|
||||
),
|
||||
deprecated: false,
|
||||
},
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "Tr",
|
||||
navigation_range: 239..241,
|
||||
node_range: 233..244,
|
||||
kind: SymbolKind(
|
||||
Trait,
|
||||
),
|
||||
detail: None,
|
||||
deprecated: false,
|
||||
},
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "Alias",
|
||||
navigation_range: 251..256,
|
||||
node_range: 245..262,
|
||||
kind: SymbolKind(
|
||||
TraitAlias,
|
||||
),
|
||||
detail: None,
|
||||
deprecated: false,
|
||||
},
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "impl E",
|
||||
navigation_range: 239..240,
|
||||
node_range: 234..243,
|
||||
navigation_range: 269..270,
|
||||
node_range: 264..273,
|
||||
kind: SymbolKind(
|
||||
Impl,
|
||||
),
|
||||
@ -471,8 +496,8 @@ fn g() {}
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "impl fmt::Debug for E",
|
||||
navigation_range: 265..266,
|
||||
node_range: 245..269,
|
||||
navigation_range: 295..296,
|
||||
node_range: 275..299,
|
||||
kind: SymbolKind(
|
||||
Impl,
|
||||
),
|
||||
@ -482,8 +507,8 @@ fn g() {}
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "mc",
|
||||
navigation_range: 284..286,
|
||||
node_range: 271..303,
|
||||
navigation_range: 314..316,
|
||||
node_range: 301..333,
|
||||
kind: SymbolKind(
|
||||
Macro,
|
||||
),
|
||||
@ -493,8 +518,8 @@ fn g() {}
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "mcexp",
|
||||
navigation_range: 334..339,
|
||||
node_range: 305..356,
|
||||
navigation_range: 364..369,
|
||||
node_range: 335..386,
|
||||
kind: SymbolKind(
|
||||
Macro,
|
||||
),
|
||||
@ -504,8 +529,8 @@ fn g() {}
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "mcexp",
|
||||
navigation_range: 387..392,
|
||||
node_range: 358..409,
|
||||
navigation_range: 417..422,
|
||||
node_range: 388..439,
|
||||
kind: SymbolKind(
|
||||
Macro,
|
||||
),
|
||||
@ -515,8 +540,8 @@ fn g() {}
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "obsolete",
|
||||
navigation_range: 428..436,
|
||||
node_range: 411..441,
|
||||
navigation_range: 458..466,
|
||||
node_range: 441..471,
|
||||
kind: SymbolKind(
|
||||
Function,
|
||||
),
|
||||
@ -528,8 +553,8 @@ fn g() {}
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "very_obsolete",
|
||||
navigation_range: 481..494,
|
||||
node_range: 443..499,
|
||||
navigation_range: 511..524,
|
||||
node_range: 473..529,
|
||||
kind: SymbolKind(
|
||||
Function,
|
||||
),
|
||||
@ -541,8 +566,8 @@ fn g() {}
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "Some region name",
|
||||
navigation_range: 501..528,
|
||||
node_range: 501..528,
|
||||
navigation_range: 531..558,
|
||||
node_range: 531..558,
|
||||
kind: Region,
|
||||
detail: None,
|
||||
deprecated: false,
|
||||
@ -550,8 +575,8 @@ fn g() {}
|
||||
StructureNode {
|
||||
parent: None,
|
||||
label: "m",
|
||||
navigation_range: 568..569,
|
||||
node_range: 543..606,
|
||||
navigation_range: 598..599,
|
||||
node_range: 573..636,
|
||||
kind: SymbolKind(
|
||||
Module,
|
||||
),
|
||||
@ -560,22 +585,22 @@ fn g() {}
|
||||
},
|
||||
StructureNode {
|
||||
parent: Some(
|
||||
20,
|
||||
22,
|
||||
),
|
||||
label: "dontpanic",
|
||||
navigation_range: 543..563,
|
||||
node_range: 543..563,
|
||||
navigation_range: 573..593,
|
||||
node_range: 573..593,
|
||||
kind: Region,
|
||||
detail: None,
|
||||
deprecated: false,
|
||||
},
|
||||
StructureNode {
|
||||
parent: Some(
|
||||
20,
|
||||
22,
|
||||
),
|
||||
label: "f",
|
||||
navigation_range: 575..576,
|
||||
node_range: 572..581,
|
||||
navigation_range: 605..606,
|
||||
node_range: 602..611,
|
||||
kind: SymbolKind(
|
||||
Function,
|
||||
),
|
||||
@ -586,11 +611,11 @@ fn g() {}
|
||||
},
|
||||
StructureNode {
|
||||
parent: Some(
|
||||
20,
|
||||
22,
|
||||
),
|
||||
label: "g",
|
||||
navigation_range: 598..599,
|
||||
node_range: 582..604,
|
||||
navigation_range: 628..629,
|
||||
node_range: 612..634,
|
||||
kind: SymbolKind(
|
||||
Function,
|
||||
),
|
||||
|
@ -764,6 +764,13 @@ trait Foo$0 { }
|
||||
"#,
|
||||
);
|
||||
|
||||
check(
|
||||
r#"
|
||||
trait Foo$0 = ;
|
||||
//^^^
|
||||
"#,
|
||||
);
|
||||
|
||||
check(
|
||||
r#"
|
||||
mod bar$0 { }
|
||||
@ -1423,7 +1430,6 @@ macro_rules! include {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod goto_impl_of_trait_fn {
|
||||
use super::check;
|
||||
#[test]
|
||||
|
@ -32,7 +32,7 @@ impl Markup {
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.text.as_str()
|
||||
}
|
||||
pub fn fenced_block(contents: &impl fmt::Display) -> Markup {
|
||||
pub fn fenced_block(contents: impl fmt::Display) -> Markup {
|
||||
format!("```rust\n{contents}\n```").into()
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ fn find_ancestors(item: SyntaxElement, direction: Direction, range: TextRange) -
|
||||
SyntaxKind::MACRO_CALL,
|
||||
SyntaxKind::TYPE_ALIAS,
|
||||
SyntaxKind::TRAIT,
|
||||
SyntaxKind::TRAIT_ALIAS,
|
||||
SyntaxKind::IMPL,
|
||||
SyntaxKind::MACRO_DEF,
|
||||
SyntaxKind::STRUCT,
|
||||
|
@ -549,6 +549,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) ->
|
||||
ast::Struct(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Enum(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Trait(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::TraitAlias(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Module(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::TypeAlias(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
ast::Const(it) => sema.to_def(&it).map(|it| it.display(db).to_string()),
|
||||
|
@ -1355,6 +1355,38 @@ fn foo(self) {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trait_alias() {
|
||||
check(
|
||||
r#"
|
||||
trait Foo {}
|
||||
trait Bar$0 = Foo where Self: ;
|
||||
fn foo<T: Bar>(_: impl Bar, _: &dyn Bar) {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
Bar TraitAlias FileId(0) 13..42 19..22
|
||||
|
||||
FileId(0) 53..56
|
||||
FileId(0) 66..69
|
||||
FileId(0) 79..82
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trait_alias_self() {
|
||||
check(
|
||||
r#"
|
||||
trait Foo = where Self$0: ;
|
||||
"#,
|
||||
expect![[r#"
|
||||
Self TypeParam FileId(0) 6..9 6..9
|
||||
|
||||
FileId(0) 18..22
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_attr_differs_from_fn_with_same_name() {
|
||||
check(
|
||||
|
@ -416,6 +416,7 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option<Runnable> {
|
||||
Definition::Const(it) => it.attrs(db),
|
||||
Definition::Static(it) => it.attrs(db),
|
||||
Definition::Trait(it) => it.attrs(db),
|
||||
Definition::TraitAlias(it) => it.attrs(db),
|
||||
Definition::TypeAlias(it) => it.attrs(db),
|
||||
Definition::Macro(it) => it.attrs(db),
|
||||
Definition::SelfType(it) => it.attrs(db),
|
||||
|
Loading…
Reference in New Issue
Block a user