Skip to content

Commit

Permalink
Fix formatter changing contents of multiline strings
Browse files Browse the repository at this point in the history
  • Loading branch information
DaelonSuzuka committed Nov 3, 2024
1 parent 25183e7 commit 22a5d63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/formatter/snapshots/leave_strings_alone.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# --- IN ---
func dump() -> String:
return """
{
level_file: '%s',
md5_hash: %s,
text: '%s',
level_size: %s,
world_pos: %s,
preview_size: %s,
preview_pos: %s,
preview_texture: %s,
explorer_layer: %s,
connections: %s,
}
"""
5 changes: 4 additions & 1 deletion src/formatter/textmate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ export function format_document(document: TextDocument, _options?: FormatterOpti
}
for (let i = 0; i < tokens.length; i++) {
// log.debug(i, tokens[i].value, tokens[i]);
if (i > 0 && tokens[i - 1].string === true && tokens[i].string === true) {
if (i === 0 && tokens[i].string) {
// leading whitespace is already accounted for
nextLine += tokens[i].original.trimStart();
} else if (i > 0 && tokens[i - 1].string && tokens[i].string) {
nextLine += tokens[i].original;
} else {
nextLine += between(tokens, i, options) + tokens[i].value.trim();
Expand Down

0 comments on commit 22a5d63

Please sign in to comment.