diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/handlers/fill_match_arms.rs | 30 | ||||
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 29 | ||||
-rw-r--r-- | crates/ra_syntax/src/parsing/text_tree_sink.rs | 13 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/ok/0065_comment_newline.txt | 17 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cargo_target_spec.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 14 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/support.rs | 1 |
9 files changed, 100 insertions, 23 deletions
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 41bb97928..8d1af9933 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs | |||
@@ -1,15 +1,11 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use std::iter; | 1 | use std::iter; |
4 | 2 | ||
5 | use hir::{Adt, HasSource, ModuleDef, Semantics}; | 3 | use hir::{Adt, HasSource, ModuleDef, Semantics}; |
6 | use itertools::Itertools; | 4 | use itertools::Itertools; |
7 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::RootDatabase; |
6 | use ra_syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat}; | ||
8 | 7 | ||
9 | use crate::{Assist, AssistCtx, AssistId}; | 8 | use crate::{Assist, AssistCtx, AssistId}; |
10 | use ra_syntax::ast::{self, make, AstNode, NameOwner}; | ||
11 | |||
12 | use ast::{MatchArm, Pat}; | ||
13 | 9 | ||
14 | // Assist: fill_match_arms | 10 | // Assist: fill_match_arms |
15 | // | 11 | // |
@@ -717,4 +713,28 @@ mod tests { | |||
717 | "#, | 713 | "#, |
718 | ); | 714 | ); |
719 | } | 715 | } |
716 | |||
717 | #[test] | ||
718 | fn fill_match_arms_placeholder() { | ||
719 | check_assist( | ||
720 | fill_match_arms, | ||
721 | r#" | ||
722 | enum A { One, Two, } | ||
723 | fn foo(a: A) { | ||
724 | match a<|> { | ||
725 | _ => (), | ||
726 | } | ||
727 | } | ||
728 | "#, | ||
729 | r#" | ||
730 | enum A { One, Two, } | ||
731 | fn foo(a: A) { | ||
732 | match <|>a { | ||
733 | A::One => {} | ||
734 | A::Two => {} | ||
735 | } | ||
736 | } | ||
737 | "#, | ||
738 | ); | ||
739 | } | ||
720 | } | 740 | } |
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 291594e2a..738fd6f61 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -75,6 +75,7 @@ pub type Target = Idx<TargetData>; | |||
75 | 75 | ||
76 | #[derive(Debug, Clone)] | 76 | #[derive(Debug, Clone)] |
77 | pub struct PackageData { | 77 | pub struct PackageData { |
78 | pub id: String, | ||
78 | pub name: String, | 79 | pub name: String, |
79 | pub manifest: PathBuf, | 80 | pub manifest: PathBuf, |
80 | pub targets: Vec<Target>, | 81 | pub targets: Vec<Target>, |
@@ -180,6 +181,7 @@ impl CargoWorkspace { | |||
180 | .with_context(|| format!("Failed to parse edition {}", edition))?; | 181 | .with_context(|| format!("Failed to parse edition {}", edition))?; |
181 | let pkg = packages.alloc(PackageData { | 182 | let pkg = packages.alloc(PackageData { |
182 | name, | 183 | name, |
184 | id: id.to_string(), | ||
183 | manifest: manifest_path, | 185 | manifest: manifest_path, |
184 | targets: Vec::new(), | 186 | targets: Vec::new(), |
185 | is_member, | 187 | is_member, |
@@ -249,6 +251,18 @@ impl CargoWorkspace { | |||
249 | pub fn workspace_root(&self) -> &Path { | 251 | pub fn workspace_root(&self) -> &Path { |
250 | &self.workspace_root | 252 | &self.workspace_root |
251 | } | 253 | } |
254 | |||
255 | pub fn package_flag(&self, package: &PackageData) -> String { | ||
256 | if self.is_unique(&*package.name) { | ||
257 | package.name.clone() | ||
258 | } else { | ||
259 | package.id.clone() | ||
260 | } | ||
261 | } | ||
262 | |||
263 | fn is_unique(&self, name: &str) -> bool { | ||
264 | self.packages.iter().filter(|(_, v)| v.name == name).count() == 1 | ||
265 | } | ||
252 | } | 266 | } |
253 | 267 | ||
254 | #[derive(Debug, Clone, Default)] | 268 | #[derive(Debug, Clone, Default)] |
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 3d023f189..b69cae234 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -369,22 +369,33 @@ impl ast::MatchArmList { | |||
369 | 369 | ||
370 | #[must_use] | 370 | #[must_use] |
371 | pub fn remove_placeholder(&self) -> ast::MatchArmList { | 371 | pub fn remove_placeholder(&self) -> ast::MatchArmList { |
372 | let placeholder = self.arms().find(|arm| { | 372 | let placeholder = |
373 | if let Some(ast::Pat::PlaceholderPat(_)) = arm.pat() { | 373 | self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::PlaceholderPat(_)))); |
374 | return true; | ||
375 | } | ||
376 | false | ||
377 | }); | ||
378 | if let Some(placeholder) = placeholder { | 374 | if let Some(placeholder) = placeholder { |
379 | let s: SyntaxElement = placeholder.syntax().clone().into(); | 375 | self.remove_arm(&placeholder) |
380 | let e = s.clone(); | ||
381 | self.replace_children(s..=e, &mut iter::empty()) | ||
382 | } else { | 376 | } else { |
383 | self.clone() | 377 | self.clone() |
384 | } | 378 | } |
385 | } | 379 | } |
386 | 380 | ||
387 | #[must_use] | 381 | #[must_use] |
382 | fn remove_arm(&self, arm: &ast::MatchArm) -> ast::MatchArmList { | ||
383 | let start = arm.syntax().clone(); | ||
384 | let end = if let Some(comma) = start | ||
385 | .siblings_with_tokens(Direction::Next) | ||
386 | .skip(1) | ||
387 | .skip_while(|it| it.kind().is_trivia()) | ||
388 | .next() | ||
389 | .filter(|it| it.kind() == T![,]) | ||
390 | { | ||
391 | comma | ||
392 | } else { | ||
393 | start.clone().into() | ||
394 | }; | ||
395 | self.replace_children(start.into()..=end, None) | ||
396 | } | ||
397 | |||
398 | #[must_use] | ||
388 | pub fn append_arm(&self, item: ast::MatchArm) -> ast::MatchArmList { | 399 | pub fn append_arm(&self, item: ast::MatchArm) -> ast::MatchArmList { |
389 | let r_curly = match self.syntax().children_with_tokens().find(|it| it.kind() == T!['}']) { | 400 | let r_curly = match self.syntax().children_with_tokens().find(|it| it.kind() == T!['}']) { |
390 | Some(t) => t, | 401 | Some(t) => t, |
diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs index dd202601d..87bb21cd9 100644 --- a/crates/ra_syntax/src/parsing/text_tree_sink.rs +++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs | |||
@@ -149,10 +149,21 @@ fn n_attached_trivias<'a>( | |||
149 | MACRO_CALL | CONST_DEF | TYPE_ALIAS_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN_DEF | 149 | MACRO_CALL | CONST_DEF | TYPE_ALIAS_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN_DEF |
150 | | TRAIT_DEF | MODULE | RECORD_FIELD_DEF | STATIC_DEF => { | 150 | | TRAIT_DEF | MODULE | RECORD_FIELD_DEF | STATIC_DEF => { |
151 | let mut res = 0; | 151 | let mut res = 0; |
152 | for (i, (kind, text)) in trivias.enumerate() { | 152 | let mut trivias = trivias.enumerate().peekable(); |
153 | |||
154 | while let Some((i, (kind, text))) = trivias.next() { | ||
153 | match kind { | 155 | match kind { |
154 | WHITESPACE => { | 156 | WHITESPACE => { |
155 | if text.contains("\n\n") { | 157 | if text.contains("\n\n") { |
158 | // we check whether the next token is a doc-comment | ||
159 | // and skip the whitespace in this case | ||
160 | if let Some((peek_kind, peek_text)) = | ||
161 | trivias.peek().map(|(_, pair)| pair) | ||
162 | { | ||
163 | if *peek_kind == COMMENT && peek_text.starts_with("///") { | ||
164 | continue; | ||
165 | } | ||
166 | } | ||
156 | break; | 167 | break; |
157 | } | 168 | } |
158 | } | 169 | } |
diff --git a/crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rs b/crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rs new file mode 100644 index 000000000..1fafe216b --- /dev/null +++ b/crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | /// Example | ||
2 | |||
3 | fn test() {} | ||
diff --git a/crates/ra_syntax/test_data/parser/ok/0065_comment_newline.txt b/crates/ra_syntax/test_data/parser/ok/0065_comment_newline.txt new file mode 100644 index 000000000..91d0c3736 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/ok/0065_comment_newline.txt | |||
@@ -0,0 +1,17 @@ | |||
1 | SOURCE_FILE@[0; 26) | ||
2 | FN_DEF@[0; 25) | ||
3 | COMMENT@[0; 11) "/// Example" | ||
4 | WHITESPACE@[11; 13) "\n\n" | ||
5 | FN_KW@[13; 15) "fn" | ||
6 | WHITESPACE@[15; 16) " " | ||
7 | NAME@[16; 20) | ||
8 | IDENT@[16; 20) "test" | ||
9 | PARAM_LIST@[20; 22) | ||
10 | L_PAREN@[20; 21) "(" | ||
11 | R_PAREN@[21; 22) ")" | ||
12 | WHITESPACE@[22; 23) " " | ||
13 | BLOCK_EXPR@[23; 25) | ||
14 | BLOCK@[23; 25) | ||
15 | L_CURLY@[23; 24) "{" | ||
16 | R_CURLY@[24; 25) "}" | ||
17 | WHITESPACE@[25; 26) "\n" | ||
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs index f87bdcec5..942c30328 100644 --- a/crates/rust-analyzer/src/cargo_target_spec.rs +++ b/crates/rust-analyzer/src/cargo_target_spec.rs | |||
@@ -77,7 +77,7 @@ impl CargoTargetSpec { | |||
77 | ProjectWorkspace::Cargo { cargo, .. } => { | 77 | ProjectWorkspace::Cargo { cargo, .. } => { |
78 | let tgt = cargo.target_by_root(&path)?; | 78 | let tgt = cargo.target_by_root(&path)?; |
79 | Some(CargoTargetSpec { | 79 | Some(CargoTargetSpec { |
80 | package: cargo[cargo[tgt].package].name.clone(), | 80 | package: cargo.package_flag(&cargo[cargo[tgt].package]), |
81 | target: cargo[tgt].name.clone(), | 81 | target: cargo[tgt].name.clone(), |
82 | target_kind: cargo[tgt].kind, | 82 | target_kind: cargo[tgt].kind, |
83 | }) | 83 | }) |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 79ea90cc9..d818243e3 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -808,14 +808,14 @@ fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) { | |||
808 | ), | 808 | ), |
809 | _ => {} | 809 | _ => {} |
810 | } | 810 | } |
811 | } | ||
812 | 811 | ||
813 | fn send_startup_progress_notif(sender: &Sender<Message>, work_done_progress: WorkDoneProgress) { | 812 | fn send_startup_progress_notif(sender: &Sender<Message>, work_done_progress: WorkDoneProgress) { |
814 | let notif = notification_new::<req::Progress>(req::ProgressParams { | 813 | let notif = notification_new::<req::Progress>(req::ProgressParams { |
815 | token: req::ProgressToken::String("rustAnalyzer/startup".into()), | 814 | token: req::ProgressToken::String("rustAnalyzer/startup".into()), |
816 | value: req::ProgressParamsValue::WorkDone(work_done_progress), | 815 | value: req::ProgressParamsValue::WorkDone(work_done_progress), |
817 | }); | 816 | }); |
818 | sender.send(notif.into()).unwrap(); | 817 | sender.send(notif.into()).unwrap(); |
818 | } | ||
819 | } | 819 | } |
820 | 820 | ||
821 | struct PoolDispatcher<'a> { | 821 | struct PoolDispatcher<'a> { |
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs index 67f3c9332..fc3c65ad9 100644 --- a/crates/rust-analyzer/tests/heavy_tests/support.rs +++ b/crates/rust-analyzer/tests/heavy_tests/support.rs | |||
@@ -188,6 +188,7 @@ impl Server { | |||
188 | self.client.sender.send(r.into()).unwrap(); | 188 | self.client.sender.send(r.into()).unwrap(); |
189 | while let Some(msg) = self.recv() { | 189 | while let Some(msg) = self.recv() { |
190 | match msg { | 190 | match msg { |
191 | Message::Request(req) if req.method == "window/workDoneProgress/create" => (), | ||
191 | Message::Request(req) => panic!("unexpected request: {:?}", req), | 192 | Message::Request(req) => panic!("unexpected request: {:?}", req), |
192 | Message::Notification(_) => (), | 193 | Message::Notification(_) => (), |
193 | Message::Response(res) => { | 194 | Message::Response(res) => { |