godotengine / godotengine/godot-vscode-plugin
Add special cases for UPPERCASE classes in GDScript syntax-coloring (`JSON`, `UPNP`, etc); and color `super` as a keyword
- Dominant language
- TypeScript
- Stars
- 2.1k
- Forks
- 257
- PR merge metrics
- No merged PRs in 30d
Description
### Godot version
4.3.stable
### VS Code version
1.96.0 codium snap
### Godot Tools VS Code extension version
2.3.0
### System information
Ubuntu 24.04
### Issue description
Opening an issue for the suggestion here https://github.com/godotengine/godot-vscode-plugin/pull/739#discussion_r1809465674 so it's not forgotten, as @DaelonSuzuka seems to agree.
It seems GDScript doesn't currently support semantic coloring, so it uses certain heuristics, like coloring UPPERCASE identifiers as constants. This is good enough for the majority of cases, but there's a few exceptions in Godot built-in classes that are somewhat easy to track.
These classes are known to be using UPPERCASE-only identifiers, exceptionally:
- `JSON` (constructible with new)
- `UPNP` (constructible with new)
- `OS`
- `IP`
- `JSONRPC`
- `XRVRS`
Since it's a very small list, it's easy to add them to `GDScript.tmLanguage.json` under `pascal_case_class` as exceptions, so they are matched as classes rather than constants. All 6 above should be added. If not, at least the first 2, which are constructible with new, and so it's extra weird to color them as constants.
https://github.com/godotengine/godot-vscode-plugin/blob/2e9117870dc0866925df947d963355ece7a32e14/syntaxes/GDScript.tmLanguage.json#L447-L450
---
Also, please move `super` away from `builtin_classes`, as it's a keyword, not a class.
It can be called like `super(arg1, arg2)` as well as `super.my_base_method(etc)`, and both of these semantics are different from a class, specially from a basic Variant type.
If even `void` is a keyword, then `super` should surely not be a type.
More importantly, it raises an error when used as an identifier, unlike built-in class names. So it's a keyword.
https://github.com/godotengine/godot-vscode-plugin/blob/2e9117870dc0866925df947d963355ece7a32e14/syntaxes/GDScript.tmLanguage.json#L439-L442
### Steps to reproduce
```gdscript
func wrong_coloring() -> void:
var data_to_send: PackedStringArray = ["a", "b", "c"]
var json_string: String = JSON.stringify(data_to_send)
var json: JSON = JSON.new()
var error: Error = json.parse(json_string)
var upnp: UPNP = UPNP.new()
upnp.discover()
upnp.add_port_mapping(7777)
```
```gdscript
func expected_coloring() -> void: # For comparison
var regex: RegEx = RegEx.new()
regex.compile("\\w-(\\d+)")
var regex2: RegEx = RegEx.create_from_string("\\w-(\\d+)")
```
Contributor guide
Assessment
This issue has not been assessed yet.