bungcip / better-toml

toml extension for vs code editor
74 stars 13 forks source link

Whitespace sensitive commas in inline tables #19

Open lylemoffitt opened 5 years ago

lylemoffitt commented 5 years ago

I've noticed that spaces preceding commas in inline tables seem to create problems for the formatter. Notably, that everything starting with the comma until the next table item is formatted as plain-text (unformatted).

Take this example from from the spec.

name = { first = "Tom", last = "Preston-Werner" }
# This works fine.
point = { x = 1, y = 2 }
animal = { name = "pug" }

But if I put a space between the value "Tom" and the comma, it breaks. Everything is unformatted up to the table item point

name = { first = "Tom" , last = "Preston-Werner" }
#                     ^ space here makes everything following formatted as plain text
# This comment and above are formatted as plain text
# Item after this line returns to correct highlighting
point = { x = 1, y = 2 }
animal = { name = "pug" }

This seems to be independent of the value type. It also breaks for integer values.

name = { first = "Tom" , last = "Preston-Werner" }
point = { x = 1 , y = 2 }
#              ^ space here also also breaks the formatter
# This comment and above are formatted as plain text
animal = { name = "pug" }

This bug seems to only apply inside inline tables, and not between them. For example, if i turn point into an array of inline tables, the comma spacing doesn't seem to be affected.

name = { first = "Tom", last = "Preston-Werner" }

# Objects in arrays seem to be fine
point = [ {x = 1} , {y = 2} ]
#                ^ This space does not cause a problem

animal = { name = "pug" }

Better TOML: v0.3.2 VS Code: v1.30.2 OSX: v10.14.2