SublimeText / PackageDev

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

Add command to autogenerate syntax tests for line of code. #341

Closed Thom1729 closed 2 years ago

Thom1729 commented 3 years ago

Example:

// SYNTAX TEST "Packages/JavaScript/JavaScript.sublime-syntax"

    if ( true ) { }

Result (with "syntax_test.suggest_scope_suffix": false):

// SYNTAX TEST "Packages/JavaScript/JavaScript.sublime-syntax"

    if ( true ) { }
//  ^^^^^^^^^^^^^^^ meta.conditional
//  ^^ keyword.control.conditional.if
//     ^^^^^^^^ meta.group
//     ^ punctuation.section.group.begin
//       ^^^^ constant.language.boolean.true
//            ^ punctuation.section.group.end
//              ^^^ meta.block
//              ^ punctuation.section.block.begin
//                ^ punctuation.section.block.end

Could probably use a key binding or something, but the implementation should be pretty much good.

Thom1729 commented 3 years ago

I added some code to make some tests for nested scopes more compact.

Before:

    42
//  ^^ meta.number.integer.decimal
//  ^^ constant.numeric.value

After:

    42
//  ^^ meta.number.integer.decimal constant.numeric.value
FichteFoll commented 3 years ago

That looks really nice. I'm going to give this a test run in hopefully the next week and work on another release.

Just wondering how we could make this command more accessible than just in the command palette without being obstrusive.

Thom1729 commented 3 years ago

I think it would make sense to bind it to control-enter or something. Do we have a context key for determining whether the view is a syntax test? If not, it would be easy to add. I see that there is one.

FichteFoll commented 2 years ago

The compacting code didn't work for me, but after some fiddling I was able to find the bugs and squash them. This will be included in the next release. I'm working on the changelog already. :rocket:

https://user-images.githubusercontent.com/931051/155862272-474a919a-1303-43aa-8e5c-af545f716bfe.mp4

Edit: no release today, though