Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lua] Add support for a few new syntax features introduced in Lua 5.4 and a couple improvements. #2693

Merged
merged 7 commits into from
Jan 28, 2021

Conversation

Ultra-Instinct-05
Copy link
Contributor

This PR

  1. Adds support for the new const and to-be-closed variables, introduced in Lua 5.4. The syntax is a bit weird IMO, but it is what it is.
  2. Previously, Lua used to have a 4th level scope to identify true vs false i.e. constant.language.boolean.true for true & constant.language.boolean.true for false (which is anyways wrong). Now, it reduces it to only constant.language.boolean since there is very little value in having the previous scopes.
  3. Adds meta.string scope to strings to comply with the scope naming guidelines. I have also reworked the string contexts to actually push or set into named contexts instead of anonymous contexts for a better debugging experience (since it is currently not possible to distinguish between anonymous contexts in the show_scope_name popup).
  4. Lua 5.4 also introduces coroutine.close(). Support is added for that function.
  5. The scopes in which snippets are triggered are now more stringent and I have excluded strings & comments since it makes least sense to expand snippets in those scopes anyways.

Lua 5.4 introduces the concept of `const` & to-be-closed variables.

1. A `const` variable is a variable whos value cannot be changed after
   initialization. The syntax is a bit weird, though.
2. A to-be-closed variable behaves like a constant local variable, except
   that its value is closed whenever the variable goes out of scope,
   including normal block termination, exiting its block by
   break/goto/return, or exiting by an error.
   (The definition is taken from the official Lua docs
   https://www.lua.org/manual/5.4/manual.html#3.3.8)
Previously, the Lua syntax assigned a fourth level scope, true or false
to identify between `true` & `false` (`false` again was wrongly scoped
as `constant.language.boolean.true.lua`).

I don't think it is really beneficial in having a 4th level scope to
identify `true` vs `false` since most people will only want to have one
color assigned to these boolean constants.
This commit adds the `meta.string` scope as per the scope naming
guidelines and also `set`(s) into named string contexts instead of
anonymous contexts to enhance debugging experience since it's currently
not possible to know the state of anonymous contexts in the
`show_scope_name` popup.

All the tests have been updated.
Lua 5.4 adds a new API endpoint for the `coruotine` library i.e. `close`.
This commit adds support for it.
This commit excludes snippets from being triggered in comments & strings
since they are least likely to be used in comments & strings anyways.
Lua/Lua.sublime-syntax Outdated Show resolved Hide resolved
Lua/Lua.sublime-syntax Outdated Show resolved Hide resolved
Lua/Lua.sublime-syntax Outdated Show resolved Hide resolved
Lua/tests/syntax_test_lua.lua Outdated Show resolved Hide resolved
@Thom1729
Copy link
Collaborator

& constant.language.boolean.true for false (which is anyways wrong)

I'd just like to apologize for this.

Lua/Lua.sublime-syntax Outdated Show resolved Hide resolved
Lua/Lua.sublime-syntax Outdated Show resolved Hide resolved
Lua/Lua.sublime-syntax Outdated Show resolved Hide resolved
@Ultra-Instinct-05
Copy link
Contributor Author

& constant.language.boolean.true for false (which is anyways wrong)

I'd just like to apologize for this.

There was no need for apologizing at all. It's just something I noticed so decided to fix it.

@Ultra-Instinct-05
Copy link
Contributor Author

I believe I have addressed all of the review comments. Let me know if any of them are wrong or more corrections needs to be done.

Lua/Lua.sublime-syntax Outdated Show resolved Hide resolved
@Ultra-Instinct-05
Copy link
Contributor Author

Thanks for the review. I have addressed both of the issues.

@wbond wbond merged commit d2105a7 into sublimehq:master Jan 28, 2021
@wbond
Copy link
Member

wbond commented Jan 28, 2021

Thanks for your fixes here @Ultra-Instinct-05! As always, thank you for the reviews @FichteFoll and @deathaxe!

@Ultra-Instinct-05 Ultra-Instinct-05 deleted the lua_5.4_features branch January 28, 2021 04:12
Ultra-Instinct-05 added a commit to Sublime-Instincts/PackageDev that referenced this pull request Sep 17, 2021
This commit adds `boolean` & `null` to the `constant.language` scope
data. There were a few PR's regarding this.

1. sublimehq/Packages#2788
2. sublimehq/Packages#2785
3. sublimehq/Packages#2693
FichteFoll pushed a commit to SublimeText/PackageDev that referenced this pull request Oct 7, 2021
This commit adds `boolean` & `null` to the `constant.language` scope
data. There were a few PR's regarding this.

1. sublimehq/Packages#2788
2. sublimehq/Packages#2785
3. sublimehq/Packages#2693
mitranim pushed a commit to mitranim/Packages that referenced this pull request Mar 25, 2022
… and a couple improvements. (sublimehq#2693)

* [Lua] Add support for `const` & to-be-closed variables.

Lua 5.4 introduces the concept of `const` & to-be-closed variables.

1. A `const` variable is a variable whos value cannot be changed after
   initialization. The syntax is a bit weird, though.
2. A to-be-closed variable behaves like a constant local variable, except
   that its value is closed whenever the variable goes out of scope,
   including normal block termination, exiting its block by
   break/goto/return, or exiting by an error.
   (The definition is taken from the official Lua docs
   https://www.lua.org/manual/5.4/manual.html#3.3.8)

* [Lua] Fix a mistake with scoping boolean language constant.

Previously, the Lua syntax assigned a fourth level scope, true or false
to identify between `true` & `false` (`false` again was wrongly scoped
as `constant.language.boolean.true.lua`).

I don't think it is really beneficial in having a 4th level scope to
identify `true` vs `false` since most people will only want to have one
color assigned to these boolean constants.

* [Lua] Add `meta.string` scope and push|set to named contexts.

This commit adds the `meta.string` scope as per the scope naming
guidelines and also `set`(s) into named string contexts instead of
anonymous contexts to enhance debugging experience since it's currently
not possible to know the state of anonymous contexts in the
`show_scope_name` popup.

All the tests have been updated.

* [Lua] Add support for `coroutine.close()`.

Lua 5.4 adds a new API endpoint for the `coruotine` library i.e. `close`.
This commit adds support for it.

* [Lua] Exclude snippets from being triggered in comments & strings.

This commit excludes snippets from being triggered in comments & strings
since they are least likely to be used in comments & strings anyways.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants