diff --git a/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap b/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap index 270f75a56e7..413f4a5ff69 100644 --- a/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap +++ b/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap @@ -1,8 +1,8 @@ --- -created: "2019-01-26T07:11:02.463391362+00:00" -creator: insta@0.5.2 -expression: structure +created: "2019-02-05T22:03:50.763530100Z" +creator: insta@0.6.1 source: crates/ra_ide_api_light/src/structure.rs +expression: structure --- [ StructureNode { @@ -11,7 +11,8 @@ source: crates/ra_ide_api_light/src/structure.rs navigation_range: [8; 11), node_range: [1; 26), kind: STRUCT_DEF, - detail: None + detail: None, + deprecated: false }, StructureNode { parent: Some( @@ -23,7 +24,8 @@ source: crates/ra_ide_api_light/src/structure.rs kind: NAMED_FIELD_DEF, detail: Some( "i32" - ) + ), + deprecated: false }, StructureNode { parent: None, @@ -31,7 +33,8 @@ source: crates/ra_ide_api_light/src/structure.rs navigation_range: [32; 33), node_range: [28; 158), kind: MODULE, - detail: None + detail: None, + deprecated: false }, StructureNode { parent: Some( @@ -43,7 +46,8 @@ source: crates/ra_ide_api_light/src/structure.rs kind: FN_DEF, detail: Some( "fn()" - ) + ), + deprecated: false }, StructureNode { parent: Some( @@ -55,7 +59,8 @@ source: crates/ra_ide_api_light/src/structure.rs kind: FN_DEF, detail: Some( "fn(t: T) -> T" - ) + ), + deprecated: false }, StructureNode { parent: Some( @@ -67,7 +72,8 @@ source: crates/ra_ide_api_light/src/structure.rs kind: FN_DEF, detail: Some( "fn(a: A, b: B) -> Vec< u32 >" - ) + ), + deprecated: false }, StructureNode { parent: None, @@ -75,7 +81,8 @@ source: crates/ra_ide_api_light/src/structure.rs navigation_range: [165; 166), node_range: [160; 180), kind: ENUM_DEF, - detail: None + detail: None, + deprecated: false }, StructureNode { parent: Some( @@ -85,7 +92,8 @@ source: crates/ra_ide_api_light/src/structure.rs navigation_range: [169; 170), node_range: [169; 170), kind: ENUM_VARIANT, - detail: None + detail: None, + deprecated: false }, StructureNode { parent: Some( @@ -95,7 +103,8 @@ source: crates/ra_ide_api_light/src/structure.rs navigation_range: [172; 173), node_range: [172; 178), kind: ENUM_VARIANT, - detail: None + detail: None, + deprecated: false }, StructureNode { parent: None, @@ -105,7 +114,8 @@ source: crates/ra_ide_api_light/src/structure.rs kind: TYPE_DEF, detail: Some( "()" - ) + ), + deprecated: false }, StructureNode { parent: None, @@ -115,7 +125,8 @@ source: crates/ra_ide_api_light/src/structure.rs kind: STATIC_DEF, detail: Some( "i32" - ) + ), + deprecated: false }, StructureNode { parent: None, @@ -125,7 +136,8 @@ source: crates/ra_ide_api_light/src/structure.rs kind: CONST_DEF, detail: Some( "i32" - ) + ), + deprecated: false }, StructureNode { parent: None, @@ -133,7 +145,8 @@ source: crates/ra_ide_api_light/src/structure.rs navigation_range: [239; 240), node_range: [234; 243), kind: IMPL_BLOCK, - detail: None + detail: None, + deprecated: false }, StructureNode { parent: None, @@ -141,6 +154,29 @@ source: crates/ra_ide_api_light/src/structure.rs navigation_range: [265; 266), node_range: [245; 269), kind: IMPL_BLOCK, - detail: None + detail: None, + deprecated: false + }, + StructureNode { + parent: None, + label: "obsolete", + navigation_range: [288; 296), + node_range: [271; 301), + kind: FN_DEF, + detail: Some( + "fn()" + ), + deprecated: true + }, + StructureNode { + parent: None, + label: "very_obsolete", + navigation_range: [341; 354), + node_range: [303; 359), + kind: FN_DEF, + detail: Some( + "fn()" + ), + deprecated: true } ] diff --git a/crates/ra_ide_api_light/src/structure.rs b/crates/ra_ide_api_light/src/structure.rs index 4e080ed03d8..330a3694cda 100644 --- a/crates/ra_ide_api_light/src/structure.rs +++ b/crates/ra_ide_api_light/src/structure.rs @@ -2,7 +2,7 @@ use crate::TextRange; use ra_syntax::{ algo::visit::{visitor, Visitor}, - ast::{self, NameOwner, TypeParamsOwner}, + ast::{self, AttrsOwner, NameOwner, TypeParamsOwner}, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, }; @@ -14,6 +14,7 @@ pub struct StructureNode { pub node_range: TextRange, pub kind: SyntaxKind, pub detail: Option, + pub deprecated: bool, } pub fn file_structure(file: &SourceFile) -> Vec { @@ -40,11 +41,11 @@ pub fn file_structure(file: &SourceFile) -> Vec { } fn structure_node(node: &SyntaxNode) -> Option { - fn decl(node: &N) -> Option { + fn decl(node: &N) -> Option { decl_with_detail(node, None) } - fn decl_with_type_ref( + fn decl_with_type_ref( node: &N, type_ref: Option<&ast::TypeRef>, ) -> Option { @@ -56,8 +57,12 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_detail(node, detail) } - fn decl_with_detail(node: &N, detail: Option) -> Option { + fn decl_with_detail( + node: &N, + detail: Option, + ) -> Option { let name = node.name()?; + Some(StructureNode { parent: None, label: name.text().to_string(), @@ -65,6 +70,10 @@ fn structure_node(node: &SyntaxNode) -> Option { node_range: node.syntax().range(), kind: node.syntax().kind(), detail, + deprecated: node + .attrs() + .filter_map(|x| x.as_named()) + .any(|x| x == "deprecated"), }) } @@ -128,6 +137,7 @@ fn structure_node(node: &SyntaxNode) -> Option { node_range: im.syntax().range(), kind: im.syntax().kind(), detail: None, + deprecated: false, }; Some(node) }) @@ -165,6 +175,12 @@ const C: i32 = 92; impl E {} impl fmt::Debug for E {} + +#[deprecated] +fn obsolete() {} + +#[deprecated(note = "for awhile")] +fn very_obsolete() {} "#, ); let structure = file_structure(&file); diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 4720a884394..ab2b81bf042 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -140,7 +140,7 @@ pub fn handle_document_symbol( name: symbol.label, detail: symbol.detail, kind: symbol.kind.conv(), - deprecated: None, + deprecated: Some(symbol.deprecated), range: symbol.node_range.conv_with(&line_index), selection_range: symbol.navigation_range.conv_with(&line_index), children: None, diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 3d22a88f358..d6237532b05 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -177,6 +177,16 @@ impl Attr { None } } + + pub fn as_named(&self) -> Option { + let tt = self.value()?; + let attr = tt.syntax().children().nth(1)?; + if attr.kind() == IDENT { + Some(attr.leaf_text().unwrap().clone()) + } else { + None + } + } } impl Comment { diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index a8d60e882d7..60314d24527 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -755,6 +755,7 @@ impl ToOwned for EnumVariant { impl ast::NameOwner for EnumVariant {} impl ast::DocCommentsOwner for EnumVariant {} +impl ast::AttrsOwner for EnumVariant {} impl EnumVariant { pub fn expr(&self) -> Option<&Expr> { super::child_opt(self) diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 2ed1fd1b886..046db588550 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -281,7 +281,7 @@ Grammar( "DocCommentsOwner" ], options: [["variant_list", "EnumVariantList"]] ), "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ), - "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner"], options: ["Expr"] ), + "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ), "TraitDef": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner"] ), "Module": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ],