Skip to content

Conversation

@JohnnyMorganz
Copy link
Owner

@JohnnyMorganz JohnnyMorganz commented Apr 29, 2021

This PR implements a Shape struct, which contains information about the current amount of width left to format in a given line.
This allows us to provide contextual position information for each formatter, to improve the decisions made about when to format.

This greatly improves the formatting based on column width, and we no longer need to rely on taking away arbitrary values to make to code "fit".

TODO:

  • Hang binary expressions before expanding them. We should try to hang binary expressions, rather than keeping them on the same line and expanding e.g. a function call.
    e.g.
EquippedLocalConfiguration = Tool:FindFirstChild("Configuration")
		or WeaponFunction:InvokeServer("InitialiseTool", Tool)
-- vs.
EquippedLocalConfiguration = Tool:FindFirstChild("Configuration") or WeaponFunction:InvokeServer(
	"InitialiseTool",
	Tool
)
  • Reformat binary expressions once they are hung. Currently, if a binary expression is hung, the expressions aren't collapsed back onto a single line if possible. Need to combine formatting and hanging together into one function.
  • Look into improving "formatting tactics" in places. E.g. for assignments we should attempt the following four tactics in order: 1) format on single line, 2) hang a binary expression, 3) hang at the equals sign, 4) expand code onto multiple lines.
  • Update changelog

Fixes #78

@JohnnyMorganz JohnnyMorganz marked this pull request as ready for review April 29, 2021 20:52
@JohnnyMorganz JohnnyMorganz merged commit c5cc7fa into master Apr 30, 2021
@JohnnyMorganz JohnnyMorganz deleted the shape branch April 30, 2021 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Turns readable multi-line function calls into harder to read, single line ones, but are under the column width

2 participants