Fill deprecation for LSP

This commit is contained in:
kjeremy 2019-02-05 17:05:46 -05:00
parent 569e1e871e
commit 852b083794
6 changed files with 86 additions and 23 deletions

View file

@ -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) -> 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, B>(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
}
]

View file

@ -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<String>,
pub deprecated: bool,
}
pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> {
@ -40,11 +41,11 @@ pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> {
}
fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
fn decl<N: NameOwner>(node: &N) -> Option<StructureNode> {
fn decl<N: NameOwner + AttrsOwner>(node: &N) -> Option<StructureNode> {
decl_with_detail(node, None)
}
fn decl_with_type_ref<N: NameOwner>(
fn decl_with_type_ref<N: NameOwner + AttrsOwner>(
node: &N,
type_ref: Option<&ast::TypeRef>,
) -> Option<StructureNode> {
@ -56,8 +57,12 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
decl_with_detail(node, detail)
}
fn decl_with_detail<N: NameOwner>(node: &N, detail: Option<String>) -> Option<StructureNode> {
fn decl_with_detail<N: NameOwner + AttrsOwner>(
node: &N,
detail: Option<String>,
) -> Option<StructureNode> {
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<StructureNode> {
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<StructureNode> {
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);

View file

@ -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,

View file

@ -177,6 +177,16 @@ impl Attr {
None
}
}
pub fn as_named(&self) -> Option<SmolStr> {
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 {

View file

@ -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)

View file

@ -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" ],