aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/config.rs10
-rw-r--r--crates/rust-analyzer/src/handlers.rs6
-rw-r--r--crates/rust-analyzer/src/to_proto.rs60
3 files changed, 66 insertions, 10 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index ed5e52871..68b2a2abd 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -127,6 +127,7 @@ pub struct ClientCapsConfig {
127 pub resolve_code_action: bool, 127 pub resolve_code_action: bool,
128 pub hover_actions: bool, 128 pub hover_actions: bool,
129 pub status_notification: bool, 129 pub status_notification: bool,
130 pub signature_help_label_offsets: bool,
130} 131}
131 132
132impl Config { 133impl Config {
@@ -302,6 +303,15 @@ impl Config {
302 { 303 {
303 self.client_caps.code_action_literals = value; 304 self.client_caps.code_action_literals = value;
304 } 305 }
306 if let Some(value) = doc_caps
307 .signature_help
308 .as_ref()
309 .and_then(|it| it.signature_information.as_ref())
310 .and_then(|it| it.parameter_information.as_ref())
311 .and_then(|it| it.label_offset_support)
312 {
313 self.client_caps.signature_help_label_offsets = value;
314 }
305 315
306 self.completion.allow_snippets(false); 316 self.completion.allow_snippets(false);
307 if let Some(completion) = &doc_caps.completion { 317 if let Some(completion) = &doc_caps.completion {
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 447d73fd4..18d660f42 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -557,7 +557,11 @@ pub(crate) fn handle_signature_help(
557 None => return Ok(None), 557 None => return Ok(None),
558 }; 558 };
559 let concise = !snap.config.call_info_full; 559 let concise = !snap.config.call_info_full;
560 let res = to_proto::signature_help(call_info, concise); 560 let res = to_proto::signature_help(
561 call_info,
562 concise,
563 snap.config.client_caps.signature_help_label_offsets,
564 );
561 Ok(Some(res)) 565 Ok(Some(res))
562} 566}
563 567
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 43fc52848..7fcb43a4f 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -219,16 +219,58 @@ pub(crate) fn completion_item(
219 res 219 res
220} 220}
221 221
222pub(crate) fn signature_help(call_info: CallInfo, concise: bool) -> lsp_types::SignatureHelp { 222pub(crate) fn signature_help(
223 let parameters = call_info 223 call_info: CallInfo,
224 .parameter_labels() 224 concise: bool,
225 .map(|label| lsp_types::ParameterInformation { 225 label_offsets: bool,
226 label: lsp_types::ParameterLabel::Simple(label.to_string()), 226) -> lsp_types::SignatureHelp {
227 documentation: None, 227 let (label, parameters) = match (concise, label_offsets) {
228 }) 228 (_, false) => {
229 .collect(); 229 let params = call_info
230 .parameter_labels()
231 .map(|label| lsp_types::ParameterInformation {
232 label: lsp_types::ParameterLabel::Simple(label.to_string()),
233 documentation: None,
234 })
235 .collect::<Vec<_>>();
236 let label =
237 if concise { call_info.parameter_labels().join(", ") } else { call_info.signature };
238 (label, params)
239 }
240 (false, true) => {
241 let params = call_info
242 .parameter_ranges()
243 .iter()
244 .map(|it| [u32::from(it.start()).into(), u32::from(it.end()).into()])
245 .map(|label_offsets| lsp_types::ParameterInformation {
246 label: lsp_types::ParameterLabel::LabelOffsets(label_offsets),
247 documentation: None,
248 })
249 .collect::<Vec<_>>();
250 (call_info.signature, params)
251 }
252 (true, true) => {
253 let mut params = Vec::new();
254 let mut label = String::new();
255 let mut first = true;
256 for param in call_info.parameter_labels() {
257 if !first {
258 label.push_str(", ");
259 }
260 first = false;
261 let start = label.len() as u64;
262 label.push_str(param);
263 let end = label.len() as u64;
264 params.push(lsp_types::ParameterInformation {
265 label: lsp_types::ParameterLabel::LabelOffsets([start, end]),
266 documentation: None,
267 });
268 }
269
270 (label, params)
271 }
272 };
230 273
231 let label = if concise { call_info.parameter_labels().join(", ") } else { call_info.signature };
232 let documentation = call_info.doc.map(|doc| { 274 let documentation = call_info.doc.map(|doc| {
233 lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent { 275 lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
234 kind: lsp_types::MarkupKind::Markdown, 276 kind: lsp_types::MarkupKind::Markdown,