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

Fix indentation in script templates #78675

Merged
merged 1 commit into from
Aug 2, 2023

Conversation

AThousandShips
Copy link
Member

@AThousandShips AThousandShips commented Jun 25, 2023

Uses a variation on the code from CodeEdit, works well in my testing, also fixes the parsing of meta-space-indent which was not updated and used the wrong spacing and error message

Would be useful to be able to unify the code but the code for CodeEdit turns one type of indentation into another instead of turning two types of indentation into one special sequence

@capnm
Copy link
Contributor

capnm commented Jun 25, 2023

If possible, you could add some unit tests.

@AThousandShips
Copy link
Member Author

AThousandShips commented Jun 25, 2023

I'm not sure that's possible this is specific to the editor interface

AFIK it's just not possible to do unit testing on the editor UI and stuff, and it wouldn't be easy to even do so as it is an internal function like this, I don't think there's any unit tests for any Editor components, but I might be wrong

@capnm
Copy link
Contributor

capnm commented Jun 25, 2023

Purely theoretical: Copy test-template to Project/script_templates/Node/.
Call godot --script create_script.gd (??) and compare the generated new_script.gd with the expected result.

@AThousandShips
Copy link
Member Author

You can't do that from CLI, this is specific to the editor UI, the ScriptCreateDialog

editor/script_create_dialog.cpp Outdated Show resolved Hide resolved
editor/script_create_dialog.cpp Outdated Show resolved Hide resolved
@akien-mga akien-mga modified the milestones: 4.1, 4.2 Jun 26, 2023
@akien-mga akien-mga added the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Jun 26, 2023
}
script_template.content += line.replace("\t", "_TS_") + "\n";
script_template.content += line.substr(i) + "\n";
Copy link
Member Author

@AThousandShips AThousandShips Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To deal with empty lines or lines that are just whitespace, this matches the pre-first non-whitespace character behavior of the old code, and also matches generally the behavior of converting indentation on save

Could simplify it and merge all spaces and combine them at the end but I think this is better

Copy link
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this but it looks good to me.

if (line.begins_with("space-indent")) {
String indent_value = line.substr(17, -1).strip_edges();
if (line.begins_with("space-indent:")) {
String indent_value = line.substr(13).strip_edges();
if (indent_value.is_valid_int()) {
int indent_size = indent_value.to_int();
if (indent_size >= 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (indent_size >= 0) {
if (indent_size > 0) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to change the original support for not converting spaces to indentation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, just suggested as it looks like a mistake.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is a mistake it should have an error, but I think it's intentional to simply prevent spaces to be used as indentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the option is not available for tabs. I don't think this is an intentional feature, but I'm not asking you to change it.

Copy link
Member Author

@AThousandShips AThousandShips Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, will see, thank you for your feedback!

There was a check for the value non-zero in the original code so it was at least not a simple error of taking >= over > in the original code.

Will add an error though as it doesn't error out if you have a negative number

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me.

@akien-mga akien-mga merged commit 2331eab into godotengine:master Aug 2, 2023
13 checks passed
@AThousandShips AThousandShips deleted the template_fix branch August 2, 2023 10:49
@akien-mga
Copy link
Member

Thanks!

@AThousandShips
Copy link
Member Author

Thank you!

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.3.

@YuriSizov YuriSizov removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Oct 19, 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 this pull request may close these issues.

Groups of spaces in scripts automatically changing into tabs/indentation
5 participants