elzr / vim-json

A better JSON for Vim: distinct highlighting of keywords vs values, JSON-specific (non-JS) warnings, quote concealing. Pathogen-friendly.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

another missing comma error syntax

itchyny opened this issue · comments

There are some error syntax which the syntax file does not warn us.
First case:

[
  { "object1": 1 }
  { "object2": 2 }
]

should be

[
  { "object1": 1 },
  { "object2": 2 }
]

Second case:

{
  "object1": []
  "object2": []
}

should be

{
  "object1": [],
  "object2": []
}

Also missing comma after literals like true/false, {}.

{
  "object1": true
  "object2": 2
}

@itchyny
This is affected by the "syn regions" on line 90. I made this change to mine to get it working:
CaptSpify@9d2fa59

Thanks @itchyny and @CaptSpify. I had known about these unhighlighted cases but frankly they were something of a pain to deal with because of how Vim won't allow you to reuse a keyword or a region as part of a match. In other words, it seemed to be either I highlighted these edge cases or I recognized true/false and {} & [] regions properly (important for folding).

Anyway, I finally found a way to do both. It adds some regex complexity but hopefully nothing that will hurt performance.

Added these new cases to the test file json-test.json. This is what you should see:
image

Works nice. Thank you @elzr.

@elzr
I ran into the same issues trying to fix it, which is why I did the hacky work-around.
Good stuff. I'll test it out tomorrow, thanks!