Improve formatting of variable/field completions for Rust
Co-Authored-By: Nathan Sobo <nathan@zed.dev> Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
8149bcbb13
commit
474ec2199c
1 changed files with 23 additions and 4 deletions
|
@ -34,10 +34,29 @@ impl LspPostProcessor for RustPostProcessor {
|
||||||
|
|
||||||
fn label_for_completion(&self, completion: &lsp::CompletionItem) -> Option<String> {
|
fn label_for_completion(&self, completion: &lsp::CompletionItem) -> Option<String> {
|
||||||
let detail = completion.detail.as_ref()?;
|
let detail = completion.detail.as_ref()?;
|
||||||
if detail.starts_with("fn(") {
|
match completion.kind {
|
||||||
Some(completion.label.replace("(…)", &detail[2..]))
|
Some(
|
||||||
} else {
|
lsp::CompletionItemKind::CONSTANT
|
||||||
None
|
| lsp::CompletionItemKind::FIELD
|
||||||
|
| lsp::CompletionItemKind::VARIABLE,
|
||||||
|
) => {
|
||||||
|
let mut label = completion.label.clone();
|
||||||
|
label.push_str(": ");
|
||||||
|
label.push_str(detail);
|
||||||
|
Some(label)
|
||||||
|
}
|
||||||
|
Some(lsp::CompletionItemKind::FUNCTION | lsp::CompletionItemKind::METHOD) => {
|
||||||
|
lazy_static! {
|
||||||
|
static ref REGEX: Regex = Regex::new("\\(…?\\)").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if detail.starts_with("fn(") {
|
||||||
|
Some(REGEX.replace(&completion.label, &detail[2..]).to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue