diff options
Diffstat (limited to 'crates')
-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 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 4 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 8 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 15 | ||||
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/params.rs | 7 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt | 32 |
12 files changed, 102 insertions, 42 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 | } | ||
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index fa07b1942..f51576521 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -285,6 +285,7 @@ fn on_request( | |||
285 | sender, | 285 | sender, |
286 | }; | 286 | }; |
287 | let req = pool_dispatcher | 287 | let req = pool_dispatcher |
288 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? | ||
288 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? | 289 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? |
289 | .on::<req::ExtendSelection>(handlers::handle_extend_selection)? | 290 | .on::<req::ExtendSelection>(handlers::handle_extend_selection)? |
290 | .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)? | 291 | .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)? |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 497f819be..d84f762f4 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -23,6 +23,10 @@ use crate::{ | |||
23 | LspError, Result, | 23 | LspError, Result, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result<String> { | ||
27 | Ok(world.status()) | ||
28 | } | ||
29 | |||
26 | pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> { | 30 | pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> { |
27 | let id = params.text_document.try_conv_with(&world)?; | 31 | let id = params.text_document.try_conv_with(&world)?; |
28 | let res = world.analysis().syntax_tree(id); | 32 | let res = world.analysis().syntax_tree(id); |
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 156cf9641..ec6b6d905 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -11,6 +11,14 @@ pub use lsp_types::{ | |||
11 | TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, | 11 | TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | pub enum AnalyzerStatus {} | ||
15 | |||
16 | impl Request for AnalyzerStatus { | ||
17 | type Params = (); | ||
18 | type Result = String; | ||
19 | const METHOD: &'static str = "ra/analyzerStatus"; | ||
20 | } | ||
21 | |||
14 | pub enum SyntaxTree {} | 22 | pub enum SyntaxTree {} |
15 | 23 | ||
16 | impl Request for SyntaxTree { | 24 | impl Request for SyntaxTree { |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index c24ded9f9..5cb97b29b 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -264,4 +264,19 @@ impl ServerWorld { | |||
264 | .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; | 264 | .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; |
265 | Ok(url) | 265 | Ok(url) |
266 | } | 266 | } |
267 | |||
268 | pub fn status(&self) -> String { | ||
269 | let mut res = String::new(); | ||
270 | if self.workspaces.is_empty() { | ||
271 | res.push_str("no workspaces\n") | ||
272 | } else { | ||
273 | res.push_str("workspaces:\n"); | ||
274 | for w in self.workspaces.iter() { | ||
275 | res += &format!("{} packages loaded\n", w.cargo.packages().count()); | ||
276 | } | ||
277 | } | ||
278 | res.push_str("\nanalysis:\n"); | ||
279 | res.push_str(&self.analysis.status()); | ||
280 | res | ||
281 | } | ||
267 | } | 282 | } |
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 05cf41a8d..c50dc6c67 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -13,7 +13,7 @@ unicode-xid = "0.1.0" | |||
13 | itertools = "0.8.0" | 13 | itertools = "0.8.0" |
14 | drop_bomb = "0.1.4" | 14 | drop_bomb = "0.1.4" |
15 | parking_lot = "0.7.0" | 15 | parking_lot = "0.7.0" |
16 | rowan = "0.3.1" | 16 | rowan = "0.3.2" |
17 | 17 | ||
18 | # ideally, `serde` should be enabled by `ra_lsp_serder`, but we enable it here | 18 | # ideally, `serde` should be enabled by `ra_lsp_serder`, but we enable it here |
19 | # to reduce number of compilations | 19 | # to reduce number of compilations |
diff --git a/crates/ra_syntax/src/grammar/params.rs b/crates/ra_syntax/src/grammar/params.rs index 658fc5820..13158429a 100644 --- a/crates/ra_syntax/src/grammar/params.rs +++ b/crates/ra_syntax/src/grammar/params.rs | |||
@@ -79,7 +79,12 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { | |||
79 | let la1 = p.nth(1); | 79 | let la1 = p.nth(1); |
80 | let la2 = p.nth(2); | 80 | let la2 = p.nth(2); |
81 | let la3 = p.nth(3); | 81 | let la3 = p.nth(3); |
82 | if la0 == IDENT && la1 == COLON | 82 | |
83 | // test trait_fn_placeholder_parameter | ||
84 | // trait Foo { | ||
85 | // fn bar(_: u64); | ||
86 | // } | ||
87 | if (la0 == IDENT || la0 == UNDERSCORE) && la1 == COLON | ||
83 | || la0 == AMP && la1 == IDENT && la2 == COLON | 88 | || la0 == AMP && la1 == IDENT && la2 == COLON |
84 | || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON | 89 | || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON |
85 | { | 90 | { |
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs index 9b93945cc..a7bfb80e2 100644 --- a/crates/ra_syntax/src/yellow.rs +++ b/crates/ra_syntax/src/yellow.rs | |||
@@ -177,6 +177,10 @@ impl SyntaxNode { | |||
177 | pub fn children(&self) -> SyntaxNodeChildren { | 177 | pub fn children(&self) -> SyntaxNodeChildren { |
178 | SyntaxNodeChildren(self.0.children()) | 178 | SyntaxNodeChildren(self.0.children()) |
179 | } | 179 | } |
180 | |||
181 | pub fn memory_size_of_subtree(&self) -> usize { | ||
182 | self.0.memory_size_of_subtree() | ||
183 | } | ||
180 | } | 184 | } |
181 | 185 | ||
182 | impl fmt::Debug for SyntaxNode { | 186 | impl fmt::Debug for SyntaxNode { |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs new file mode 100644 index 000000000..aede3f4fe --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | trait Foo { | ||
2 | fn bar(_: u64); | ||
3 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt new file mode 100644 index 000000000..248d491df --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt | |||
@@ -0,0 +1,32 @@ | |||
1 | SOURCE_FILE@[0; 34) | ||
2 | TRAIT_DEF@[0; 33) | ||
3 | TRAIT_KW@[0; 5) | ||
4 | WHITESPACE@[5; 6) | ||
5 | NAME@[6; 9) | ||
6 | IDENT@[6; 9) "Foo" | ||
7 | WHITESPACE@[9; 10) | ||
8 | ITEM_LIST@[10; 33) | ||
9 | L_CURLY@[10; 11) | ||
10 | WHITESPACE@[11; 16) | ||
11 | FN_DEF@[16; 31) | ||
12 | FN_KW@[16; 18) | ||
13 | WHITESPACE@[18; 19) | ||
14 | NAME@[19; 22) | ||
15 | IDENT@[19; 22) "bar" | ||
16 | PARAM_LIST@[22; 30) | ||
17 | L_PAREN@[22; 23) | ||
18 | PARAM@[23; 29) | ||
19 | PLACEHOLDER_PAT@[23; 24) | ||
20 | UNDERSCORE@[23; 24) | ||
21 | COLON@[24; 25) | ||
22 | WHITESPACE@[25; 26) | ||
23 | PATH_TYPE@[26; 29) | ||
24 | PATH@[26; 29) | ||
25 | PATH_SEGMENT@[26; 29) | ||
26 | NAME_REF@[26; 29) | ||
27 | IDENT@[26; 29) "u64" | ||
28 | R_PAREN@[29; 30) | ||
29 | SEMI@[30; 31) | ||
30 | WHITESPACE@[31; 32) | ||
31 | R_CURLY@[32; 33) | ||
32 | WHITESPACE@[33; 34) | ||