Skip to content

Commit

Permalink
Auto merge of #15269 - DropDemBits:structured-snippets-deferred-rende…
Browse files Browse the repository at this point in the history
…ring, 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.
  • Loading branch information
bors committed Aug 1, 2023
2 parents f6bffa4 + 614987a commit c71e136
Show file tree
Hide file tree
Showing 8 changed files with 956 additions and 233 deletions.
93 changes: 55 additions & 38 deletions crates/ide-assists/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
.filter(|it| !it.source_file_edits.is_empty() || !it.file_system_edits.is_empty())
.expect("Assist did not contain any source changes");
let mut actual = before;
if let Some(source_file_edit) = source_change.get_source_edit(file_id) {
if let Some((source_file_edit, snippet_edit)) =
source_change.get_source_and_snippet_edit(file_id)
{
source_file_edit.apply(&mut actual);
if let Some(snippet_edit) = snippet_edit {
snippet_edit.apply(&mut actual);
}
}
actual
};
Expand Down Expand Up @@ -191,9 +196,12 @@ fn check_with_config(
&& source_change.file_system_edits.len() == 0;

let mut buf = String::new();
for (file_id, edit) in source_change.source_file_edits {
for (file_id, (edit, snippet_edit)) in source_change.source_file_edits {
let mut text = db.file_text(file_id).as_ref().to_owned();
edit.apply(&mut text);
if let Some(snippet_edit) = snippet_edit {
snippet_edit.apply(&mut text);
}
if !skip_header {
let sr = db.file_source_root(file_id);
let sr = db.source_root(sr);
Expand Down Expand Up @@ -485,18 +493,21 @@ pub fn test_some_range(a: int) -> bool {
source_file_edits: {
FileId(
0,
): TextEdit {
indels: [
Indel {
insert: "let $0var_name = 5;\n ",
delete: 45..45,
},
Indel {
insert: "var_name",
delete: 59..60,
},
],
},
): (
TextEdit {
indels: [
Indel {
insert: "let $0var_name = 5;\n ",
delete: 45..45,
},
Indel {
insert: "var_name",
delete: 59..60,
},
],
},
None,
),
},
file_system_edits: [],
is_snippet: true,
Expand Down Expand Up @@ -544,18 +555,21 @@ pub fn test_some_range(a: int) -> bool {
source_file_edits: {
FileId(
0,
): TextEdit {
indels: [
Indel {
insert: "let $0var_name = 5;\n ",
delete: 45..45,
},
Indel {
insert: "var_name",
delete: 59..60,
},
],
},
): (
TextEdit {
indels: [
Indel {
insert: "let $0var_name = 5;\n ",
delete: 45..45,
},
Indel {
insert: "var_name",
delete: 59..60,
},
],
},
None,
),
},
file_system_edits: [],
is_snippet: true,
Expand All @@ -581,18 +595,21 @@ pub fn test_some_range(a: int) -> bool {
source_file_edits: {
FileId(
0,
): TextEdit {
indels: [
Indel {
insert: "fun_name()",
delete: 59..60,
},
Indel {
insert: "\n\nfn $0fun_name() -> i32 {\n 5\n}",
delete: 110..110,
},
],
},
): (
TextEdit {
indels: [
Indel {
insert: "fun_name()",
delete: 59..60,
},
Indel {
insert: "\n\nfn $0fun_name() -> i32 {\n 5\n}",
delete: 110..110,
},
],
},
None,
),
},
file_system_edits: [],
is_snippet: true,
Expand Down
Loading

0 comments on commit c71e136

Please sign in to comment.