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

[4.0dev] GDScript - Mixed tabs and spaces not allowed in multiline declarations #49171

Closed
Tracked by #40488
nobuyukinyuu opened this issue May 28, 2021 · 10 comments · Fixed by #76286
Closed
Tracked by #40488

[4.0dev] GDScript - Mixed tabs and spaces not allowed in multiline declarations #49171

nobuyukinyuu opened this issue May 28, 2021 · 10 comments · Fixed by #76286

Comments

@nobuyukinyuu
Copy link
Contributor

nobuyukinyuu commented May 28, 2021

Godot version:

364ea7f

OS/device including version:

Windows 10 (20H2) x64

Issue description:

This issue is similar to the issue in #30937, except it might not be considered a regression as the language has had some fundamental changes between 3.x and 4.x. Multiline declarations such as arrays and dicts do not support the same multiline syntax as in 3.x, popping up an error about mixed tabs and spaces when writing these declarations in a way to align them to a user's screen. See example in next section, and the related issue for examples which still produce the issue in the new version of GDScript.

Steps to reproduce:
image

@fcole90
Copy link

fcole90 commented May 30, 2021

Workaround (tldr: only use spaces):
I think this issue could actually be much mitigated at the level of the text editor. Let's say that the indentation is set to 4 spaces, pressing TAB could actually add 4 spaces. In this way, we retain the comfort of adding such spaces in a quick way, but the error is much less likely to happen, as you would really need to copy/paste a \t for this to happen. Most modern editors such as VS Code and PyCharm do exactly that when writing in Python.

P.S.: I just realised how to set the text editor to achieve what I was suggesting.
In the top menu, find and press on Editor -> Editor Settings. It will open a new window and you will find on the left, the item Text Editor with subitem Indentation. There you can change Type from Tabs to Spaces. I recommend you leave Size to 4 and that you enable Draw Spaces.

@Calinou
Copy link
Member

Calinou commented May 30, 2021

@fcole90 The above report uses tabs for indentation but spaces for alignemnt. This is a common pattern to format code in programming. (You can see it with the indentation icons on the left which represent tabs, not spaces.)

The GDScript style guide uses tabs, so tabs will remain the default. Personally, I only use tabs ever (including for alignment), since I consider it to be less effort. However, some people like to use spaces to "complete" their alignment so that things are perfectly aligned.

@fcole90
Copy link

fcole90 commented May 30, 2021

@Calinou I know tabs take less effort, and that's why I was looking for a solution that achieves exactly that level of comfort. With my workaround, pressing TAB inserts 4 spaces, so you can just press TAB as you used to do, but 4 spaces will appear, hence keeping the same effect as proper tabs. I too use spaces to complete alignment, especially with dictionaries, lists or functions with many parameters, and this workaround really helped me into that. I have no tabs at all in my Python code but I achieve the same effect. I think, indeed, that Python forbids entirely mixing tabs and spaces in the same file (except for docstrings).

I would recommend revising the GDScript style guide then, as using just spaces in such a way could really improve everything.

Python3 indentation guidelines: https://docs.python.org/3/reference/lexical_analysis.html#indentation

P.S. I created a proposal to change the guidelines: godotengine/godot-proposals#2800

@name-here
Copy link

But many people will want to use tabs, and have actual tab characters show up in their source files and. Removing the ability to use actual tabs would be annoying. It's not just about tabs being easier to type or something.

@fcole90
Copy link

fcole90 commented May 30, 2021

Yes, my suggestion here is just a workaround, I never suggested tabs being removed from the language. At most I suggested spaces being the default 😉

@YuriSizov YuriSizov modified the milestones: 4.0, 4.x Feb 23, 2023
@nobuyukinyuu
Copy link
Contributor Author

nobuyukinyuu commented Mar 4, 2023

Just downloaded new 4.0 and see this is still an issue but appears to no longer have an explicit timeline for addressing it. Is the discussion tag for deciding if this is still considered a regression? (I'm encountering it again when migrating projects)

Edit: This also affects comment lines

@vnen vnen removed the discussion label Mar 6, 2023
@vnen
Copy link
Member

vnen commented Mar 6, 2023

I don't think this needs more discussion. It is a bug since the contents of a multiline expression should not consider indentation and it's a regression because it worked in 3.x.

Regarding the time to fix, there's only so much we can do in a certain time frame, some fixes will have to be postponed. I didn't even notice it was assigned to me until now TBH.

@MystMagus
Copy link
Contributor

MystMagus commented Mar 23, 2023

Changing the if (mixed) { around line 1100 in modules/gdscript/gdscript_tokenizer.cpp to if (mixed && !(line_continuation || multiline_mode)) { seems to be enough to solve it.

@vnen
Copy link
Member

vnen commented Apr 18, 2023

@MystMagus feel free to open a PR with your change BTW.

@MystMagus
Copy link
Contributor

Hope that's correct, have not contributed before.

@akien-mga akien-mga modified the milestones: 4.x, 4.1 Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants