diff options
author | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
commit | b21d9337d9200e2cfdc90b386591c72c302dc03e (patch) | |
tree | f81f5c08f821115cee26fa4d3ceaae88c7807fd5 /crates/ra_ide/src/display/navigation_target.rs | |
parent | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff) | |
parent | ce07a2daa9e53aa86a769f8641b14c2878444fbc (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'crates/ra_ide/src/display/navigation_target.rs')
-rw-r--r-- | crates/ra_ide/src/display/navigation_target.rs | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 6ac60722b..b9ae67828 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs | |||
@@ -1,11 +1,12 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource, Source}; | 3 | use either::Either; |
4 | use hir::{AssocItem, FieldSource, HasSource, InFile, ModuleSource}; | ||
4 | use ra_db::{FileId, SourceDatabase}; | 5 | use ra_db::{FileId, SourceDatabase}; |
5 | use ra_syntax::{ | 6 | use ra_syntax::{ |
6 | ast::{self, DocCommentsOwner, NameOwner}, | 7 | ast::{self, DocCommentsOwner, NameOwner}, |
7 | match_ast, AstNode, SmolStr, | 8 | match_ast, AstNode, SmolStr, |
8 | SyntaxKind::{self, BIND_PAT}, | 9 | SyntaxKind::{self, BIND_PAT, TYPE_PARAM}, |
9 | TextRange, | 10 | TextRange, |
10 | }; | 11 | }; |
11 | 12 | ||
@@ -141,7 +142,7 @@ impl NavigationTarget { | |||
141 | /// Allows `NavigationTarget` to be created from a `NameOwner` | 142 | /// Allows `NavigationTarget` to be created from a `NameOwner` |
142 | pub(crate) fn from_named( | 143 | pub(crate) fn from_named( |
143 | db: &RootDatabase, | 144 | db: &RootDatabase, |
144 | node: Source<&dyn ast::NameOwner>, | 145 | node: InFile<&dyn ast::NameOwner>, |
145 | docs: Option<String>, | 146 | docs: Option<String>, |
146 | description: Option<String>, | 147 | description: Option<String>, |
147 | ) -> NavigationTarget { | 148 | ) -> NavigationTarget { |
@@ -230,34 +231,20 @@ impl ToNav for hir::Module { | |||
230 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 231 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
231 | let src = self.definition_source(db); | 232 | let src = self.definition_source(db); |
232 | let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); | 233 | let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); |
233 | match &src.value { | 234 | let syntax = match &src.value { |
234 | ModuleSource::SourceFile(node) => { | 235 | ModuleSource::SourceFile(node) => node.syntax(), |
235 | let frange = original_range(db, src.with_value(node.syntax())); | 236 | ModuleSource::Module(node) => node.syntax(), |
236 | 237 | }; | |
237 | NavigationTarget::from_syntax( | 238 | let frange = original_range(db, src.with_value(syntax)); |
238 | frange.file_id, | 239 | NavigationTarget::from_syntax( |
239 | name, | 240 | frange.file_id, |
240 | None, | 241 | name, |
241 | frange.range, | 242 | None, |
242 | node.syntax().kind(), | 243 | frange.range, |
243 | None, | 244 | syntax.kind(), |
244 | None, | 245 | None, |
245 | ) | 246 | None, |
246 | } | 247 | ) |
247 | ModuleSource::Module(node) => { | ||
248 | let frange = original_range(db, src.with_value(node.syntax())); | ||
249 | |||
250 | NavigationTarget::from_syntax( | ||
251 | frange.file_id, | ||
252 | name, | ||
253 | None, | ||
254 | frange.range, | ||
255 | node.syntax().kind(), | ||
256 | node.doc_comment_text(), | ||
257 | node.short_label(), | ||
258 | ) | ||
259 | } | ||
260 | } | ||
261 | } | 248 | } |
262 | } | 249 | } |
263 | 250 | ||
@@ -341,22 +328,43 @@ impl ToNav for hir::AssocItem { | |||
341 | impl ToNav for hir::Local { | 328 | impl ToNav for hir::Local { |
342 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 329 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
343 | let src = self.source(db); | 330 | let src = self.source(db); |
344 | let (full_range, focus_range) = match src.value { | 331 | let node = match &src.value { |
345 | Either::A(it) => { | 332 | Either::Left(bind_pat) => { |
346 | (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range())) | 333 | bind_pat.name().map_or_else(|| bind_pat.syntax().clone(), |it| it.syntax().clone()) |
347 | } | 334 | } |
348 | Either::B(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())), | 335 | Either::Right(it) => it.syntax().clone(), |
349 | }; | 336 | }; |
337 | let full_range = original_range(db, src.with_value(&node)); | ||
350 | let name = match self.name(db) { | 338 | let name = match self.name(db) { |
351 | Some(it) => it.to_string().into(), | 339 | Some(it) => it.to_string().into(), |
352 | None => "".into(), | 340 | None => "".into(), |
353 | }; | 341 | }; |
354 | NavigationTarget { | 342 | NavigationTarget { |
355 | file_id: src.file_id.original_file(db), | 343 | file_id: full_range.file_id, |
356 | name, | 344 | name, |
357 | kind: BIND_PAT, | 345 | kind: BIND_PAT, |
358 | full_range, | 346 | full_range: full_range.range, |
359 | focus_range, | 347 | focus_range: None, |
348 | container_name: None, | ||
349 | description: None, | ||
350 | docs: None, | ||
351 | } | ||
352 | } | ||
353 | } | ||
354 | |||
355 | impl ToNav for hir::TypeParam { | ||
356 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | ||
357 | let src = self.source(db); | ||
358 | let range = match src.value { | ||
359 | Either::Left(it) => it.syntax().text_range(), | ||
360 | Either::Right(it) => it.syntax().text_range(), | ||
361 | }; | ||
362 | NavigationTarget { | ||
363 | file_id: src.file_id.original_file(db), | ||
364 | name: self.name(db).to_string().into(), | ||
365 | kind: TYPE_PARAM, | ||
366 | full_range: range, | ||
367 | focus_range: None, | ||
360 | container_name: None, | 368 | container_name: None, |
361 | description: None, | 369 | description: None, |
362 | docs: None, | 370 | docs: None, |