godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.55k stars 166 forks source link

Incorrect newline indentation level when there is a preceding code block with greater indentation #219

Closed ghost closed 7 months ago

ghost commented 4 years ago

Steps to reproduce:

  1. following code:

    func testfunc():
    for x in 5:
        for y in 10:
            for z in 20:
                pass
    
    var tmp = 5
  2. move cursor to line before var tmp = 5

  3. press enter

  4. newline will indent to the same level as pass, when it should indent to same level as var tmp = 5

linkpy commented 3 years ago

Well... This comes from the limitation of the language configuration :

https://github.com/godotengine/godot-vscode-plugin/blob/8115fba3672a128fcd60d0c3bcee049898785ff7/configurations/gdscript-configuration.json#L25-L28

These lines define how indentation works with a GDScript file, but there is no way to define a deindentation rule that would fix the issue (since here the rule needs to do 4 deindent, and a rule can only do one). So to fix that issue :

Let me know what you think of this.

Shatur commented 3 years ago

we can switch the language definition to use a more complex definition format, like Tree Sitter, which is a huge amount of work.

It would be awesome.

we can remove these lines, and thus removing automatic indentation. Without it, VSCode fallsback to automatic indentation by using brackets. The user still have to manually indent (once, VSCode remembers the last indentation level and indents newlines to it) and deindent.

But this is okay too. I currently disabled language-provided indentation in my workflow.

Vlad-Zumer commented 3 years ago

Might be fixable by using onEnterRules in the gdscript-configuration.json. Will have a look soon.

DaelonSuzuka commented 7 months ago

The indent/dedent rules have been modified since this was posted, and with godot-tools 2.0.0 I think it behaves correctly now (or at least better).

I also don't think there's any room for improvement, given the limitations @linkpy outlined.

(Speaking of @linkpy, if you actually know how to implement tree-sitter in a vscode extension please hit me up...)