return immediately from render_tuple_lit if snippet_cap is None

partially addresses #13767
This commit is contained in:
Brent Westbrook 2022-12-20 11:07:37 -05:00
parent 4596847a88
commit 1116cc93ec
2 changed files with 40 additions and 1 deletions

View file

@ -124,7 +124,12 @@ fn complete_fields(
#[cfg(test)]
mod tests {
use crate::tests::check_edit;
use ide_db::SnippetCap;
use crate::{
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
CompletionConfig,
};
#[test]
fn literal_struct_completion_edit() {
@ -151,6 +156,37 @@ fn baz() {
)
}
#[test]
fn enum_variant_no_snippets() {
let conf = CompletionConfig { snippet_cap: SnippetCap::new(false), ..TEST_CONFIG };
check_edit_with_config(
conf,
"Variant()",
r#"
enum Enum {
Variant(usize),
}
impl Enum {
fn new(u: usize) -> Self {
Self::Va$0
}
}
"#,
r#"
enum Enum {
Variant(usize),
}
impl Enum {
fn new(u: usize) -> Self {
Self::Variant
}
}
"#,
)
}
#[test]
fn literal_struct_impl_self_completion() {
check_edit(

View file

@ -48,6 +48,9 @@ pub(crate) fn render_tuple_lit(
fields: &[hir::Field],
path: &str,
) -> RenderedLiteral {
if snippet_cap.is_none() {
return RenderedLiteral { literal: format!("{}", path), detail: format!("{}", path) };
}
let completions = fields.iter().enumerate().format_with(", ", |(idx, _), f| {
if snippet_cap.is_some() {
f(&format_args!("${{{}:()}}", idx + 1))