mirror of
https://github.com/godotengine/godot-vscode-plugin.git
synced 2025-12-31 13:48:24 +03:00
Fix syntax highlighting edge cases (#350)
Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
@@ -5,6 +5,12 @@
|
||||
"scopeName": "source.gdscript",
|
||||
"name": "GDScript",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#nodepath_object"
|
||||
},
|
||||
{
|
||||
"include": "#nodepath_function"
|
||||
},
|
||||
{
|
||||
"include": "#base_expression"
|
||||
},
|
||||
@@ -159,24 +165,88 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"nodepath_object": {
|
||||
"name": "meta.literal.nodepath.gdscript",
|
||||
"begin": "(NodePath)\\s*(?:\\()",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "support.class.library.gdscript"
|
||||
}
|
||||
},
|
||||
"end": "(?:\\))",
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "[\\\"\\']",
|
||||
"end": "[\\\"\\']",
|
||||
"name": "constant.character.escape"
|
||||
}
|
||||
]
|
||||
},
|
||||
"nodepath_function": {
|
||||
"name": "meta.literal.nodepath.gdscript",
|
||||
"begin": "(get_node_or_null|has_node|find_node|get_node)\\s*(?:\\()",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "entity.name.function.gdscript"
|
||||
}
|
||||
},
|
||||
"end": "(?:\\))",
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "[\\\"\\']",
|
||||
"end": "[\\\"\\']",
|
||||
"name": "constant.character.escape"
|
||||
}
|
||||
]
|
||||
},
|
||||
"self": {
|
||||
"match": "\\bself\\b",
|
||||
"name": "variable.language.gdscript"
|
||||
},
|
||||
"base_expression": {
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#builtin_get_node_shorthand"
|
||||
},
|
||||
{
|
||||
"include": "#nodepath_object"
|
||||
},
|
||||
{
|
||||
"include": "#nodepath_function"
|
||||
},
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"include": "#keywords"
|
||||
},
|
||||
{
|
||||
"include": "#function-call"
|
||||
},
|
||||
{
|
||||
"include": "#comment"
|
||||
},
|
||||
{
|
||||
"include": "#self"
|
||||
},
|
||||
{
|
||||
"include": "#letter"
|
||||
},
|
||||
{
|
||||
"include": "#numbers"
|
||||
},
|
||||
{
|
||||
"include": "#builtin_func"
|
||||
},
|
||||
{
|
||||
"include": "#builtin_classes"
|
||||
},
|
||||
{
|
||||
"include": "#const_vars"
|
||||
},
|
||||
{
|
||||
"include": "#pascal_case_class"
|
||||
},
|
||||
{
|
||||
"include": "#line-continuation"
|
||||
}
|
||||
@@ -487,6 +557,32 @@
|
||||
]
|
||||
},
|
||||
"annotated-parameter": {
|
||||
"begin": "(?x)\n \\b\n ([[:alpha:]_]\\w*) \\s* (:)\n",
|
||||
"end": "(,)|(?=\\))",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "variable.parameter.function.language.gdscript"
|
||||
},
|
||||
"2": {
|
||||
"name": "punctuation.separator.annotation.gdscript"
|
||||
}
|
||||
},
|
||||
"endCaptures": {
|
||||
"1": {
|
||||
"name": "punctuation.separator.parameters.gdscript"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#base_expression"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.assignment.gdscript",
|
||||
"match": "=(?!=)"
|
||||
}
|
||||
]
|
||||
},
|
||||
"annotated-parameter2": {
|
||||
"begin": "(?x)\n \\b\n ([[:alpha:]_]\\w*) \\s* (:) \\s* ([[:alpha:]_]\\w*)? \\s* (=)? \\s* ([[:alpha:].0-9\\'\\\"_]*)?\n",
|
||||
"end": "(,)|(?=\\))",
|
||||
"beginCaptures": {
|
||||
@@ -512,10 +608,7 @@
|
||||
"5": {
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#numbers"
|
||||
},
|
||||
{
|
||||
"include": "#strings"
|
||||
"include": "#base_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -562,6 +655,85 @@
|
||||
"any-property": {
|
||||
"match": "(?<=[^.]\\.)\\b([A-Za-z_]\\w*)\\b(?![(])",
|
||||
"name": "variable.other.property.gdscript"
|
||||
},
|
||||
"function-call": {
|
||||
"name": "meta.function-call.gdscript",
|
||||
"comment": "Regular function call of the type \"name(args)\"",
|
||||
"begin": "(?x)\n \\b(?=\n ([[:alpha:]_]\\w*) \\s* (\\()\n )\n",
|
||||
"end": "(\\))",
|
||||
"endCaptures": {
|
||||
"1": {
|
||||
"name": "punctuation.definition.arguments.end.gdscript"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#function-name"
|
||||
},
|
||||
{
|
||||
"include": "#function-arguments"
|
||||
}
|
||||
]
|
||||
},
|
||||
"function-name": {
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#builtin_func"
|
||||
},
|
||||
{
|
||||
"include": "#builtin_classes"
|
||||
},
|
||||
{
|
||||
"comment": "Some color schemas support meta.function-call.generic scope",
|
||||
"name": "support.function.any-method.gdscript",
|
||||
"match": "(?x)\n \\b ([[:alpha:]_]\\w*) \\b\n"
|
||||
}
|
||||
]
|
||||
},
|
||||
"function-arguments": {
|
||||
"begin": "(\\()",
|
||||
"end": "(?=\\))(?!\\)\\s*\\()",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "punctuation.definition.arguments.begin.gdscript"
|
||||
}
|
||||
},
|
||||
"contentName": "meta.function-call.arguments.gdscript",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "punctuation.separator.arguments.gdscript",
|
||||
"match": "(,)"
|
||||
},
|
||||
{
|
||||
"match": "\\b([[:alpha:]_]\\w*)\\s*(=)(?!=)",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "variable.parameter.function-call.gdscript"
|
||||
},
|
||||
"2": {
|
||||
"name": "keyword.operator.assignment.gdscript"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.assignment.gdscript",
|
||||
"match": "=(?!=)"
|
||||
},
|
||||
{
|
||||
"include": "#base_expression"
|
||||
},
|
||||
{
|
||||
"match": "\\s*(\\))\\s*(\\()",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "punctuation.definition.arguments.end.gdscript"
|
||||
},
|
||||
"2": {
|
||||
"name": "punctuation.definition.arguments.begin.gdscript"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ puppet var e :int
|
||||
signal sig_a
|
||||
signal sig_b()
|
||||
signal sig_c(param1, param2)
|
||||
signal sig_d(param1: int, param2: Dictionary)
|
||||
signal sig_e(
|
||||
param1: int, # first param
|
||||
param2: Dictionary,
|
||||
)
|
||||
# signal sig_d(param1: int, param2: Dictionary)
|
||||
# signal sig_e(
|
||||
# param1: int, # first param
|
||||
# param2: Dictionary,
|
||||
# )
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
@@ -37,10 +37,46 @@ func get_g() -> int:
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
func func_a():
|
||||
func func_a(param1, param2, param3):
|
||||
self.test()
|
||||
$Node.get_node('Foo')
|
||||
$Node.has_node('Foo')
|
||||
$Node.find_node('Foo')
|
||||
$Node.get_node_or_null('Foo')
|
||||
print($Node.has_node('Foo'))
|
||||
print(NodePath('Foo'))
|
||||
print(NodePath("Foo"))
|
||||
pass
|
||||
|
||||
func func_b(param1, param2):
|
||||
func func_b(param1, param2=func_a(10, 1.0, 'test')) -> void:
|
||||
pass
|
||||
|
||||
func func_b1(param1 = false, param2: bool = false, param3 := false):
|
||||
pass
|
||||
|
||||
func func_b2(param1 = 10, param2: int = 100, param3 := 1000):
|
||||
pass
|
||||
|
||||
func func_b3(param1 = 1.0, param2: float = 10.0, param3 := 100.001):
|
||||
pass
|
||||
|
||||
func func_b4(param1 = 'foo', param2: String = 'bar', param3 := 'foobar'):
|
||||
pass
|
||||
|
||||
func func_b5(
|
||||
param1 = 'foo', # comment
|
||||
param2: String = 'bar',
|
||||
param3: float = 3.14159,
|
||||
param4:='foobar',
|
||||
param5:=1000,
|
||||
param6:=[],
|
||||
param7:={},
|
||||
param8:=func_a(),
|
||||
param9:=Vector2(0, 1),
|
||||
param10:=Vector2(0, 0),
|
||||
param11:=Color(1, 1, 1, 0.5),
|
||||
param12:=NodePath('Foo')
|
||||
) -> void:
|
||||
pass
|
||||
|
||||
var dict = {
|
||||
@@ -51,21 +87,20 @@ var dict = {
|
||||
|
||||
func func_c(
|
||||
param1: int = 10,
|
||||
param11,
|
||||
param2 := 1.0,
|
||||
param3: String = 'string',
|
||||
param4 := {a=0, b=0.0, c='test'},
|
||||
param4 := {a=0, b=0.0, c='test'}
|
||||
):
|
||||
pass
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
var h = "double quotes"
|
||||
var i = 'single quotes'
|
||||
var j = """
|
||||
var q = "double quotes"
|
||||
var r = 'single quotes'
|
||||
var s = """
|
||||
triple double quotes
|
||||
"""
|
||||
# var k = '''triple single quotes''' # this should be red because it's invalid
|
||||
var t = '''triple single quotes''' # this should be red because it's invalid
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user