aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorJeremy Kolb <[email protected]>2019-01-14 01:08:33 +0000
committerJeremy Kolb <[email protected]>2019-01-14 01:08:33 +0000
commit2d7b4cc548a5b72c8b268a774444a59dd1ce669e (patch)
tree7ada3ac191c2f3f17e2f62ebf34cb9cdd8ee0e71 /crates/ra_ide_api
parenta901cb4f342b0a784e716e29934999cc036dc835 (diff)
Add visibility to hover
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/hover.rs50
1 files changed, 41 insertions, 9 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index c445d4fa1..4dafefa2c 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,7 +1,7 @@
1use ra_db::{Cancelable, SyntaxDatabase}; 1use ra_db::{Cancelable, SyntaxDatabase};
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, SyntaxNode, TreeArc, 3 AstNode, SyntaxNode, TreeArc,
4 ast::{self, NameOwner}, 4 ast::{self, NameOwner, VisibilityOwner},
5 algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, 5 algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}},
6}; 6};
7 7
@@ -140,42 +140,74 @@ impl NavigationTarget {
140 // TODO: Refactor to be have less repetition 140 // TODO: Refactor to be have less repetition
141 visitor() 141 visitor()
142 .visit(|node: &ast::FnDef| { 142 .visit(|node: &ast::FnDef| {
143 let mut string = "fn ".to_string(); 143 let mut string = node
144 .visibility()
145 .map(|v| format!("{} ", v.syntax().text()))
146 .unwrap_or_default();
147 string.push_str("fn ");
144 node.name()?.syntax().text().push_to(&mut string); 148 node.name()?.syntax().text().push_to(&mut string);
145 Some(string) 149 Some(string)
146 }) 150 })
147 .visit(|node: &ast::StructDef| { 151 .visit(|node: &ast::StructDef| {
148 let mut string = "struct ".to_string(); 152 let mut string = node
153 .visibility()
154 .map(|v| format!("{} ", v.syntax().text()))
155 .unwrap_or_default();
156 string.push_str("struct ");
149 node.name()?.syntax().text().push_to(&mut string); 157 node.name()?.syntax().text().push_to(&mut string);
150 Some(string) 158 Some(string)
151 }) 159 })
152 .visit(|node: &ast::EnumDef| { 160 .visit(|node: &ast::EnumDef| {
153 let mut string = "enum ".to_string(); 161 let mut string = node
162 .visibility()
163 .map(|v| format!("{} ", v.syntax().text()))
164 .unwrap_or_default();
165 string.push_str("enum ");
154 node.name()?.syntax().text().push_to(&mut string); 166 node.name()?.syntax().text().push_to(&mut string);
155 Some(string) 167 Some(string)
156 }) 168 })
157 .visit(|node: &ast::TraitDef| { 169 .visit(|node: &ast::TraitDef| {
158 let mut string = "trait ".to_string(); 170 let mut string = node
171 .visibility()
172 .map(|v| format!("{} ", v.syntax().text()))
173 .unwrap_or_default();
174 string.push_str("trait ");
159 node.name()?.syntax().text().push_to(&mut string); 175 node.name()?.syntax().text().push_to(&mut string);
160 Some(string) 176 Some(string)
161 }) 177 })
162 .visit(|node: &ast::Module| { 178 .visit(|node: &ast::Module| {
163 let mut string = "mod ".to_string(); 179 let mut string = node
180 .visibility()
181 .map(|v| format!("{} ", v.syntax().text()))
182 .unwrap_or_default();
183 string.push_str("mod ");
164 node.name()?.syntax().text().push_to(&mut string); 184 node.name()?.syntax().text().push_to(&mut string);
165 Some(string) 185 Some(string)
166 }) 186 })
167 .visit(|node: &ast::TypeDef| { 187 .visit(|node: &ast::TypeDef| {
168 let mut string = "type ".to_string(); 188 let mut string = node
189 .visibility()
190 .map(|v| format!("{} ", v.syntax().text()))
191 .unwrap_or_default();
192 string.push_str("type ");
169 node.name()?.syntax().text().push_to(&mut string); 193 node.name()?.syntax().text().push_to(&mut string);
170 Some(string) 194 Some(string)
171 }) 195 })
172 .visit(|node: &ast::ConstDef| { 196 .visit(|node: &ast::ConstDef| {
173 let mut string = "const ".to_string(); 197 let mut string = node
198 .visibility()
199 .map(|v| format!("{} ", v.syntax().text()))
200 .unwrap_or_default();
201 string.push_str("const ");
174 node.name()?.syntax().text().push_to(&mut string); 202 node.name()?.syntax().text().push_to(&mut string);
175 Some(string) 203 Some(string)
176 }) 204 })
177 .visit(|node: &ast::StaticDef| { 205 .visit(|node: &ast::StaticDef| {
178 let mut string = "static ".to_string(); 206 let mut string = node
207 .visibility()
208 .map(|v| format!("{} ", v.syntax().text()))
209 .unwrap_or_default();
210 string.push_str("static ");
179 node.name()?.syntax().text().push_to(&mut string); 211 node.name()?.syntax().text().push_to(&mut string);
180 Some(string) 212 Some(string)
181 }) 213 })