Skip to content

Fix Luau array access modifier formatting - #1148

Open
Companion wants to merge 1 commit into
JohnnyMorganz:mainfrom
Companion:fix/luau-array-access-modifier-spacing
Open

Fix Luau array access modifier formatting#1148
Companion wants to merge 1 commit into
JohnnyMorganz:mainfrom
Companion:fix/luau-array-access-modifier-spacing

Conversation

@Companion

Copy link
Copy Markdown

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.

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 })

1 participant