Skip to content

Commit 69fe27f

Browse files
Keep tab stop-less snippets in completion list (zed-industries#45227)
Closes zed-industries#45083 cc @agu-z Release Notes: - Fixed certain rust-analyzer snippets not shown
1 parent 469da2f commit 69fe27f

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

crates/languages/src/rust.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl LspAdapter for RustLspAdapter {
355355
| lsp::CompletionTextEdit::Edit(lsp::TextEdit { new_text, .. }),
356356
) = completion.text_edit.as_ref()
357357
&& let Ok(mut snippet) = snippet::Snippet::parse(new_text)
358-
&& !snippet.tabstops.is_empty()
358+
&& snippet.tabstops.len() > 1
359359
{
360360
label = String::new();
361361

@@ -421,7 +421,9 @@ impl LspAdapter for RustLspAdapter {
421421
0..label.rfind('(').unwrap_or(completion.label.len()),
422422
highlight_id,
423423
));
424-
} else if detail_left.is_none() {
424+
} else if detail_left.is_none()
425+
&& kind != Some(lsp::CompletionItemKind::SNIPPET)
426+
{
425427
return None;
426428
}
427429
}
@@ -1597,6 +1599,40 @@ mod tests {
15971599
))
15981600
);
15991601

1602+
// Postfix completion without actual tabstops (only implicit final $0)
1603+
// The label should use completion.label so it can be filtered by "ref"
1604+
let ref_completion = adapter
1605+
.label_for_completion(
1606+
&lsp::CompletionItem {
1607+
kind: Some(lsp::CompletionItemKind::SNIPPET),
1608+
label: "ref".to_string(),
1609+
filter_text: Some("ref".to_string()),
1610+
label_details: Some(CompletionItemLabelDetails {
1611+
detail: None,
1612+
description: Some("&expr".to_string()),
1613+
}),
1614+
detail: Some("&expr".to_string()),
1615+
insert_text_format: Some(lsp::InsertTextFormat::SNIPPET),
1616+
text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
1617+
range: lsp::Range::default(),
1618+
new_text: "&String::new()".to_string(),
1619+
})),
1620+
..Default::default()
1621+
},
1622+
&language,
1623+
)
1624+
.await;
1625+
assert!(
1626+
ref_completion.is_some(),
1627+
"ref postfix completion should have a label"
1628+
);
1629+
let ref_label = ref_completion.unwrap();
1630+
let filter_text = &ref_label.text[ref_label.filter_range.clone()];
1631+
assert!(
1632+
filter_text.contains("ref"),
1633+
"filter range text '{filter_text}' should contain 'ref' for filtering to work",
1634+
);
1635+
16001636
// Test for correct range calculation with mixed empty and non-empty tabstops.(See https://github.com/zed-industries/zed/issues/44825)
16011637
let res = adapter
16021638
.label_for_completion(

0 commit comments

Comments
 (0)