diff options
Diffstat (limited to 'crates/ra_ide_api/src/display')
-rw-r--r-- | crates/ra_ide_api/src/display/function_signature.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 61 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/short_label.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/structure.rs | 120 |
4 files changed, 100 insertions, 85 deletions
diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs index 644a4532b..43f022ccd 100644 --- a/crates/ra_ide_api/src/display/function_signature.rs +++ b/crates/ra_ide_api/src/display/function_signature.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
1 | use std::fmt::{self, Display}; | 3 | use std::fmt::{self, Display}; |
2 | 4 | ||
3 | use hir::{Docs, Documentation, HasSource}; | 5 | use hir::{Docs, Documentation, HasSource}; |
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index d3e774bd0..d0b1a8a2a 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -1,9 +1,10 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
1 | use hir::{AssocItem, FieldSource, HasSource, ModuleSource}; | 3 | use hir::{AssocItem, FieldSource, HasSource, ModuleSource}; |
2 | use ra_db::{FileId, SourceDatabase}; | 4 | use ra_db::{FileId, SourceDatabase}; |
3 | use ra_syntax::{ | 5 | use ra_syntax::{ |
4 | algo::visit::{visitor, Visitor}, | ||
5 | ast::{self, DocCommentsOwner}, | 6 | ast::{self, DocCommentsOwner}, |
6 | AstNode, AstPtr, SmolStr, | 7 | match_ast, AstNode, AstPtr, SmolStr, |
7 | SyntaxKind::{self, NAME}, | 8 | SyntaxKind::{self, NAME}, |
8 | SyntaxNode, TextRange, | 9 | SyntaxNode, TextRange, |
9 | }; | 10 | }; |
@@ -306,19 +307,22 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option | |||
306 | let parse = db.parse(symbol.file_id); | 307 | let parse = db.parse(symbol.file_id); |
307 | let node = symbol.ptr.to_node(parse.tree().syntax()); | 308 | let node = symbol.ptr.to_node(parse.tree().syntax()); |
308 | 309 | ||
309 | visitor() | 310 | match_ast! { |
310 | .visit(|it: ast::FnDef| it.doc_comment_text()) | 311 | match node { |
311 | .visit(|it: ast::StructDef| it.doc_comment_text()) | 312 | ast::FnDef(it) => { it.doc_comment_text() }, |
312 | .visit(|it: ast::EnumDef| it.doc_comment_text()) | 313 | ast::StructDef(it) => { it.doc_comment_text() }, |
313 | .visit(|it: ast::TraitDef| it.doc_comment_text()) | 314 | ast::EnumDef(it) => { it.doc_comment_text() }, |
314 | .visit(|it: ast::Module| it.doc_comment_text()) | 315 | ast::TraitDef(it) => { it.doc_comment_text() }, |
315 | .visit(|it: ast::TypeAliasDef| it.doc_comment_text()) | 316 | ast::Module(it) => { it.doc_comment_text() }, |
316 | .visit(|it: ast::ConstDef| it.doc_comment_text()) | 317 | ast::TypeAliasDef(it) => { it.doc_comment_text() }, |
317 | .visit(|it: ast::StaticDef| it.doc_comment_text()) | 318 | ast::ConstDef(it) => { it.doc_comment_text() }, |
318 | .visit(|it: ast::RecordFieldDef| it.doc_comment_text()) | 319 | ast::StaticDef(it) => { it.doc_comment_text() }, |
319 | .visit(|it: ast::EnumVariant| it.doc_comment_text()) | 320 | ast::RecordFieldDef(it) => { it.doc_comment_text() }, |
320 | .visit(|it: ast::MacroCall| it.doc_comment_text()) | 321 | ast::EnumVariant(it) => { it.doc_comment_text() }, |
321 | .accept(&node)? | 322 | ast::MacroCall(it) => { it.doc_comment_text() }, |
323 | _ => None, | ||
324 | } | ||
325 | } | ||
322 | } | 326 | } |
323 | 327 | ||
324 | /// Get a description of a symbol. | 328 | /// Get a description of a symbol. |
@@ -328,16 +332,19 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> | |||
328 | let parse = db.parse(symbol.file_id); | 332 | let parse = db.parse(symbol.file_id); |
329 | let node = symbol.ptr.to_node(parse.tree().syntax()); | 333 | let node = symbol.ptr.to_node(parse.tree().syntax()); |
330 | 334 | ||
331 | visitor() | 335 | match_ast! { |
332 | .visit(|node: ast::FnDef| node.short_label()) | 336 | match node { |
333 | .visit(|node: ast::StructDef| node.short_label()) | 337 | ast::FnDef(it) => { it.short_label() }, |
334 | .visit(|node: ast::EnumDef| node.short_label()) | 338 | ast::StructDef(it) => { it.short_label() }, |
335 | .visit(|node: ast::TraitDef| node.short_label()) | 339 | ast::EnumDef(it) => { it.short_label() }, |
336 | .visit(|node: ast::Module| node.short_label()) | 340 | ast::TraitDef(it) => { it.short_label() }, |
337 | .visit(|node: ast::TypeAliasDef| node.short_label()) | 341 | ast::Module(it) => { it.short_label() }, |
338 | .visit(|node: ast::ConstDef| node.short_label()) | 342 | ast::TypeAliasDef(it) => { it.short_label() }, |
339 | .visit(|node: ast::StaticDef| node.short_label()) | 343 | ast::ConstDef(it) => { it.short_label() }, |
340 | .visit(|node: ast::RecordFieldDef| node.short_label()) | 344 | ast::StaticDef(it) => { it.short_label() }, |
341 | .visit(|node: ast::EnumVariant| node.short_label()) | 345 | ast::RecordFieldDef(it) => { it.short_label() }, |
342 | .accept(&node)? | 346 | ast::EnumVariant(it) => { it.short_label() }, |
347 | _ => None, | ||
348 | } | ||
349 | } | ||
343 | } | 350 | } |
diff --git a/crates/ra_ide_api/src/display/short_label.rs b/crates/ra_ide_api/src/display/short_label.rs index b16d504e1..5d2bce3d2 100644 --- a/crates/ra_ide_api/src/display/short_label.rs +++ b/crates/ra_ide_api/src/display/short_label.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
1 | use format_buf::format; | 3 | use format_buf::format; |
2 | use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; | 4 | use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; |
3 | 5 | ||
diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs index be042ed17..ddd8b7b20 100644 --- a/crates/ra_ide_api/src/display/structure.rs +++ b/crates/ra_ide_api/src/display/structure.rs | |||
@@ -1,9 +1,10 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
1 | use crate::TextRange; | 3 | use crate::TextRange; |
2 | 4 | ||
3 | use ra_syntax::{ | 5 | use ra_syntax::{ |
4 | algo::visit::{visitor, Visitor}, | ||
5 | ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, | 6 | ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, |
6 | AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, | 7 | match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, |
7 | }; | 8 | }; |
8 | 9 | ||
9 | #[derive(Debug, Clone)] | 10 | #[derive(Debug, Clone)] |
@@ -77,7 +78,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
77 | node_range: node.syntax().text_range(), | 78 | node_range: node.syntax().text_range(), |
78 | kind: node.syntax().kind(), | 79 | kind: node.syntax().kind(), |
79 | detail, | 80 | detail, |
80 | deprecated: node.attrs().filter_map(|x| x.as_named()).any(|x| x == "deprecated"), | 81 | deprecated: node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated"), |
81 | }) | 82 | }) |
82 | } | 83 | } |
83 | 84 | ||
@@ -99,63 +100,66 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
99 | }) | 100 | }) |
100 | } | 101 | } |
101 | 102 | ||
102 | visitor() | 103 | match_ast! { |
103 | .visit(|fn_def: ast::FnDef| { | 104 | match node { |
104 | let mut detail = String::from("fn"); | 105 | ast::FnDef(it) => { |
105 | if let Some(type_param_list) = fn_def.type_param_list() { | 106 | let mut detail = String::from("fn"); |
106 | collapse_ws(type_param_list.syntax(), &mut detail); | 107 | if let Some(type_param_list) = it.type_param_list() { |
107 | } | 108 | collapse_ws(type_param_list.syntax(), &mut detail); |
108 | if let Some(param_list) = fn_def.param_list() { | 109 | } |
109 | collapse_ws(param_list.syntax(), &mut detail); | 110 | if let Some(param_list) = it.param_list() { |
110 | } | 111 | collapse_ws(param_list.syntax(), &mut detail); |
111 | if let Some(ret_type) = fn_def.ret_type() { | 112 | } |
112 | detail.push_str(" "); | 113 | if let Some(ret_type) = it.ret_type() { |
113 | collapse_ws(ret_type.syntax(), &mut detail); | 114 | detail.push_str(" "); |
114 | } | 115 | collapse_ws(ret_type.syntax(), &mut detail); |
115 | |||
116 | decl_with_detail(fn_def, Some(detail)) | ||
117 | }) | ||
118 | .visit(decl::<ast::StructDef>) | ||
119 | .visit(decl::<ast::EnumDef>) | ||
120 | .visit(decl::<ast::EnumVariant>) | ||
121 | .visit(decl::<ast::TraitDef>) | ||
122 | .visit(decl::<ast::Module>) | ||
123 | .visit(|td: ast::TypeAliasDef| { | ||
124 | let ty = td.type_ref(); | ||
125 | decl_with_type_ref(td, ty) | ||
126 | }) | ||
127 | .visit(decl_with_ascription::<ast::RecordFieldDef>) | ||
128 | .visit(decl_with_ascription::<ast::ConstDef>) | ||
129 | .visit(decl_with_ascription::<ast::StaticDef>) | ||
130 | .visit(|im: ast::ImplBlock| { | ||
131 | let target_type = im.target_type()?; | ||
132 | let target_trait = im.target_trait(); | ||
133 | let label = match target_trait { | ||
134 | None => format!("impl {}", target_type.syntax().text()), | ||
135 | Some(t) => { | ||
136 | format!("impl {} for {}", t.syntax().text(), target_type.syntax().text(),) | ||
137 | } | 116 | } |
138 | }; | ||
139 | 117 | ||
140 | let node = StructureNode { | 118 | decl_with_detail(it, Some(detail)) |
141 | parent: None, | 119 | }, |
142 | label, | 120 | ast::StructDef(it) => { decl(it) }, |
143 | navigation_range: target_type.syntax().text_range(), | 121 | ast::EnumDef(it) => { decl(it) }, |
144 | node_range: im.syntax().text_range(), | 122 | ast::EnumVariant(it) => { decl(it) }, |
145 | kind: im.syntax().kind(), | 123 | ast::TraitDef(it) => { decl(it) }, |
146 | detail: None, | 124 | ast::Module(it) => { decl(it) }, |
147 | deprecated: false, | 125 | ast::TypeAliasDef(it) => { |
148 | }; | 126 | let ty = it.type_ref(); |
149 | Some(node) | 127 | decl_with_type_ref(it, ty) |
150 | }) | 128 | }, |
151 | .visit(|mc: ast::MacroCall| { | 129 | ast::RecordFieldDef(it) => { decl_with_ascription(it) }, |
152 | let first_token = mc.syntax().first_token().unwrap(); | 130 | ast::ConstDef(it) => { decl_with_ascription(it) }, |
153 | if first_token.text().as_str() != "macro_rules" { | 131 | ast::StaticDef(it) => { decl_with_ascription(it) }, |
154 | return None; | 132 | ast::ImplBlock(it) => { |
155 | } | 133 | let target_type = it.target_type()?; |
156 | decl(mc) | 134 | let target_trait = it.target_trait(); |
157 | }) | 135 | let label = match target_trait { |
158 | .accept(&node)? | 136 | None => format!("impl {}", target_type.syntax().text()), |
137 | Some(t) => { | ||
138 | format!("impl {} for {}", t.syntax().text(), target_type.syntax().text(),) | ||
139 | } | ||
140 | }; | ||
141 | |||
142 | let node = StructureNode { | ||
143 | parent: None, | ||
144 | label, | ||
145 | navigation_range: target_type.syntax().text_range(), | ||
146 | node_range: it.syntax().text_range(), | ||
147 | kind: it.syntax().kind(), | ||
148 | detail: None, | ||
149 | deprecated: false, | ||
150 | }; | ||
151 | Some(node) | ||
152 | }, | ||
153 | ast::MacroCall(it) => { | ||
154 | let first_token = it.syntax().first_token().unwrap(); | ||
155 | if first_token.text().as_str() != "macro_rules" { | ||
156 | return None; | ||
157 | } | ||
158 | decl(it) | ||
159 | }, | ||
160 | _ => None, | ||
161 | } | ||
162 | } | ||
159 | } | 163 | } |
160 | 164 | ||
161 | #[cfg(test)] | 165 | #[cfg(test)] |