diff options
| author | Brent Westbrook <brentrwestbrook@gmail.com> | 2022-12-20 11:07:37 -0500 |
|---|---|---|
| committer | Brent Westbrook <brentrwestbrook@gmail.com> | 2022-12-20 11:07:37 -0500 |
| commit | 1116cc93ec29fb7db3515afed6a99ab7d70917ff (patch) | |
| tree | d5a4d3a844fb0895b702c0b6336aefd685859a3b | |
| parent | 4596847a88abb0d5077c5111c3093e724673d7a0 (diff) | |
| download | rust-1116cc93ec29fb7db3515afed6a99ab7d70917ff.tar.gz rust-1116cc93ec29fb7db3515afed6a99ab7d70917ff.zip | |
return immediately from `render_tuple_lit` if `snippet_cap` is None
partially addresses #13767
| -rw-r--r-- | crates/ide-completion/src/completions/record.rs | 38 | ||||
| -rw-r--r-- | crates/ide-completion/src/render/variant.rs | 3 |
2 files changed, 40 insertions, 1 deletions
diff --git a/crates/ide-completion/src/completions/record.rs b/crates/ide-completion/src/completions/record.rs index 5d96fbd30a8..6743ec897f0 100644 --- a/crates/ide-completion/src/completions/record.rs +++ b/crates/ide-completion/src/completions/record.rs @@ -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() { @@ -152,6 +157,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( "Self{}", diff --git a/crates/ide-completion/src/render/variant.rs b/crates/ide-completion/src/render/variant.rs index 24e6abdc9ad..c328962b110 100644 --- a/crates/ide-completion/src/render/variant.rs +++ b/crates/ide-completion/src/render/variant.rs @@ -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)) |
