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

Corrected 'add_callback' for Signal Connection to Prevent Incorrect Number of New Lines #33666

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Eoin-ONeill-Yokai
Copy link
Contributor

@Eoin-ONeill-Yokai Eoin-ONeill-Yokai commented Nov 16, 2019

As originally reported by KoBeWi #33287 -- With code end-line behavior added in #29262, it's sometimes possible for the wrong number of new lines to be created depending on the number of new lines at the end of the document.

Now, it will try to find the last line with valid content and add the appropriate number of spaces according to the GDScript standard (2 new lines between each function.) This should bring more consistency to the user experience. For files with ridiculous amount of whitespace at the end of the document, there's a cutoff of 50 lines.

@Eoin-ONeill-Yokai Eoin-ONeill-Yokai force-pushed the add_callback_doublespace_correction branch from 3fba24a to 417befe Compare November 17, 2019 00:03
@Eoin-ONeill-Yokai Eoin-ONeill-Yokai changed the title Corrected 'add_callback' On Signal Addition to Prevent Double New Lines Corrected 'add_callback' for Signal Connection to Prevent Double New Lines Nov 17, 2019
@Calinou
Copy link
Member

Calinou commented Nov 17, 2019

I'm not sure about this, as the GDScript style guide recommends separating functions with two blank lines (like in Python). However, we can still make a check to avoid separating functions with more than two blank lines.

@Eoin-ONeill-Yokai
Copy link
Contributor Author

Ah yeah that's a good point. Well I could update it to reflect that (so that 2 lines don't become 3, for instance.)

Basically, the operation should always try to maintain ideal spacing between functions regardless of the amount of blank space at the end of the document.

@Eoin-ONeill-Yokai Eoin-ONeill-Yokai changed the title Corrected 'add_callback' for Signal Connection to Prevent Double New Lines Corrected 'add_callback' for Signal Connection to Prevent Incorrect Number of New Lines Nov 17, 2019
@Eoin-ONeill-Yokai
Copy link
Contributor Author

In fact, I will go ahead and update this so that all new functions added conform to the GDScript guidelines with a single new line at the end of the document.

@Eoin-ONeill-Yokai Eoin-ONeill-Yokai force-pushed the add_callback_doublespace_correction branch from 417befe to a2e1a32 Compare November 17, 2019 03:40
@Eoin-ONeill-Yokai
Copy link
Contributor Author

@Calinou Thanks for that feedback -- that's a good call and I should have double-checked the gdscript coding standards before pushing this upstream.

I've made changes that still address the concern of unwanted extra space after the last function. Now we can fetch the last line with actual content in it (non-empty line) and insert the appropriate number of new lines (2 lines).

Somewhat related to this, I actually feel that the number of preemptive new lines should be fetched from the scripts' language (via script->get_language()->lines_between_functions() akin to how function text is generated) so that the languages actually specify the standard of how many new lines we should be making.

@akien-mga akien-mga added this to the 4.0 milestone Nov 21, 2019
@KoBeWi
Copy link
Member

KoBeWi commented Dec 11, 2019

I'm not sure about this, as the GDScript style guide recommends separating functions with two blank lines (like in Python).

How about making this optional? I use one line and expect the dialog to do the same.

@Eoin-ONeill-Yokai
Copy link
Contributor Author

Eoin-ONeill-Yokai commented Jun 22, 2020

I'm not sure about this, as the GDScript style guide recommends separating functions with two blank lines (like in Python).

How about making this optional? I use one line and expect the dialog to do the same.

Anybody have an additional thoughts on this?

Also, should I add the above proposed function to the Language api?

@aaronfranke
Copy link
Member

aaronfranke commented Jul 1, 2020

@KoBeWi IMO, Godot should always follow the language standards when modifying script files. If you use one line between functions in your project, it is very easy to simply erase the extra line that Godot creates :)

@Eoin-ONeill-Yokai When you get a chance, this needs to be rebased on the latest master branch. While there are no conflicts, rebasing is important so that reviewers can easily test the PR.

@Eoin-ONeill-Yokai
Copy link
Contributor Author

@Eoin-ONeill-Yokai When you get a chance, this needs to be rebased on the latest master branch. While there are no conflicts, rebasing is important so that reviewers can easily test the PR.

Yeah no worries, I'll rebase it this weekend.

@Eoin-ONeill-Yokai Eoin-ONeill-Yokai force-pushed the add_callback_doublespace_correction branch from a2e1a32 to 265a861 Compare July 5, 2020 22:10
@Eoin-ONeill-Yokai
Copy link
Contributor Author

@aaronfranke I've gone ahead and rebased this patch. Did some light testing and nothing seems to be broken since implementation.

@Eoin-ONeill-Yokai Eoin-ONeill-Yokai force-pushed the add_callback_doublespace_correction branch 3 times, most recently from 0a29496 to 584bd58 Compare August 1, 2020 03:43
@Eoin-ONeill-Yokai Eoin-ONeill-Yokai force-pushed the add_callback_doublespace_correction branch from 584bd58 to 23fcd17 Compare August 31, 2020 04:15
…s are always made.

This patch will always add the appropriate number of spaces after the
last valid line of a code file and all new functions added always
conform to the gdscript formatting standard.
@Eoin-ONeill-Yokai Eoin-ONeill-Yokai force-pushed the add_callback_doublespace_correction branch from cd59194 to bbb8c7e Compare January 1, 2021 07:28
@YuriSizov YuriSizov requested a review from a team August 24, 2021 22:25
@akien-mga akien-mga modified the milestones: 4.0, 4.x Jul 26, 2022
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.

None yet

5 participants