Skip to content

Commit c71e136

Browse files
committed
Auto merge of #15269 - DropDemBits:structured-snippets-deferred-rendering, r=Veykril
internal: Defer structured snippet rendering to allow escaping snippet bits Since we know exactly where snippets are, we can transparently escape snippet bits to the exact text edits that need it, and not have to do it for anything other text edits. Also will eventually fix #11006 once all assists are migrated. This comes as a side-effect of text edits that don't have snippets get marked as having no insert formatting at all.
2 parents f6bffa4 + 614987a commit c71e136

File tree

8 files changed

+956
-233
lines changed

8 files changed

+956
-233
lines changed

crates/ide-assists/src/tests.rs

+55-38
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,13 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
132132
.filter(|it| !it.source_file_edits.is_empty() || !it.file_system_edits.is_empty())
133133
.expect("Assist did not contain any source changes");
134134
let mut actual = before;
135-
if let Some(source_file_edit) = source_change.get_source_edit(file_id) {
135+
if let Some((source_file_edit, snippet_edit)) =
136+
source_change.get_source_and_snippet_edit(file_id)
137+
{
136138
source_file_edit.apply(&mut actual);
139+
if let Some(snippet_edit) = snippet_edit {
140+
snippet_edit.apply(&mut actual);
141+
}
137142
}
138143
actual
139144
};
@@ -191,9 +196,12 @@ fn check_with_config(
191196
&& source_change.file_system_edits.len() == 0;
192197

193198
let mut buf = String::new();
194-
for (file_id, edit) in source_change.source_file_edits {
199+
for (file_id, (edit, snippet_edit)) in source_change.source_file_edits {
195200
let mut text = db.file_text(file_id).as_ref().to_owned();
196201
edit.apply(&mut text);
202+
if let Some(snippet_edit) = snippet_edit {
203+
snippet_edit.apply(&mut text);
204+
}
197205
if !skip_header {
198206
let sr = db.file_source_root(file_id);
199207
let sr = db.source_root(sr);
@@ -485,18 +493,21 @@ pub fn test_some_range(a: int) -> bool {
485493
source_file_edits: {
486494
FileId(
487495
0,
488-
): TextEdit {
489-
indels: [
490-
Indel {
491-
insert: "let $0var_name = 5;\n ",
492-
delete: 45..45,
493-
},
494-
Indel {
495-
insert: "var_name",
496-
delete: 59..60,
497-
},
498-
],
499-
},
496+
): (
497+
TextEdit {
498+
indels: [
499+
Indel {
500+
insert: "let $0var_name = 5;\n ",
501+
delete: 45..45,
502+
},
503+
Indel {
504+
insert: "var_name",
505+
delete: 59..60,
506+
},
507+
],
508+
},
509+
None,
510+
),
500511
},
501512
file_system_edits: [],
502513
is_snippet: true,
@@ -544,18 +555,21 @@ pub fn test_some_range(a: int) -> bool {
544555
source_file_edits: {
545556
FileId(
546557
0,
547-
): TextEdit {
548-
indels: [
549-
Indel {
550-
insert: "let $0var_name = 5;\n ",
551-
delete: 45..45,
552-
},
553-
Indel {
554-
insert: "var_name",
555-
delete: 59..60,
556-
},
557-
],
558-
},
558+
): (
559+
TextEdit {
560+
indels: [
561+
Indel {
562+
insert: "let $0var_name = 5;\n ",
563+
delete: 45..45,
564+
},
565+
Indel {
566+
insert: "var_name",
567+
delete: 59..60,
568+
},
569+
],
570+
},
571+
None,
572+
),
559573
},
560574
file_system_edits: [],
561575
is_snippet: true,
@@ -581,18 +595,21 @@ pub fn test_some_range(a: int) -> bool {
581595
source_file_edits: {
582596
FileId(
583597
0,
584-
): TextEdit {
585-
indels: [
586-
Indel {
587-
insert: "fun_name()",
588-
delete: 59..60,
589-
},
590-
Indel {
591-
insert: "\n\nfn $0fun_name() -> i32 {\n 5\n}",
592-
delete: 110..110,
593-
},
594-
],
595-
},
598+
): (
599+
TextEdit {
600+
indels: [
601+
Indel {
602+
insert: "fun_name()",
603+
delete: 59..60,
604+
},
605+
Indel {
606+
insert: "\n\nfn $0fun_name() -> i32 {\n 5\n}",
607+
delete: 110..110,
608+
},
609+
],
610+
},
611+
None,
612+
),
596613
},
597614
file_system_edits: [],
598615
is_snippet: true,

0 commit comments

Comments
 (0)