aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/completion.rs2
-rw-r--r--crates/ra_ide/src/completion/test_utils.rs2
-rw-r--r--crates/ra_ide/src/diagnostics.rs2
-rw-r--r--crates/ra_ide/src/lib.rs10
-rw-r--r--crates/ra_ide/src/references/rename.rs3
-rw-r--r--crates/ra_ide/src/runnables.rs70
6 files changed, 77 insertions, 12 deletions
diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs
index 8bdc43b1a..191300704 100644
--- a/crates/ra_ide/src/completion.rs
+++ b/crates/ra_ide/src/completion.rs
@@ -59,8 +59,8 @@ pub use crate::completion::{
59/// with ordering of completions (currently this is done by the client). 59/// with ordering of completions (currently this is done by the client).
60pub(crate) fn completions( 60pub(crate) fn completions(
61 db: &RootDatabase, 61 db: &RootDatabase,
62 position: FilePosition,
63 config: &CompletionConfig, 62 config: &CompletionConfig,
63 position: FilePosition,
64) -> Option<Completions> { 64) -> Option<Completions> {
65 let ctx = CompletionContext::new(db, position, config)?; 65 let ctx = CompletionContext::new(db, position, config)?;
66 66
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs
index eb90b5279..bf22452a2 100644
--- a/crates/ra_ide/src/completion/test_utils.rs
+++ b/crates/ra_ide/src/completion/test_utils.rs
@@ -20,7 +20,7 @@ pub(crate) fn do_completion_with_options(
20 } else { 20 } else {
21 single_file_with_position(code) 21 single_file_with_position(code)
22 }; 22 };
23 let completions = analysis.completions(position, options).unwrap().unwrap(); 23 let completions = analysis.completions(options, position).unwrap().unwrap();
24 let completion_items: Vec<CompletionItem> = completions.into(); 24 let completion_items: Vec<CompletionItem> = completions.into();
25 let mut kind_completions: Vec<CompletionItem> = 25 let mut kind_completions: Vec<CompletionItem> =
26 completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); 26 completion_items.into_iter().filter(|c| c.completion_kind == kind).collect();
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 87a0b80f1..54c2bcc09 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -629,6 +629,7 @@ mod tests {
629 }, 629 },
630 ], 630 ],
631 cursor_position: None, 631 cursor_position: None,
632 is_snippet: false,
632 }, 633 },
633 ), 634 ),
634 severity: Error, 635 severity: Error,
@@ -685,6 +686,7 @@ mod tests {
685 ], 686 ],
686 file_system_edits: [], 687 file_system_edits: [],
687 cursor_position: None, 688 cursor_position: None,
689 is_snippet: false,
688 }, 690 },
689 ), 691 ),
690 severity: Error, 692 severity: Error,
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 78149ddfc..66125f2f5 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -82,7 +82,7 @@ pub use crate::{
82}; 82};
83 83
84pub use hir::Documentation; 84pub use hir::Documentation;
85pub use ra_assists::AssistId; 85pub use ra_assists::{AssistConfig, AssistId};
86pub use ra_db::{ 86pub use ra_db::{
87 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, 87 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId,
88}; 88};
@@ -458,17 +458,17 @@ impl Analysis {
458 /// Computes completions at the given position. 458 /// Computes completions at the given position.
459 pub fn completions( 459 pub fn completions(
460 &self, 460 &self,
461 position: FilePosition,
462 config: &CompletionConfig, 461 config: &CompletionConfig,
462 position: FilePosition,
463 ) -> Cancelable<Option<Vec<CompletionItem>>> { 463 ) -> Cancelable<Option<Vec<CompletionItem>>> {
464 self.with_db(|db| completion::completions(db, position, config).map(Into::into)) 464 self.with_db(|db| completion::completions(db, config, position).map(Into::into))
465 } 465 }
466 466
467 /// Computes assists (aka code actions aka intentions) for the given 467 /// Computes assists (aka code actions aka intentions) for the given
468 /// position. 468 /// position.
469 pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<Assist>> { 469 pub fn assists(&self, config: &AssistConfig, frange: FileRange) -> Cancelable<Vec<Assist>> {
470 self.with_db(|db| { 470 self.with_db(|db| {
471 ra_assists::Assist::resolved(db, frange) 471 ra_assists::Assist::resolved(db, config, frange)
472 .into_iter() 472 .into_iter()
473 .map(|assist| Assist { 473 .map(|assist| Assist {
474 id: assist.assist.id, 474 id: assist.assist.id,
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index 410dae75c..68a53ad4b 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -670,6 +670,7 @@ mod tests {
670 }, 670 },
671 ], 671 ],
672 cursor_position: None, 672 cursor_position: None,
673 is_snippet: false,
673 }, 674 },
674 }, 675 },
675 ) 676 )
@@ -722,6 +723,7 @@ mod tests {
722 }, 723 },
723 ], 724 ],
724 cursor_position: None, 725 cursor_position: None,
726 is_snippet: false,
725 }, 727 },
726 }, 728 },
727 ) 729 )
@@ -818,6 +820,7 @@ mod tests {
818 }, 820 },
819 ], 821 ],
820 cursor_position: None, 822 cursor_position: None,
823 is_snippet: false,
821 }, 824 },
822 }, 825 },
823 ) 826 )
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs
index fa8a9d92c..131b8f307 100644
--- a/crates/ra_ide/src/runnables.rs
+++ b/crates/ra_ide/src/runnables.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::Semantics; 3use hir::{AsAssocItem, Semantics};
4use itertools::Itertools; 4use itertools::Itertools;
5use ra_ide_db::RootDatabase; 5use ra_ide_db::RootDatabase;
6use ra_syntax::{ 6use ra_syntax::{
@@ -65,14 +65,36 @@ fn runnable_fn(sema: &Semantics<RootDatabase>, fn_def: ast::FnDef) -> Option<Run
65 RunnableKind::Bin 65 RunnableKind::Bin
66 } else { 66 } else {
67 let test_id = if let Some(module) = sema.to_def(&fn_def).map(|def| def.module(sema.db)) { 67 let test_id = if let Some(module) = sema.to_def(&fn_def).map(|def| def.module(sema.db)) {
68 let path = module 68 let def = sema.to_def(&fn_def)?;
69 let impl_trait_name =
70 def.as_assoc_item(sema.db).and_then(|assoc_item| {
71 match assoc_item.container(sema.db) {
72 hir::AssocItemContainer::Trait(trait_item) => {
73 Some(trait_item.name(sema.db).to_string())
74 }
75 hir::AssocItemContainer::ImplDef(impl_def) => impl_def
76 .target_ty(sema.db)
77 .as_adt()
78 .map(|adt| adt.name(sema.db).to_string()),
79 }
80 });
81
82 let path_iter = module
69 .path_to_root(sema.db) 83 .path_to_root(sema.db)
70 .into_iter() 84 .into_iter()
71 .rev() 85 .rev()
72 .filter_map(|it| it.name(sema.db)) 86 .filter_map(|it| it.name(sema.db))
73 .map(|name| name.to_string()) 87 .map(|name| name.to_string());
74 .chain(std::iter::once(name_string)) 88
75 .join("::"); 89 let path = if let Some(impl_trait_name) = impl_trait_name {
90 path_iter
91 .chain(std::iter::once(impl_trait_name))
92 .chain(std::iter::once(name_string))
93 .join("::")
94 } else {
95 path_iter.chain(std::iter::once(name_string)).join("::")
96 };
97
76 TestId::Path(path) 98 TestId::Path(path)
77 } else { 99 } else {
78 TestId::Name(name_string) 100 TestId::Name(name_string)
@@ -238,6 +260,44 @@ mod tests {
238 } 260 }
239 261
240 #[test] 262 #[test]
263 fn test_runnables_doc_test_in_impl() {
264 let (analysis, pos) = analysis_and_position(
265 r#"
266 //- /lib.rs
267 <|> //empty
268 fn main() {}
269
270 struct Data;
271 impl Data {
272 /// ```
273 /// let x = 5;
274 /// ```
275 fn foo() {}
276 }
277 "#,
278 );
279 let runnables = analysis.runnables(pos.file_id).unwrap();
280 assert_debug_snapshot!(&runnables,
281 @r###"
282 [
283 Runnable {
284 range: 1..21,
285 kind: Bin,
286 },
287 Runnable {
288 range: 51..105,
289 kind: DocTest {
290 test_id: Path(
291 "Data::foo",
292 ),
293 },
294 },
295 ]
296 "###
297 );
298 }
299
300 #[test]
241 fn test_runnables_module() { 301 fn test_runnables_module() {
242 let (analysis, pos) = analysis_and_position( 302 let (analysis, pos) = analysis_and_position(
243 r#" 303 r#"