godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.53k stars 151 forks source link

Single-line scopes are confused for type annotations #449

Closed migmoog closed 1 year ago

migmoog commented 1 year ago

Godot version

3.5stable

VS Code version

1.64.2

Godot Tools VS Code extension version

1.3.1

System information

Windows 10

Issue description

the syntax highlighter reads one-line scopes as type annotations for variables, which highlights any keyword or symbol without an accompanying operator or syntax as a type.

As seen in vscode: image

Steps to reproduce

Paste the following in vscode

# example
extends Node

func fn() -> void:
    for i in 3:
        #keywords are confused
        if i == 2: continue

    var foo = 3
    # seems to be confusing these as a var declaration with the colon and equal sign
    if foo < 4: foo = 12
    if foo == 3: return

    # same thing for match statements
    var bar = 1
    match bar:
        0: bar = 1
        1: return

# functions simply don't highlight single-line scopes 
func one_line_int_fn() -> int: return 3
func one_line_print() -> void: print("Uh oh")
func one_line_fn() -> void: return
DaelonSuzuka commented 1 year ago

Very interesting. Thank you for the report and the example code.

This is what your example looks like on the master branch for me. Everything inside fn() (lines 265-280) looks correct to me.

The single-line functions at the bottom are definitely wrong, so I'll see if I can fix that.

image

migmoog commented 1 year ago

I'm testing this with a Godot 3.5 project with the current state of master and it looks fine, just like your screenshot. Might be something specific to the current release and will be amended once 1.4.0 is done. The single line functions however are the same as in your example though

DaelonSuzuka commented 1 year ago

That's excellent, thank you very much for confirming. This fix will be in PR #441, so whenever I finish that you should be able to grab a new dev build.

DaelonSuzuka commented 1 year ago

Fixed in #441:

image