diff options
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/hover.rs | 64 | ||||
-rw-r--r-- | crates/ide/src/lib.rs | 24 |
2 files changed, 59 insertions, 29 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index dc9621f46..1b6ff6d21 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use hir::{ | 1 | use hir::{ |
2 | Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, | 2 | Adt, AsAssocItem, AssocItemContainer, FieldSource, HasAttrs, HasSource, HirDisplay, Module, |
3 | Module, ModuleDef, ModuleSource, Semantics, | 3 | ModuleDef, ModuleSource, Semantics, |
4 | }; | 4 | }; |
5 | use ide_db::base_db::SourceDatabase; | 5 | use ide_db::base_db::SourceDatabase; |
6 | use ide_db::{ | 6 | use ide_db::{ |
@@ -319,31 +319,27 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> { | |||
319 | let mod_path = definition_mod_path(db, &def); | 319 | let mod_path = definition_mod_path(db, &def); |
320 | return match def { | 320 | return match def { |
321 | Definition::Macro(it) => { | 321 | Definition::Macro(it) => { |
322 | let src = it.source(db); | 322 | let label = macro_label(&it.source(db).value); |
323 | let docs = Documentation::from_ast(&src.value).map(Into::into); | 323 | from_def_source_labeled(db, it, Some(label), mod_path) |
324 | hover_markup(docs, Some(macro_label(&src.value)), mod_path) | ||
325 | } | 324 | } |
326 | Definition::Field(it) => { | 325 | Definition::Field(def) => { |
327 | let src = it.source(db); | 326 | let src = def.source(db).value; |
328 | match src.value { | 327 | if let FieldSource::Named(it) = src { |
329 | FieldSource::Named(it) => { | 328 | from_def_source_labeled(db, def, it.short_label(), mod_path) |
330 | let docs = Documentation::from_ast(&it).map(Into::into); | 329 | } else { |
331 | hover_markup(docs, it.short_label(), mod_path) | 330 | None |
332 | } | ||
333 | _ => None, | ||
334 | } | 331 | } |
335 | } | 332 | } |
336 | Definition::ModuleDef(it) => match it { | 333 | Definition::ModuleDef(it) => match it { |
337 | ModuleDef::Module(it) => match it.definition_source(db).value { | 334 | ModuleDef::Module(it) => from_def_source_labeled( |
338 | ModuleSource::Module(it) => { | 335 | db, |
339 | let docs = Documentation::from_ast(&it).map(Into::into); | 336 | it, |
340 | hover_markup(docs, it.short_label(), mod_path) | 337 | match it.definition_source(db).value { |
341 | } | 338 | ModuleSource::Module(it) => it.short_label(), |
342 | ModuleSource::SourceFile(it) => { | 339 | ModuleSource::SourceFile(it) => it.short_label(), |
343 | let docs = Documentation::from_ast(&it).map(Into::into); | 340 | }, |
344 | hover_markup(docs, it.short_label(), mod_path) | 341 | mod_path, |
345 | } | 342 | ), |
346 | }, | ||
347 | ModuleDef::Function(it) => from_def_source(db, it, mod_path), | 343 | ModuleDef::Function(it) => from_def_source(db, it, mod_path), |
348 | ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path), | 344 | ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path), |
349 | ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path), | 345 | ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path), |
@@ -371,12 +367,24 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> { | |||
371 | 367 | ||
372 | fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> | 368 | fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> |
373 | where | 369 | where |
374 | D: HasSource<Ast = A>, | 370 | D: HasSource<Ast = A> + HasAttrs + Copy, |
375 | A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel + ast::AttrsOwner, | 371 | A: ShortLabel, |
372 | { | ||
373 | let short_label = def.source(db).value.short_label(); | ||
374 | from_def_source_labeled(db, def, short_label, mod_path) | ||
375 | } | ||
376 | |||
377 | fn from_def_source_labeled<D>( | ||
378 | db: &RootDatabase, | ||
379 | def: D, | ||
380 | short_label: Option<String>, | ||
381 | mod_path: Option<String>, | ||
382 | ) -> Option<Markup> | ||
383 | where | ||
384 | D: HasAttrs, | ||
376 | { | 385 | { |
377 | let src = def.source(db); | 386 | let docs = def.attrs(db).docs().map(Into::into); |
378 | let docs = Documentation::from_ast(&src.value).map(Into::into); | 387 | hover_markup(docs, short_label, mod_path) |
379 | hover_markup(docs, src.value.short_label(), mod_path) | ||
380 | } | 388 | } |
381 | } | 389 | } |
382 | 390 | ||
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 5244bdd61..71068cac2 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -80,7 +80,8 @@ pub use crate::{ | |||
80 | }, | 80 | }, |
81 | }; | 81 | }; |
82 | pub use completion::{ | 82 | pub use completion::{ |
83 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, | 83 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionResolveCapability, |
84 | CompletionScore, ImportEdit, InsertTextFormat, | ||
84 | }; | 85 | }; |
85 | pub use ide_db::{ | 86 | pub use ide_db::{ |
86 | call_info::CallInfo, | 87 | call_info::CallInfo, |
@@ -468,6 +469,27 @@ impl Analysis { | |||
468 | self.with_db(|db| completion::completions(db, config, position).map(Into::into)) | 469 | self.with_db(|db| completion::completions(db, config, position).map(Into::into)) |
469 | } | 470 | } |
470 | 471 | ||
472 | /// Resolves additional completion data at the position given. | ||
473 | pub fn resolve_completion_edits( | ||
474 | &self, | ||
475 | config: &CompletionConfig, | ||
476 | position: FilePosition, | ||
477 | full_import_path: &str, | ||
478 | imported_name: &str, | ||
479 | ) -> Cancelable<Vec<TextEdit>> { | ||
480 | Ok(self | ||
481 | .with_db(|db| { | ||
482 | completion::resolve_completion_edits( | ||
483 | db, | ||
484 | config, | ||
485 | position, | ||
486 | full_import_path, | ||
487 | imported_name, | ||
488 | ) | ||
489 | })? | ||
490 | .unwrap_or_default()) | ||
491 | } | ||
492 | |||
471 | /// Computes resolved assists with source changes for the given position. | 493 | /// Computes resolved assists with source changes for the given position. |
472 | pub fn resolved_assists( | 494 | pub fn resolved_assists( |
473 | &self, | 495 | &self, |