Skip to content

Formatter discards comments in blocks #9940

Description

@elijahimmer

This is my first bug report, if I did anything wrong just tell me so I can fix it and know for next time.

This was all done on revision e98a812

Currently, roc fmt removes comments in many cases when formatting blocks (be they code blocks, lists, or records)

Examples:

test = |{}| {
   # Some informational comment on why this is empty
}

turning into:

test = |{}| {}

or

w = { a: 10
# test
 }

turning into:

w = {
	a: 10,
}

This is particularly relevant with things that are inline:

platform ""
	requires {}
	exposes [
		# Stderr,
		# EventQueue,
		# Duration,
	]
	packages {
		# This is where all the package stuff goes
	}
	provides {
		"roc_init": init_for_host!,
		# "roc_generate": generate_for_host!,
	 }
	hosted { "hosted_stderr_line": Stderr.line!,
	#"hosted_event_queue_enqueue": EventQueue.enqueue!
	}
	targets: {
		inputs_dir: "targets/",
		x64mac: { inputs: ["libhost.a", app] },
		arm64mac: { inputs: ["libhost.a", app] },
		x64musl: { inputs: ["crt1.o", "libhost.a", app, "libc.a"] },
		arm64musl: { inputs: ["crt1.o", "libhost.a", app, "libc.a"] },
		x64win: { inputs: ["host.lib", app] },
		arm64win: { inputs: ["host.lib", app] },
	}

Formats into:

platform ""
	requires {}
	exposes []
	packages {}
	provides { "roc_init": init_for_host! }
	hosted { "hosted_stderr_line": Stderr.line! }
	targets: {
		inputs_dir: "targets/",
		x64mac: { inputs: ["libhost.a", app] },
		arm64mac: { inputs: ["libhost.a", app] },
		x64musl: { inputs: ["crt1.o", "libhost.a", app, "libc.a"] },
		arm64musl: { inputs: ["crt1.o", "libhost.a", app, "libc.a"] },
		x64win: { inputs: ["host.lib", app] },
		arm64win: { inputs: ["host.lib", app] },
	}

Notability, uncommenting any combination of the three exposes will preserve the entire block and it's comments.

I imagine these are all different cases in the formatter, and I can try to look into it more and split up the issue into solitary issues. There are also likely more cases then these.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions