aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/imp.rs11
-rw-r--r--crates/ra_analysis/src/lib.rs5
-rw-r--r--crates/ra_analysis/tests/tests.rs12
3 files changed, 21 insertions, 7 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index e9af98474..07357fc84 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -323,6 +323,17 @@ impl AnalysisImpl {
323 323
324 Ok(symbol.docs(&file)) 324 Ok(symbol.docs(&file))
325 } 325 }
326 pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> {
327 let file = self.db.source_file(file_id);
328 let result = match (symbol.description(&file), symbol.docs(&file)) {
329 (Some(desc), Some(docs)) => Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs),
330 (Some(desc), None) => Some("```rust\n".to_string() + &*desc + "\n```"),
331 (None, Some(docs)) => Some(docs),
332 _ => None,
333 };
334
335 Ok(result)
336 }
326 337
327 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 338 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
328 let syntax = self.db.source_file(file_id); 339 let syntax = self.db.source_file(file_id);
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 4b8b10816..d33f3e4ca 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -236,7 +236,7 @@ impl Analysis {
236 pub fn approximately_resolve_symbol( 236 pub fn approximately_resolve_symbol(
237 &self, 237 &self,
238 position: FilePosition, 238 position: FilePosition,
239 ) -> Cancelable<Vec<(FileId, FileSymbol)>> { 239 ) -> Cancelable<Option<(TextRange, Vec<(FileId, FileSymbol)>)>> {
240 self.imp.approximately_resolve_symbol(position) 240 self.imp.approximately_resolve_symbol(position)
241 } 241 }
242 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 242 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
@@ -249,6 +249,9 @@ impl Analysis {
249 ) -> Cancelable<Option<String>> { 249 ) -> Cancelable<Option<String>> {
250 self.imp.doc_comment_for(file_id, symbol) 250 self.imp.doc_comment_for(file_id, symbol)
251 } 251 }
252 pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> {
253 self.imp.doc_text_for(file_id, symbol)
254 }
252 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { 255 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> {
253 self.imp.parent_module(position) 256 self.imp.parent_module(position)
254 } 257 }
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs
index 4ce2c5c85..05ad687ae 100644
--- a/crates/ra_analysis/tests/tests.rs
+++ b/crates/ra_analysis/tests/tests.rs
@@ -21,9 +21,9 @@ fn approximate_resolve_works_in_items() {
21 ", 21 ",
22 ); 22 );
23 23
24 let symbols = analysis.approximately_resolve_symbol(pos).unwrap(); 24 let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap();
25 assert_eq_dbg( 25 assert_eq_dbg(
26 r#"[(FileId(1), FileSymbol { name: "Foo", node_range: [0; 11), kind: STRUCT_DEF })]"#, 26 r#"([23; 26), [(FileId(1), FileSymbol { name: "Foo", node_range: [0; 11), kind: STRUCT_DEF })])"#,
27 &symbols, 27 &symbols,
28 ); 28 );
29} 29}
@@ -39,9 +39,9 @@ fn test_resolve_module() {
39 ", 39 ",
40 ); 40 );
41 41
42 let symbols = analysis.approximately_resolve_symbol(pos).unwrap(); 42 let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap();
43 assert_eq_dbg( 43 assert_eq_dbg(
44 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, 44 r#"([4; 7), [(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })])"#,
45 &symbols, 45 &symbols,
46 ); 46 );
47 47
@@ -54,9 +54,9 @@ fn test_resolve_module() {
54 ", 54 ",
55 ); 55 );
56 56
57 let symbols = analysis.approximately_resolve_symbol(pos).unwrap(); 57 let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap();
58 assert_eq_dbg( 58 assert_eq_dbg(
59 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, 59 r#"([4; 7), [(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })])"#,
60 &symbols, 60 &symbols,
61 ); 61 );
62} 62}