diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-18 11:37:46 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-18 11:37:46 +0000 |
commit | 32e72ecd66fede0b39e8f34ca3e1b92128e1d91a (patch) | |
tree | acc9507f5910be3b2f722a28b6dccac795bca53e /crates/ra_ide_api | |
parent | 91509073c54a6f815a443f70fd8f9e505b750177 (diff) | |
parent | 5e8c22dbf35e815af148fbdd8dd6da4b50f7aea7 (diff) |
Merge #2299
2299: More sources r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 40 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 33 |
2 files changed, 32 insertions, 41 deletions
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 291b5ee40..b30ef8e05 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -6,7 +6,7 @@ use ra_syntax::{ | |||
6 | ast::{self, DocCommentsOwner, NameOwner}, | 6 | ast::{self, DocCommentsOwner, NameOwner}, |
7 | match_ast, AstNode, SmolStr, | 7 | match_ast, AstNode, SmolStr, |
8 | SyntaxKind::{self, BIND_PAT}, | 8 | SyntaxKind::{self, BIND_PAT}, |
9 | SyntaxNode, TextRange, | 9 | TextRange, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{db::RootDatabase, expand::original_range, FileSymbol}; | 12 | use crate::{db::RootDatabase, expand::original_range, FileSymbol}; |
@@ -86,7 +86,7 @@ impl NavigationTarget { | |||
86 | name, | 86 | name, |
87 | None, | 87 | None, |
88 | frange.range, | 88 | frange.range, |
89 | src.ast.syntax(), | 89 | src.ast.syntax().kind(), |
90 | src.ast.doc_comment_text(), | 90 | src.ast.doc_comment_text(), |
91 | src.ast.short_label(), | 91 | src.ast.short_label(), |
92 | ); | 92 | ); |
@@ -141,23 +141,22 @@ impl NavigationTarget { | |||
141 | /// Allows `NavigationTarget` to be created from a `NameOwner` | 141 | /// Allows `NavigationTarget` to be created from a `NameOwner` |
142 | pub(crate) fn from_named( | 142 | pub(crate) fn from_named( |
143 | db: &RootDatabase, | 143 | db: &RootDatabase, |
144 | file_id: hir::HirFileId, | 144 | node: Source<&dyn ast::NameOwner>, |
145 | node: &impl ast::NameOwner, | ||
146 | docs: Option<String>, | 145 | docs: Option<String>, |
147 | description: Option<String>, | 146 | description: Option<String>, |
148 | ) -> NavigationTarget { | 147 | ) -> NavigationTarget { |
149 | //FIXME: use `_` instead of empty string | 148 | //FIXME: use `_` instead of empty string |
150 | let name = node.name().map(|it| it.text().clone()).unwrap_or_default(); | 149 | let name = node.ast.name().map(|it| it.text().clone()).unwrap_or_default(); |
151 | let focus_range = | 150 | let focus_range = |
152 | node.name().map(|it| original_range(db, Source::new(file_id, it.syntax())).range); | 151 | node.ast.name().map(|it| original_range(db, node.with_ast(it.syntax())).range); |
153 | let frange = original_range(db, Source::new(file_id, node.syntax())); | 152 | let frange = original_range(db, node.map(|it| it.syntax())); |
154 | 153 | ||
155 | NavigationTarget::from_syntax( | 154 | NavigationTarget::from_syntax( |
156 | frange.file_id, | 155 | frange.file_id, |
157 | name, | 156 | name, |
158 | focus_range, | 157 | focus_range, |
159 | frange.range, | 158 | frange.range, |
160 | node.syntax(), | 159 | node.ast.syntax().kind(), |
161 | docs, | 160 | docs, |
162 | description, | 161 | description, |
163 | ) | 162 | ) |
@@ -168,14 +167,14 @@ impl NavigationTarget { | |||
168 | name: SmolStr, | 167 | name: SmolStr, |
169 | focus_range: Option<TextRange>, | 168 | focus_range: Option<TextRange>, |
170 | full_range: TextRange, | 169 | full_range: TextRange, |
171 | node: &SyntaxNode, | 170 | kind: SyntaxKind, |
172 | docs: Option<String>, | 171 | docs: Option<String>, |
173 | description: Option<String>, | 172 | description: Option<String>, |
174 | ) -> NavigationTarget { | 173 | ) -> NavigationTarget { |
175 | NavigationTarget { | 174 | NavigationTarget { |
176 | file_id, | 175 | file_id, |
177 | name, | 176 | name, |
178 | kind: node.kind(), | 177 | kind, |
179 | full_range, | 178 | full_range, |
180 | focus_range, | 179 | focus_range, |
181 | container_name: None, | 180 | container_name: None, |
@@ -220,8 +219,7 @@ where | |||
220 | let src = self.source(db); | 219 | let src = self.source(db); |
221 | NavigationTarget::from_named( | 220 | NavigationTarget::from_named( |
222 | db, | 221 | db, |
223 | src.file_id, | 222 | src.as_ref().map(|it| it as &dyn ast::NameOwner), |
224 | &src.ast, | ||
225 | src.ast.doc_comment_text(), | 223 | src.ast.doc_comment_text(), |
226 | src.ast.short_label(), | 224 | src.ast.short_label(), |
227 | ) | 225 | ) |
@@ -241,7 +239,7 @@ impl ToNav for hir::Module { | |||
241 | name, | 239 | name, |
242 | None, | 240 | None, |
243 | frange.range, | 241 | frange.range, |
244 | node.syntax(), | 242 | node.syntax().kind(), |
245 | None, | 243 | None, |
246 | None, | 244 | None, |
247 | ) | 245 | ) |
@@ -254,7 +252,7 @@ impl ToNav for hir::Module { | |||
254 | name, | 252 | name, |
255 | None, | 253 | None, |
256 | frange.range, | 254 | frange.range, |
257 | node.syntax(), | 255 | node.syntax().kind(), |
258 | node.doc_comment_text(), | 256 | node.doc_comment_text(), |
259 | node.short_label(), | 257 | node.short_label(), |
260 | ) | 258 | ) |
@@ -273,7 +271,7 @@ impl ToNav for hir::ImplBlock { | |||
273 | "impl".into(), | 271 | "impl".into(), |
274 | None, | 272 | None, |
275 | frange.range, | 273 | frange.range, |
276 | src.ast.syntax(), | 274 | src.ast.syntax().kind(), |
277 | None, | 275 | None, |
278 | None, | 276 | None, |
279 | ) | 277 | ) |
@@ -287,8 +285,7 @@ impl ToNav for hir::StructField { | |||
287 | match &src.ast { | 285 | match &src.ast { |
288 | FieldSource::Named(it) => NavigationTarget::from_named( | 286 | FieldSource::Named(it) => NavigationTarget::from_named( |
289 | db, | 287 | db, |
290 | src.file_id, | 288 | src.with_ast(it), |
291 | it, | ||
292 | it.doc_comment_text(), | 289 | it.doc_comment_text(), |
293 | it.short_label(), | 290 | it.short_label(), |
294 | ), | 291 | ), |
@@ -299,7 +296,7 @@ impl ToNav for hir::StructField { | |||
299 | "".into(), | 296 | "".into(), |
300 | None, | 297 | None, |
301 | frange.range, | 298 | frange.range, |
302 | it.syntax(), | 299 | it.syntax().kind(), |
303 | None, | 300 | None, |
304 | None, | 301 | None, |
305 | ) | 302 | ) |
@@ -312,7 +309,12 @@ impl ToNav for hir::MacroDef { | |||
312 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 309 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
313 | let src = self.source(db); | 310 | let src = self.source(db); |
314 | log::debug!("nav target {:#?}", src.ast.syntax()); | 311 | log::debug!("nav target {:#?}", src.ast.syntax()); |
315 | NavigationTarget::from_named(db, src.file_id, &src.ast, src.ast.doc_comment_text(), None) | 312 | NavigationTarget::from_named( |
313 | db, | ||
314 | src.as_ref().map(|it| it as &dyn ast::NameOwner), | ||
315 | src.ast.doc_comment_text(), | ||
316 | None, | ||
317 | ) | ||
316 | } | 318 | } |
317 | } | 319 | } |
318 | 320 | ||
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 1a8db0ea0..3f16e9566 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -120,8 +120,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
120 | ast::StructDef(it) => { | 120 | ast::StructDef(it) => { |
121 | Some(NavigationTarget::from_named( | 121 | Some(NavigationTarget::from_named( |
122 | db, | 122 | db, |
123 | node.file_id, | 123 | node.with_ast(&it), |
124 | &it, | ||
125 | it.doc_comment_text(), | 124 | it.doc_comment_text(), |
126 | it.short_label(), | 125 | it.short_label(), |
127 | )) | 126 | )) |
@@ -129,8 +128,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
129 | ast::EnumDef(it) => { | 128 | ast::EnumDef(it) => { |
130 | Some(NavigationTarget::from_named( | 129 | Some(NavigationTarget::from_named( |
131 | db, | 130 | db, |
132 | node.file_id, | 131 | node.with_ast(&it), |
133 | &it, | ||
134 | it.doc_comment_text(), | 132 | it.doc_comment_text(), |
135 | it.short_label(), | 133 | it.short_label(), |
136 | )) | 134 | )) |
@@ -138,8 +136,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
138 | ast::EnumVariant(it) => { | 136 | ast::EnumVariant(it) => { |
139 | Some(NavigationTarget::from_named( | 137 | Some(NavigationTarget::from_named( |
140 | db, | 138 | db, |
141 | node.file_id, | 139 | node.with_ast(&it), |
142 | &it, | ||
143 | it.doc_comment_text(), | 140 | it.doc_comment_text(), |
144 | it.short_label(), | 141 | it.short_label(), |
145 | )) | 142 | )) |
@@ -147,8 +144,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
147 | ast::FnDef(it) => { | 144 | ast::FnDef(it) => { |
148 | Some(NavigationTarget::from_named( | 145 | Some(NavigationTarget::from_named( |
149 | db, | 146 | db, |
150 | node.file_id, | 147 | node.with_ast(&it), |
151 | &it, | ||
152 | it.doc_comment_text(), | 148 | it.doc_comment_text(), |
153 | it.short_label(), | 149 | it.short_label(), |
154 | )) | 150 | )) |
@@ -156,8 +152,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
156 | ast::TypeAliasDef(it) => { | 152 | ast::TypeAliasDef(it) => { |
157 | Some(NavigationTarget::from_named( | 153 | Some(NavigationTarget::from_named( |
158 | db, | 154 | db, |
159 | node.file_id, | 155 | node.with_ast(&it), |
160 | &it, | ||
161 | it.doc_comment_text(), | 156 | it.doc_comment_text(), |
162 | it.short_label(), | 157 | it.short_label(), |
163 | )) | 158 | )) |
@@ -165,8 +160,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
165 | ast::ConstDef(it) => { | 160 | ast::ConstDef(it) => { |
166 | Some(NavigationTarget::from_named( | 161 | Some(NavigationTarget::from_named( |
167 | db, | 162 | db, |
168 | node.file_id, | 163 | node.with_ast(&it), |
169 | &it, | ||
170 | it.doc_comment_text(), | 164 | it.doc_comment_text(), |
171 | it.short_label(), | 165 | it.short_label(), |
172 | )) | 166 | )) |
@@ -174,8 +168,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
174 | ast::StaticDef(it) => { | 168 | ast::StaticDef(it) => { |
175 | Some(NavigationTarget::from_named( | 169 | Some(NavigationTarget::from_named( |
176 | db, | 170 | db, |
177 | node.file_id, | 171 | node.with_ast(&it), |
178 | &it, | ||
179 | it.doc_comment_text(), | 172 | it.doc_comment_text(), |
180 | it.short_label(), | 173 | it.short_label(), |
181 | )) | 174 | )) |
@@ -183,8 +176,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
183 | ast::TraitDef(it) => { | 176 | ast::TraitDef(it) => { |
184 | Some(NavigationTarget::from_named( | 177 | Some(NavigationTarget::from_named( |
185 | db, | 178 | db, |
186 | node.file_id, | 179 | node.with_ast(&it), |
187 | &it, | ||
188 | it.doc_comment_text(), | 180 | it.doc_comment_text(), |
189 | it.short_label(), | 181 | it.short_label(), |
190 | )) | 182 | )) |
@@ -192,8 +184,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
192 | ast::RecordFieldDef(it) => { | 184 | ast::RecordFieldDef(it) => { |
193 | Some(NavigationTarget::from_named( | 185 | Some(NavigationTarget::from_named( |
194 | db, | 186 | db, |
195 | node.file_id, | 187 | node.with_ast(&it), |
196 | &it, | ||
197 | it.doc_comment_text(), | 188 | it.doc_comment_text(), |
198 | it.short_label(), | 189 | it.short_label(), |
199 | )) | 190 | )) |
@@ -201,8 +192,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
201 | ast::Module(it) => { | 192 | ast::Module(it) => { |
202 | Some(NavigationTarget::from_named( | 193 | Some(NavigationTarget::from_named( |
203 | db, | 194 | db, |
204 | node.file_id, | 195 | node.with_ast(&it), |
205 | &it, | ||
206 | it.doc_comment_text(), | 196 | it.doc_comment_text(), |
207 | it.short_label(), | 197 | it.short_label(), |
208 | )) | 198 | )) |
@@ -210,8 +200,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati | |||
210 | ast::MacroCall(it) => { | 200 | ast::MacroCall(it) => { |
211 | Some(NavigationTarget::from_named( | 201 | Some(NavigationTarget::from_named( |
212 | db, | 202 | db, |
213 | node.file_id, | 203 | node.with_ast(&it), |
214 | &it, | ||
215 | it.doc_comment_text(), | 204 | it.doc_comment_text(), |
216 | None, | 205 | None, |
217 | )) | 206 | )) |