diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-21 15:57:14 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-21 15:57:14 +0000 |
commit | 1ae20d2b894171f0b8368309da727cd365b95fc1 (patch) | |
tree | 86c6b6974c63dcb9abe87e797ef0b417578483a5 | |
parent | d51cf133f68eec63eee27a8666c7590d2e8b4ef8 (diff) | |
parent | f3c7499be58941827ac8f500083b32ca74e0e8c4 (diff) |
Merge #8132
8132: Add `'` to trigger_characters, allowing more direct lifetime completions r=Veykril a=Veykril
Fixes having to type a character after `'` to complete lifetimes and labels
Co-authored-by: Lukas Wirth <[email protected]>
-rw-r--r-- | crates/ide_completion/src/completions/lifetime.rs | 31 | ||||
-rw-r--r-- | crates/ide_completion/src/context.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/caps.rs | 2 |
3 files changed, 37 insertions, 2 deletions
diff --git a/crates/ide_completion/src/completions/lifetime.rs b/crates/ide_completion/src/completions/lifetime.rs index 628c1fb9b..5eeddf7a4 100644 --- a/crates/ide_completion/src/completions/lifetime.rs +++ b/crates/ide_completion/src/completions/lifetime.rs | |||
@@ -70,6 +70,16 @@ fn func<'lifetime>(foo: &'li$0) {} | |||
70 | fn func<'lifetime>(foo: &'lifetime) {} | 70 | fn func<'lifetime>(foo: &'lifetime) {} |
71 | "#, | 71 | "#, |
72 | ); | 72 | ); |
73 | cov_mark::check!(completes_if_lifetime_without_idents); | ||
74 | check_edit( | ||
75 | "'lifetime", | ||
76 | r#" | ||
77 | fn func<'lifetime>(foo: &'$0) {} | ||
78 | "#, | ||
79 | r#" | ||
80 | fn func<'lifetime>(foo: &'lifetime) {} | ||
81 | "#, | ||
82 | ); | ||
73 | } | 83 | } |
74 | 84 | ||
75 | #[test] | 85 | #[test] |
@@ -192,6 +202,27 @@ fn foo<'footime, 'lifetime: 'a$0>() {} | |||
192 | } | 202 | } |
193 | 203 | ||
194 | #[test] | 204 | #[test] |
205 | fn check_label_edit() { | ||
206 | check_edit( | ||
207 | "'label", | ||
208 | r#" | ||
209 | fn foo() { | ||
210 | 'label: loop { | ||
211 | break '$0 | ||
212 | } | ||
213 | } | ||
214 | "#, | ||
215 | r#" | ||
216 | fn foo() { | ||
217 | 'label: loop { | ||
218 | break 'label | ||
219 | } | ||
220 | } | ||
221 | "#, | ||
222 | ); | ||
223 | } | ||
224 | |||
225 | #[test] | ||
195 | fn complete_label_in_loop() { | 226 | fn complete_label_in_loop() { |
196 | check( | 227 | check( |
197 | r#" | 228 | r#" |
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 67e2d6f6c..32f81aec1 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs | |||
@@ -255,6 +255,10 @@ impl<'a> CompletionContext<'a> { | |||
255 | if kind == IDENT || kind == LIFETIME_IDENT || kind == UNDERSCORE || kind.is_keyword() { | 255 | if kind == IDENT || kind == LIFETIME_IDENT || kind == UNDERSCORE || kind.is_keyword() { |
256 | cov_mark::hit!(completes_if_prefix_is_keyword); | 256 | cov_mark::hit!(completes_if_prefix_is_keyword); |
257 | self.original_token.text_range() | 257 | self.original_token.text_range() |
258 | } else if kind == CHAR { | ||
259 | // assume we are completing a lifetime but the user has only typed the ' | ||
260 | cov_mark::hit!(completes_if_lifetime_without_idents); | ||
261 | TextRange::at(self.original_token.text_range().start(), TextSize::from(1)) | ||
258 | } else { | 262 | } else { |
259 | TextRange::empty(self.position.offset) | 263 | TextRange::empty(self.position.offset) |
260 | } | 264 | } |
@@ -471,7 +475,7 @@ impl<'a> CompletionContext<'a> { | |||
471 | self.lifetime_syntax = | 475 | self.lifetime_syntax = |
472 | find_node_at_offset(original_file, lifetime.syntax().text_range().start()); | 476 | find_node_at_offset(original_file, lifetime.syntax().text_range().start()); |
473 | if let Some(parent) = lifetime.syntax().parent() { | 477 | if let Some(parent) = lifetime.syntax().parent() { |
474 | if parent.kind() == syntax::SyntaxKind::ERROR { | 478 | if parent.kind() == ERROR { |
475 | return; | 479 | return; |
476 | } | 480 | } |
477 | 481 | ||
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs index aa48c455c..7a5bcb8c7 100644 --- a/crates/rust-analyzer/src/caps.rs +++ b/crates/rust-analyzer/src/caps.rs | |||
@@ -33,7 +33,7 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti | |||
33 | hover_provider: Some(HoverProviderCapability::Simple(true)), | 33 | hover_provider: Some(HoverProviderCapability::Simple(true)), |
34 | completion_provider: Some(CompletionOptions { | 34 | completion_provider: Some(CompletionOptions { |
35 | resolve_provider: completions_resolve_provider(client_caps), | 35 | resolve_provider: completions_resolve_provider(client_caps), |
36 | trigger_characters: Some(vec![":".to_string(), ".".to_string()]), | 36 | trigger_characters: Some(vec![":".to_string(), ".".to_string(), "'".to_string()]), |
37 | all_commit_characters: None, | 37 | all_commit_characters: None, |
38 | completion_item: None, | 38 | completion_item: None, |
39 | work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None }, | 39 | work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None }, |