diff options
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 47 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/status.rs | 15 |
3 files changed, 28 insertions, 40 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 18b9508ef..798fb7c13 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | use std::cmp::{max, min}; | ||
2 | |||
3 | use ra_db::SyntaxDatabase; | 1 | use ra_db::SyntaxDatabase; |
4 | use ra_syntax::{ | 2 | use ra_syntax::{ |
5 | AstNode, SyntaxNode, TextUnit, TextRange, | 3 | AstNode, SyntaxNode, TextUnit, TextRange, |
@@ -107,15 +105,13 @@ impl<'a> FnCallNode<'a> { | |||
107 | 105 | ||
108 | impl CallInfo { | 106 | impl CallInfo { |
109 | fn new(node: &ast::FnDef) -> Option<Self> { | 107 | fn new(node: &ast::FnDef) -> Option<Self> { |
110 | let mut doc = None; | 108 | let label: String = if let Some(body) = node.body() { |
111 | |||
112 | // Strip the body out for the label. | ||
113 | let mut label: String = if let Some(body) = node.body() { | ||
114 | let body_range = body.syntax().range(); | 109 | let body_range = body.syntax().range(); |
115 | let label: String = node | 110 | let label: String = node |
116 | .syntax() | 111 | .syntax() |
117 | .children() | 112 | .children() |
118 | .filter(|child| !child.range().is_subrange(&body_range)) | 113 | .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body |
114 | .filter(|child| ast::Comment::cast(child).is_none()) // Filter out doc comments | ||
119 | .map(|node| node.text().to_string()) | 115 | .map(|node| node.text().to_string()) |
120 | .collect(); | 116 | .collect(); |
121 | label | 117 | label |
@@ -123,16 +119,9 @@ impl CallInfo { | |||
123 | node.syntax().text().to_string() | 119 | node.syntax().text().to_string() |
124 | }; | 120 | }; |
125 | 121 | ||
126 | if let Some((comment_range, docs)) = extract_doc_comments(node) { | 122 | let mut doc = None; |
127 | let comment_range = comment_range | 123 | let docs = node.doc_comment_text(); |
128 | .checked_sub(node.syntax().range().start()) | 124 | if !docs.is_empty() { |
129 | .unwrap(); | ||
130 | let start = comment_range.start().to_usize(); | ||
131 | let end = comment_range.end().to_usize(); | ||
132 | |||
133 | // Remove the comment from the label | ||
134 | label.replace_range(start..end, ""); | ||
135 | |||
136 | // Massage markdown | 125 | // Massage markdown |
137 | let mut processed_lines = Vec::new(); | 126 | let mut processed_lines = Vec::new(); |
138 | let mut in_code_block = false; | 127 | let mut in_code_block = false; |
@@ -150,9 +139,7 @@ impl CallInfo { | |||
150 | processed_lines.push(line); | 139 | processed_lines.push(line); |
151 | } | 140 | } |
152 | 141 | ||
153 | if !processed_lines.is_empty() { | 142 | doc = Some(processed_lines.join("\n")); |
154 | doc = Some(processed_lines.join("\n")); | ||
155 | } | ||
156 | } | 143 | } |
157 | 144 | ||
158 | Some(CallInfo { | 145 | Some(CallInfo { |
@@ -164,26 +151,6 @@ impl CallInfo { | |||
164 | } | 151 | } |
165 | } | 152 | } |
166 | 153 | ||
167 | fn extract_doc_comments(node: &ast::FnDef) -> Option<(TextRange, String)> { | ||
168 | if node.doc_comments().count() == 0 { | ||
169 | return None; | ||
170 | } | ||
171 | |||
172 | let comment_text = node.doc_comment_text(); | ||
173 | |||
174 | let (begin, end) = node | ||
175 | .doc_comments() | ||
176 | .map(|comment| comment.syntax().range()) | ||
177 | .map(|range| (range.start().to_usize(), range.end().to_usize())) | ||
178 | .fold((std::usize::MAX, std::usize::MIN), |acc, range| { | ||
179 | (min(acc.0, range.0), max(acc.1, range.1)) | ||
180 | }); | ||
181 | |||
182 | let range = TextRange::from_to(TextUnit::from_usize(begin), TextUnit::from_usize(end)); | ||
183 | |||
184 | Some((range, comment_text)) | ||
185 | } | ||
186 | |||
187 | fn param_list(node: &ast::FnDef) -> Vec<String> { | 154 | fn param_list(node: &ast::FnDef) -> Vec<String> { |
188 | let mut res = vec![]; | 155 | let mut res = vec![]; |
189 | if let Some(param_list) = node.param_list() { | 156 | if let Some(param_list) = node.param_list() { |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index a09a8f926..3c53e75ac 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -15,6 +15,7 @@ pub mod mock_analysis; | |||
15 | mod symbol_index; | 15 | mod symbol_index; |
16 | mod navigation_target; | 16 | mod navigation_target; |
17 | 17 | ||
18 | mod status; | ||
18 | mod completion; | 19 | mod completion; |
19 | mod runnables; | 20 | mod runnables; |
20 | mod goto_definition; | 21 | mod goto_definition; |
@@ -293,6 +294,11 @@ pub struct Analysis { | |||
293 | } | 294 | } |
294 | 295 | ||
295 | impl Analysis { | 296 | impl Analysis { |
297 | /// Debug info about the current state of the analysis | ||
298 | pub fn status(&self) -> String { | ||
299 | status::status(&*self.db) | ||
300 | } | ||
301 | |||
296 | /// Gets the text of the source file. | 302 | /// Gets the text of the source file. |
297 | pub fn file_text(&self, file_id: FileId) -> Arc<String> { | 303 | pub fn file_text(&self, file_id: FileId) -> Arc<String> { |
298 | self.db.file_text(file_id) | 304 | self.db.file_text(file_id) |
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs new file mode 100644 index 000000000..d3e04be23 --- /dev/null +++ b/crates/ra_ide_api/src/status.rs | |||
@@ -0,0 +1,15 @@ | |||
1 | use ra_db::{ | ||
2 | LocationIntener, SourceFileQuery, | ||
3 | salsa::{Database, debug::DebugQueryTable}, | ||
4 | }; | ||
5 | |||
6 | use crate::db::RootDatabase; | ||
7 | |||
8 | pub(crate) fn status(db: &RootDatabase) -> String { | ||
9 | let n_parsed_files = db.query(SourceFileQuery).keys::<Vec<_>>().len(); | ||
10 | let n_defs = { | ||
11 | let interner: &LocationIntener<hir::DefLoc, hir::DefId> = db.as_ref(); | ||
12 | interner.len() | ||
13 | }; | ||
14 | format!("#n_parsed_files {}\n#n_defs {}\n", n_parsed_files, n_defs) | ||
15 | } | ||