lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Parser gets confused by stray commas

Open emmericp opened this issue 1 year ago • 0 comments

Example:

L.FOO = "something",
L.BAR = "something else"

This triggers two unexpected diagnostics: err-equal-as-assign and redundant-value which is a bit confusing.

The reason is that it interprets this as that the user's intent was to write FOO, (some other var) = "something", BAR == "something else"

However, the actual error is a stray comma after the first line.

This error may sound a bit obscure, because why would add someone a stray comma? The answer is that this happened in a localization files where people who are not necessarily familiar with Lua are contributing translations. Sometimes these translations are given in table literals where they need to add commas after each line and sometimes they are given as a list of setfield statements...

This is probably not easy to fix because the parser's interpretation is completely valid until it encounteres the assignment...

emmericp avatar Mar 08 '24 19:03 emmericp