diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-06 17:09:58 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-06 17:09:58 +0000 |
commit | 8e8c5a73ff3b26a7c919fee6caa3212dca9c6ba5 (patch) | |
tree | 22a0cb43006931d9acfb77940b2cda2d16f702d6 | |
parent | ce7496ec2227746cfcd2147fadf58fa71f65e35b (diff) | |
parent | 3ff170d65872d9965c4bd88184701d957f23570e (diff) |
Merge #3498
3498: Trigger parameter info automatically r=matklad a=matklad
See https://github.com/Microsoft/vscode/issues/64023
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/ra_ide/src/completion/completion_item.rs | 15 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 22 | ||||
-rw-r--r-- | crates/ra_ide_db/src/feature_flags.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/conv.rs | 10 | ||||
-rw-r--r-- | editors/code/package.json | 4 |
5 files changed, 46 insertions, 6 deletions
diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs index 61867c0ff..19bbb2517 100644 --- a/crates/ra_ide/src/completion/completion_item.rs +++ b/crates/ra_ide/src/completion/completion_item.rs | |||
@@ -47,6 +47,10 @@ pub struct CompletionItem { | |||
47 | 47 | ||
48 | /// Whether this item is marked as deprecated | 48 | /// Whether this item is marked as deprecated |
49 | deprecated: bool, | 49 | deprecated: bool, |
50 | |||
51 | /// If completing a function call, ask the editor to show parameter popup | ||
52 | /// after completion. | ||
53 | trigger_call_info: bool, | ||
50 | } | 54 | } |
51 | 55 | ||
52 | // We use custom debug for CompletionItem to make `insta`'s diffs more readable. | 56 | // We use custom debug for CompletionItem to make `insta`'s diffs more readable. |
@@ -139,6 +143,7 @@ impl CompletionItem { | |||
139 | kind: None, | 143 | kind: None, |
140 | text_edit: None, | 144 | text_edit: None, |
141 | deprecated: None, | 145 | deprecated: None, |
146 | trigger_call_info: None, | ||
142 | } | 147 | } |
143 | } | 148 | } |
144 | /// What user sees in pop-up in the UI. | 149 | /// What user sees in pop-up in the UI. |
@@ -177,6 +182,10 @@ impl CompletionItem { | |||
177 | pub fn deprecated(&self) -> bool { | 182 | pub fn deprecated(&self) -> bool { |
178 | self.deprecated | 183 | self.deprecated |
179 | } | 184 | } |
185 | |||
186 | pub fn trigger_call_info(&self) -> bool { | ||
187 | self.trigger_call_info | ||
188 | } | ||
180 | } | 189 | } |
181 | 190 | ||
182 | /// A helper to make `CompletionItem`s. | 191 | /// A helper to make `CompletionItem`s. |
@@ -193,6 +202,7 @@ pub(crate) struct Builder { | |||
193 | kind: Option<CompletionItemKind>, | 202 | kind: Option<CompletionItemKind>, |
194 | text_edit: Option<TextEdit>, | 203 | text_edit: Option<TextEdit>, |
195 | deprecated: Option<bool>, | 204 | deprecated: Option<bool>, |
205 | trigger_call_info: Option<bool>, | ||
196 | } | 206 | } |
197 | 207 | ||
198 | impl Builder { | 208 | impl Builder { |
@@ -221,6 +231,7 @@ impl Builder { | |||
221 | kind: self.kind, | 231 | kind: self.kind, |
222 | completion_kind: self.completion_kind, | 232 | completion_kind: self.completion_kind, |
223 | deprecated: self.deprecated.unwrap_or(false), | 233 | deprecated: self.deprecated.unwrap_or(false), |
234 | trigger_call_info: self.trigger_call_info.unwrap_or(false), | ||
224 | } | 235 | } |
225 | } | 236 | } |
226 | pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder { | 237 | pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder { |
@@ -271,6 +282,10 @@ impl Builder { | |||
271 | self.deprecated = Some(deprecated); | 282 | self.deprecated = Some(deprecated); |
272 | self | 283 | self |
273 | } | 284 | } |
285 | pub(crate) fn trigger_call_info(mut self) -> Builder { | ||
286 | self.trigger_call_info = Some(true); | ||
287 | self | ||
288 | } | ||
274 | } | 289 | } |
275 | 290 | ||
276 | impl<'a> Into<CompletionItem> for Builder { | 291 | impl<'a> Into<CompletionItem> for Builder { |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index dac232a85..d6196a5ce 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -103,7 +103,7 @@ impl Completions { | |||
103 | } | 103 | } |
104 | }; | 104 | }; |
105 | 105 | ||
106 | // If not an import, add parenthesis automatically. | 106 | // Add `<>` for generic types |
107 | if ctx.is_path_type | 107 | if ctx.is_path_type |
108 | && !ctx.has_type_args | 108 | && !ctx.has_type_args |
109 | && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") | 109 | && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") |
@@ -211,7 +211,7 @@ impl Completions { | |||
211 | .set_deprecated(is_deprecated(func, ctx.db)) | 211 | .set_deprecated(is_deprecated(func, ctx.db)) |
212 | .detail(function_signature.to_string()); | 212 | .detail(function_signature.to_string()); |
213 | 213 | ||
214 | // Add `<>` for generic types | 214 | // If not an import, add parenthesis automatically. |
215 | if ctx.use_item_syntax.is_none() | 215 | if ctx.use_item_syntax.is_none() |
216 | && !ctx.is_call | 216 | && !ctx.is_call |
217 | && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") | 217 | && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") |
@@ -221,16 +221,26 @@ impl Completions { | |||
221 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { | 221 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { |
222 | (format!("{}()$0", name), format!("{}()", name)) | 222 | (format!("{}()$0", name), format!("{}()", name)) |
223 | } else { | 223 | } else { |
224 | let to_skip = if has_self_param { 1 } else { 0 }; | 224 | builder = builder.trigger_call_info(); |
225 | let function_params_snippet = | 225 | let snippet = if ctx |
226 | join( | 226 | .db |
227 | .feature_flags | ||
228 | .get("completion.insertion.add-argument-sippets") | ||
229 | { | ||
230 | let to_skip = if has_self_param { 1 } else { 0 }; | ||
231 | let function_params_snippet = join( | ||
227 | function_signature.parameter_names.iter().skip(to_skip).enumerate().map( | 232 | function_signature.parameter_names.iter().skip(to_skip).enumerate().map( |
228 | |(index, param_name)| format!("${{{}:{}}}", index + 1, param_name), | 233 | |(index, param_name)| format!("${{{}:{}}}", index + 1, param_name), |
229 | ), | 234 | ), |
230 | ) | 235 | ) |
231 | .separator(", ") | 236 | .separator(", ") |
232 | .to_string(); | 237 | .to_string(); |
233 | (format!("{}({})$0", name, function_params_snippet), format!("{}(…)", name)) | 238 | format!("{}({})$0", name, function_params_snippet) |
239 | } else { | ||
240 | format!("{}($0)", name) | ||
241 | }; | ||
242 | |||
243 | (snippet, format!("{}(…)", name)) | ||
234 | }; | 244 | }; |
235 | builder = builder.lookup_by(name).label(label).insert_snippet(snippet); | 245 | builder = builder.lookup_by(name).label(label).insert_snippet(snippet); |
236 | } | 246 | } |
diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/ra_ide_db/src/feature_flags.rs index 76655f572..d9c9d6cd2 100644 --- a/crates/ra_ide_db/src/feature_flags.rs +++ b/crates/ra_ide_db/src/feature_flags.rs | |||
@@ -54,6 +54,7 @@ impl Default for FeatureFlags { | |||
54 | FeatureFlags::new(&[ | 54 | FeatureFlags::new(&[ |
55 | ("lsp.diagnostics", true), | 55 | ("lsp.diagnostics", true), |
56 | ("completion.insertion.add-call-parenthesis", true), | 56 | ("completion.insertion.add-call-parenthesis", true), |
57 | ("completion.insertion.add-argument-sippets", true), | ||
57 | ("completion.enable-postfix", true), | 58 | ("completion.enable-postfix", true), |
58 | ("notifications.workspace-loaded", true), | 59 | ("notifications.workspace-loaded", true), |
59 | ("notifications.cargo-toml-not-found", true), | 60 | ("notifications.cargo-toml-not-found", true), |
diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs index eeeb33e8f..fe3b588e4 100644 --- a/crates/rust-analyzer/src/conv.rs +++ b/crates/rust-analyzer/src/conv.rs | |||
@@ -150,6 +150,16 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem { | |||
150 | additional_text_edits: Some(additional_text_edits), | 150 | additional_text_edits: Some(additional_text_edits), |
151 | documentation: self.documentation().map(|it| it.conv()), | 151 | documentation: self.documentation().map(|it| it.conv()), |
152 | deprecated: Some(self.deprecated()), | 152 | deprecated: Some(self.deprecated()), |
153 | command: if self.trigger_call_info() { | ||
154 | let cmd = lsp_types::Command { | ||
155 | title: "triggerParameterHints".into(), | ||
156 | command: "editor.action.triggerParameterHints".into(), | ||
157 | arguments: None, | ||
158 | }; | ||
159 | Some(cmd) | ||
160 | } else { | ||
161 | None | ||
162 | }, | ||
153 | ..Default::default() | 163 | ..Default::default() |
154 | }; | 164 | }; |
155 | 165 | ||
diff --git a/editors/code/package.json b/editors/code/package.json index 830358605..2f442aae8 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -197,6 +197,10 @@ | |||
197 | "type": "boolean", | 197 | "type": "boolean", |
198 | "description": "Whether to add parenthesis when completing functions" | 198 | "description": "Whether to add parenthesis when completing functions" |
199 | }, | 199 | }, |
200 | "completion.insertion.add-argument-sippets": { | ||
201 | "type": "boolean", | ||
202 | "description": "Whether to add argument snippets when completing functions" | ||
203 | }, | ||
200 | "completion.enable-postfix": { | 204 | "completion.enable-postfix": { |
201 | "type": "boolean", | 205 | "type": "boolean", |
202 | "description": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc." | 206 | "description": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc." |