mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Take label offets client capability into account
This commit is contained in:
parent
6da22ed975
commit
e1e79cf064
@ -127,6 +127,7 @@ pub struct ClientCapsConfig {
|
|||||||
pub resolve_code_action: bool,
|
pub resolve_code_action: bool,
|
||||||
pub hover_actions: bool,
|
pub hover_actions: bool,
|
||||||
pub status_notification: bool,
|
pub status_notification: bool,
|
||||||
|
pub signature_help_label_offsets: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -302,6 +303,15 @@ impl Config {
|
|||||||
{
|
{
|
||||||
self.client_caps.code_action_literals = value;
|
self.client_caps.code_action_literals = value;
|
||||||
}
|
}
|
||||||
|
if let Some(value) = doc_caps
|
||||||
|
.signature_help
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|it| it.signature_information.as_ref())
|
||||||
|
.and_then(|it| it.parameter_information.as_ref())
|
||||||
|
.and_then(|it| it.label_offset_support)
|
||||||
|
{
|
||||||
|
self.client_caps.signature_help_label_offsets = value;
|
||||||
|
}
|
||||||
|
|
||||||
self.completion.allow_snippets(false);
|
self.completion.allow_snippets(false);
|
||||||
if let Some(completion) = &doc_caps.completion {
|
if let Some(completion) = &doc_caps.completion {
|
||||||
|
@ -557,7 +557,11 @@ pub(crate) fn handle_signature_help(
|
|||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
let concise = !snap.config.call_info_full;
|
let concise = !snap.config.call_info_full;
|
||||||
let res = to_proto::signature_help(call_info, concise);
|
let res = to_proto::signature_help(
|
||||||
|
call_info,
|
||||||
|
concise,
|
||||||
|
snap.config.client_caps.signature_help_label_offsets,
|
||||||
|
);
|
||||||
Ok(Some(res))
|
Ok(Some(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,16 +219,58 @@ pub(crate) fn completion_item(
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn signature_help(call_info: CallInfo, concise: bool) -> lsp_types::SignatureHelp {
|
pub(crate) fn signature_help(
|
||||||
let parameters = call_info
|
call_info: CallInfo,
|
||||||
.parameter_labels()
|
concise: bool,
|
||||||
.map(|label| lsp_types::ParameterInformation {
|
label_offsets: bool,
|
||||||
label: lsp_types::ParameterLabel::Simple(label.to_string()),
|
) -> lsp_types::SignatureHelp {
|
||||||
documentation: None,
|
let (label, parameters) = match (concise, label_offsets) {
|
||||||
})
|
(_, false) => {
|
||||||
.collect();
|
let params = call_info
|
||||||
|
.parameter_labels()
|
||||||
|
.map(|label| lsp_types::ParameterInformation {
|
||||||
|
label: lsp_types::ParameterLabel::Simple(label.to_string()),
|
||||||
|
documentation: None,
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let label =
|
||||||
|
if concise { call_info.parameter_labels().join(", ") } else { call_info.signature };
|
||||||
|
(label, params)
|
||||||
|
}
|
||||||
|
(false, true) => {
|
||||||
|
let params = call_info
|
||||||
|
.parameter_ranges()
|
||||||
|
.iter()
|
||||||
|
.map(|it| [u32::from(it.start()).into(), u32::from(it.end()).into()])
|
||||||
|
.map(|label_offsets| lsp_types::ParameterInformation {
|
||||||
|
label: lsp_types::ParameterLabel::LabelOffsets(label_offsets),
|
||||||
|
documentation: None,
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
(call_info.signature, params)
|
||||||
|
}
|
||||||
|
(true, true) => {
|
||||||
|
let mut params = Vec::new();
|
||||||
|
let mut label = String::new();
|
||||||
|
let mut first = true;
|
||||||
|
for param in call_info.parameter_labels() {
|
||||||
|
if !first {
|
||||||
|
label.push_str(", ");
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
let start = label.len() as u64;
|
||||||
|
label.push_str(param);
|
||||||
|
let end = label.len() as u64;
|
||||||
|
params.push(lsp_types::ParameterInformation {
|
||||||
|
label: lsp_types::ParameterLabel::LabelOffsets([start, end]),
|
||||||
|
documentation: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
(label, params)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let label = if concise { call_info.parameter_labels().join(", ") } else { call_info.signature };
|
|
||||||
let documentation = call_info.doc.map(|doc| {
|
let documentation = call_info.doc.map(|doc| {
|
||||||
lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
|
lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
|
||||||
kind: lsp_types::MarkupKind::Markdown,
|
kind: lsp_types::MarkupKind::Markdown,
|
||||||
|
Loading…
Reference in New Issue
Block a user