SublimeText / PackageDev

Tools to ease the creation of snippets, syntax definitions, etc. for Sublime Text.
MIT License
436 stars 83 forks source link

Warn wrong dict/list type mistakes in .sublime-syntax #299

Closed jfcherng closed 4 years ago

jfcherng commented 4 years ago

@genericptr is a newbie learning .sublime-syntax and he encountered a "weird" situation that his rule was not working at all. (chat: https://discord.com/channels/280102180189634562/280157083356233728/733181451616518184)

  main:
    - match: \b(?i:(function|procedure)+)\b\s+(\w+)
      captures:
        - 1: keyword.control.pascal
        - 3: entity.name.function.pascal

It took me a while to figure out that he was using a list in captures rather than a dict. Or sometimes similarly, people may wrongly do meta_scope: rather than - meta_scope: etc...


It could be a common mistake and could be hard to find out at the first glance. So I guess it would be good if those dict/list mistakes can be warned.

genericptr commented 4 years ago

I would be excellent if we got syntax errors in this situation, like we do for other errors when we save the file. It should be obvious to anyone paying close enough attention but it slipped past me as I was still learning the syntax.

FichteFoll commented 4 years ago

Ultimately, ST should complain about this problem when parsing the syntax definition as it has a proper parser and knows the types of any structure. I find it weird that it wouldn't complain for this kind of error (which I just checked, it doesn't), so we should probably raise this upstream.

For the record, most other errors, such as forgetting the - before meta_scope, correctly trigger an error message.

FichteFoll commented 4 years ago

Moved to https://github.com/sublimehq/sublime_text/issues/3475.