Skip to content

Commit 1116cc9

Browse files
committed
return immediately from render_tuple_lit if snippet_cap is None
partially addresses #13767
1 parent 4596847 commit 1116cc9

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

crates/ide-completion/src/completions/record.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ fn complete_fields(
124124

125125
#[cfg(test)]
126126
mod tests {
127-
use crate::tests::check_edit;
127+
use ide_db::SnippetCap;
128+
129+
use crate::{
130+
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
131+
CompletionConfig,
132+
};
128133

129134
#[test]
130135
fn literal_struct_completion_edit() {
@@ -151,6 +156,37 @@ fn baz() {
151156
)
152157
}
153158

159+
#[test]
160+
fn enum_variant_no_snippets() {
161+
let conf = CompletionConfig { snippet_cap: SnippetCap::new(false), ..TEST_CONFIG };
162+
check_edit_with_config(
163+
conf,
164+
"Variant()",
165+
r#"
166+
enum Enum {
167+
Variant(usize),
168+
}
169+
170+
impl Enum {
171+
fn new(u: usize) -> Self {
172+
Self::Va$0
173+
}
174+
}
175+
"#,
176+
r#"
177+
enum Enum {
178+
Variant(usize),
179+
}
180+
181+
impl Enum {
182+
fn new(u: usize) -> Self {
183+
Self::Variant
184+
}
185+
}
186+
"#,
187+
)
188+
}
189+
154190
#[test]
155191
fn literal_struct_impl_self_completion() {
156192
check_edit(

crates/ide-completion/src/render/variant.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub(crate) fn render_tuple_lit(
4848
fields: &[hir::Field],
4949
path: &str,
5050
) -> RenderedLiteral {
51+
if snippet_cap.is_none() {
52+
return RenderedLiteral { literal: format!("{}", path), detail: format!("{}", path) };
53+
}
5154
let completions = fields.iter().enumerate().format_with(", ", |(idx, _), f| {
5255
if snippet_cap.is_some() {
5356
f(&format_args!("${{{}:()}}", idx + 1))

0 commit comments

Comments
 (0)