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

Indentation errors loading space indented project into tab indented editor #35007

Open
Tracked by #40488
lawnjelly opened this issue Jan 11, 2020 · 4 comments
Open
Tracked by #40488

Comments

@lawnjelly
Copy link
Member

Godot version:
Godot 3.2 beta 5

OS/device including version:
Linux Mint 18.2

Issue description:
When testing a project from an unrelated issue (#34963) I encountered a parse error when loading the project: Parser Error: Mixed tabs and spaces in indentation

The author had used the Godot IDE in space indentation mode, and my IDE was set to tabs (with 4 spaces to a tab).

When running the project, my editor auto-converted each group of 4 spaces to tabs, however, this caused problems because the authored file contained 'odd' numbers of spaces.

This means that projects authored as space indented cannot be currently guaranteed to work in tab indented editor. It is also painful to manually fix this problem.

Steps to reproduce:
By trial and error I figured out the problem occurs in the following situation:

...if true:
....print("hello")

This parses and runs fine when using spaces. However when auto converting to tabs, the first line is used as is with spaces, however the second line is converted to a tab, which then triggers the mixed tabs and spaces in indentation error.

Minimal reproduction project:
TabsSpaces.zip

If you load the minimal project when your editor is set to spaces, it will work. If you load it when the IDE is set to tabs, it will error with the parse error.

@lawnjelly
Copy link
Member Author

lawnjelly commented Jan 11, 2020

One way of fixing this may be to keep track of the indentation per line, instead of doing a fixed 4 spaces = tab conversion.

Thus

...if true:
.....print("hello")

becomes (regardless of the number of spaces)

[tab]if true:
[tab][tab]print("hello")

However this may require a more intelligent converter. This would also be more robust because at present the results depend on your 'number of spaces per tab' setting.

@burstina
Copy link

becomes (regardless of the number of spaces)

[tab]if true:
[tab][tab]print("hello")

This solution is good, it would also correct indentatinon to a more consistent result.
However each coder's brain has his own way of getting oriented in the code, so there are different real world cases where people use "[tab][space]" indentation to achieve visual arrangement he likes.

As an example:
supposte you have size set to 3 spaces in indent editor settings and you load a script like that:

...if (xx ==  yy or
.......yy ==  zz or
.......zz == jj):

converter does this:

[tab]if (xx ==  yy or
[tab][tab][tab]yy ==  zz or
[tab][tab][tab]zz == jj):

output:

   if (xx ==  yy or
         yy ==  zz or
         zz == jj):

It could not be an issue if "we don't care, learn to do this not", it is going to be an issue when many people work at the same project:
Figure somebody has size set to 3, somebody else set to 4 and somebody else again has set indent to spaces: try to think the same script being modified a lot by different people. what kind of mess would come out?

@KoBeWi
Copy link
Member

KoBeWi commented Nov 27, 2020

Seems still valid in 3.2.4 beta2

@aXu-AP
Copy link
Contributor

aXu-AP commented May 26, 2022

Just ran into this bug while testing out variety addons from asset library. As I have a habit of inspecting a few scripts from newly installed addons, indentations on some addon got screwed up when I tried to run.

Another, easier way to solve this would be aborting convertion if strange-sized indentation was found. It's not ideal, but at least it won't corrupt scripts like it currently does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants