From 852b08379473cc3ee06878c5aae809b63d76cbc3 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Tue, 5 Feb 2019 17:05:46 -0500 Subject: Fill deprecation for LSP --- .../src/snapshots/tests__file_structure.snap | 70 ++++++++++++++++------ crates/ra_ide_api_light/src/structure.rs | 24 ++++++-- 2 files changed, 73 insertions(+), 21 deletions(-) (limited to 'crates/ra_ide_api_light') 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 270f75a56..413f4a5ff 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 4e080ed03..dc3534498 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()?; + dbg!(name.text().to_string()); 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); -- cgit v1.2.3 From d107926f8621dfc08010ffc5bf4a1ac6356c6c87 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Wed, 6 Feb 2019 07:22:16 -0500 Subject: Remove stray dbg! --- crates/ra_ide_api_light/src/structure.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api_light') diff --git a/crates/ra_ide_api_light/src/structure.rs b/crates/ra_ide_api_light/src/structure.rs index dc3534498..330a3694c 100644 --- a/crates/ra_ide_api_light/src/structure.rs +++ b/crates/ra_ide_api_light/src/structure.rs @@ -62,7 +62,7 @@ fn structure_node(node: &SyntaxNode) -> Option { detail: Option, ) -> Option { let name = node.name()?; - dbg!(name.text().to_string()); + Some(StructureNode { parent: None, label: name.text().to_string(), -- cgit v1.2.3