diff options
Diffstat (limited to 'crates/ra_analysis/src/hover.rs')
-rw-r--r-- | crates/ra_analysis/src/hover.rs | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs index 06632df4f..5607c3ef3 100644 --- a/crates/ra_analysis/src/hover.rs +++ b/crates/ra_analysis/src/hover.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use ra_db::{Cancelable, SyntaxDatabase}; | 1 | use ra_db::{Cancelable, SyntaxDatabase}; |
2 | use ra_editor::find_node_at_offset; | 2 | use ra_editor::find_node_at_offset; |
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | AstNode, SyntaxNode, | 4 | AstNode, SyntaxNode, TreePtr, |
5 | ast::{self, NameOwner}, | 5 | ast::{self, NameOwner}, |
6 | algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}}, | 6 | algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}}, |
7 | }; | 7 | }; |
@@ -88,20 +88,19 @@ fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Cancelable<Option<S | |||
88 | } | 88 | } |
89 | 89 | ||
90 | impl NavigationTarget { | 90 | impl NavigationTarget { |
91 | fn node(&self, db: &RootDatabase) -> Option<SyntaxNode> { | 91 | fn node(&self, db: &RootDatabase) -> Option<TreePtr<SyntaxNode>> { |
92 | let source_file = db.source_file(self.file_id); | 92 | let source_file = db.source_file(self.file_id); |
93 | let source_file = source_file.syntax(); | 93 | let source_file = source_file.syntax(); |
94 | let node = source_file | 94 | let node = source_file |
95 | .descendants() | 95 | .descendants() |
96 | .find(|node| node.kind() == self.kind && node.range() == self.range)? | 96 | .find(|node| node.kind() == self.kind && node.range() == self.range)? |
97 | .owned(); | 97 | .to_owned(); |
98 | Some(node) | 98 | Some(node) |
99 | } | 99 | } |
100 | 100 | ||
101 | fn docs(&self, db: &RootDatabase) -> Option<String> { | 101 | fn docs(&self, db: &RootDatabase) -> Option<String> { |
102 | let node = self.node(db)?; | 102 | let node = self.node(db)?; |
103 | let node = node.borrowed(); | 103 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { |
104 | fn doc_comments<'a, N: ast::DocCommentsOwner<'a>>(node: N) -> Option<String> { | ||
105 | let comments = node.doc_comment_text(); | 104 | let comments = node.doc_comment_text(); |
106 | if comments.is_empty() { | 105 | if comments.is_empty() { |
107 | None | 106 | None |
@@ -119,7 +118,7 @@ impl NavigationTarget { | |||
119 | .visit(doc_comments::<ast::TypeDef>) | 118 | .visit(doc_comments::<ast::TypeDef>) |
120 | .visit(doc_comments::<ast::ConstDef>) | 119 | .visit(doc_comments::<ast::ConstDef>) |
121 | .visit(doc_comments::<ast::StaticDef>) | 120 | .visit(doc_comments::<ast::StaticDef>) |
122 | .accept(node)? | 121 | .accept(&node)? |
123 | } | 122 | } |
124 | 123 | ||
125 | /// Get a description of this node. | 124 | /// Get a description of this node. |
@@ -128,50 +127,49 @@ impl NavigationTarget { | |||
128 | fn description(&self, db: &RootDatabase) -> Option<String> { | 127 | fn description(&self, db: &RootDatabase) -> Option<String> { |
129 | // TODO: After type inference is done, add type information to improve the output | 128 | // TODO: After type inference is done, add type information to improve the output |
130 | let node = self.node(db)?; | 129 | let node = self.node(db)?; |
131 | let node = node.borrowed(); | ||
132 | // TODO: Refactor to be have less repetition | 130 | // TODO: Refactor to be have less repetition |
133 | visitor() | 131 | visitor() |
134 | .visit(|node: ast::FnDef| { | 132 | .visit(|node: &ast::FnDef| { |
135 | let mut string = "fn ".to_string(); | 133 | let mut string = "fn ".to_string(); |
136 | node.name()?.syntax().text().push_to(&mut string); | 134 | node.name()?.syntax().text().push_to(&mut string); |
137 | Some(string) | 135 | Some(string) |
138 | }) | 136 | }) |
139 | .visit(|node: ast::StructDef| { | 137 | .visit(|node: &ast::StructDef| { |
140 | let mut string = "struct ".to_string(); | 138 | let mut string = "struct ".to_string(); |
141 | node.name()?.syntax().text().push_to(&mut string); | 139 | node.name()?.syntax().text().push_to(&mut string); |
142 | Some(string) | 140 | Some(string) |
143 | }) | 141 | }) |
144 | .visit(|node: ast::EnumDef| { | 142 | .visit(|node: &ast::EnumDef| { |
145 | let mut string = "enum ".to_string(); | 143 | let mut string = "enum ".to_string(); |
146 | node.name()?.syntax().text().push_to(&mut string); | 144 | node.name()?.syntax().text().push_to(&mut string); |
147 | Some(string) | 145 | Some(string) |
148 | }) | 146 | }) |
149 | .visit(|node: ast::TraitDef| { | 147 | .visit(|node: &ast::TraitDef| { |
150 | let mut string = "trait ".to_string(); | 148 | let mut string = "trait ".to_string(); |
151 | node.name()?.syntax().text().push_to(&mut string); | 149 | node.name()?.syntax().text().push_to(&mut string); |
152 | Some(string) | 150 | Some(string) |
153 | }) | 151 | }) |
154 | .visit(|node: ast::Module| { | 152 | .visit(|node: &ast::Module| { |
155 | let mut string = "mod ".to_string(); | 153 | let mut string = "mod ".to_string(); |
156 | node.name()?.syntax().text().push_to(&mut string); | 154 | node.name()?.syntax().text().push_to(&mut string); |
157 | Some(string) | 155 | Some(string) |
158 | }) | 156 | }) |
159 | .visit(|node: ast::TypeDef| { | 157 | .visit(|node: &ast::TypeDef| { |
160 | let mut string = "type ".to_string(); | 158 | let mut string = "type ".to_string(); |
161 | node.name()?.syntax().text().push_to(&mut string); | 159 | node.name()?.syntax().text().push_to(&mut string); |
162 | Some(string) | 160 | Some(string) |
163 | }) | 161 | }) |
164 | .visit(|node: ast::ConstDef| { | 162 | .visit(|node: &ast::ConstDef| { |
165 | let mut string = "const ".to_string(); | 163 | let mut string = "const ".to_string(); |
166 | node.name()?.syntax().text().push_to(&mut string); | 164 | node.name()?.syntax().text().push_to(&mut string); |
167 | Some(string) | 165 | Some(string) |
168 | }) | 166 | }) |
169 | .visit(|node: ast::StaticDef| { | 167 | .visit(|node: &ast::StaticDef| { |
170 | let mut string = "static ".to_string(); | 168 | let mut string = "static ".to_string(); |
171 | node.name()?.syntax().text().push_to(&mut string); | 169 | node.name()?.syntax().text().push_to(&mut string); |
172 | Some(string) | 170 | Some(string) |
173 | }) | 171 | }) |
174 | .accept(node)? | 172 | .accept(&node)? |
175 | } | 173 | } |
176 | } | 174 | } |
177 | 175 | ||