Skip to content

Fix Luau array access modifier formatting - #1148

Merged
JohnnyMorganz merged 2 commits into
JohnnyMorganz:mainfrom
Companion:fix/luau-array-access-modifier-spacing
Oct 3, 2026
Merged

JohnnyMorganz merged 2 commits into
JohnnyMorganz:mainfrom
Companion:fix/luau-array-access-modifier-spacing

Conversation

@Companion

Copy link
Copy Markdown
Contributor

Fixes #1126

Problem

StyLua removes the separator between read or write access modifiers and element types in Luau array shorthand:

type A = { read Service }
type B = { write Service }

This was formatted as:

type A = { readService }
type B = { writeService }

The output still parses, but refers to different types and changes the meaning of the code. Multiline forms could also misplace indentation, while a single line comment between the modifier and element could swallow the element type.

Change

Preserve the required separator after array access modifiers and route multiline indentation to the modifier when it is the first token of the element.

Trailing single line comments are terminated with a newline and the element type receives the correct indentation. Width calculations exclude trivia and count exactly one required separator, preventing types near the column limit from wrapping early.

Property and indexer access modifiers remain unchanged.

Testing

Added Luau snapshot coverage for:

  • Single line read and write array types
  • Multiline array types and comment preservation
  • Comments between the modifier and element type
  • Excess whitespace normalization
  • Property, indexer and unmodified array controls
  • Types immediately below and above the column width boundary

The fixed output passes --verify and is idempotent. Luau and all feature tests were run alongside rustfmt and clippy. The existing seven Windows specific LSP path test failures were identical on clean main and the changed branch.

@Companion

Copy link
Copy Markdown
Contributor Author

@JohnnyMorganz can you check this please?

@JohnnyMorganz JohnnyMorganz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@JohnnyMorganz
JohnnyMorganz enabled auto-merge (squash) October 3, 2026 17:15
@JohnnyMorganz
JohnnyMorganz merged commit 4bc44dc into JohnnyMorganz:main Oct 3, 2026
21 checks passed
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.

Luau: read/write modifier in array types merges into the element type, changing code meaning ({ read Foo } -> { readFoo })

2 participants