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

GDScript: Fix doc comment parsing (newlines and spaces) #75043

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

dalexeev
Copy link
Member

@dalexeev dalexeev commented Mar 17, 2023

  • Do not add an extra space after [br].
  • Do not add an extra space at the end of codeblock.
  • Fix text overlapping after [/codeblock].
  • More correct processing of codeblocks.
  • @tutorial and blank line no longer resets in_codeblock in class doc comment.
## Line
## Continue[br]
## New Line
## [codeblock]
## if true:
##     print(42)
## [/codeblock]
## Test
func test():
    pass

Before:

After:

Another test:

## Line
## Continue[br]
## New Line[br]
## Test[br]Test
## [codeblock]
## test
## test[br]
## test[br]test
##
## @tutorial
## [/codeblock]
## test

Closes #76815.

@dalexeev dalexeev requested a review from a team as a code owner March 17, 2023 21:52
@dalexeev dalexeev force-pushed the gds-fix-doc-comment-parsing branch from 64584c4 to 1664b3d Compare March 17, 2023 21:53
@akien-mga
Copy link
Member

CC @anvilfolk

@dalexeev dalexeev force-pushed the gds-fix-doc-comment-parsing branch from 1664b3d to 3d43c68 Compare May 9, 2023 17:06
@anvilfolk
Copy link
Contributor

I keep meaning to give this one a review but everyone in my household is currently sick and I'm not super familiar with this part of the code. Some comments would be lovely, explaining what the functions do, why some ints used in for start at 2, etc :)

I didn't know [codeblock] could be used in docstrings, that's very cool!

@dalexeev
Copy link
Member Author

The main problem that this PR solves is the correct detection of line join, depending on whether the current line is inside [codeblock][/codeblock] or not, and also whether the previous line ends with [br] or not.

  • Outside codeblock:
    • If the text is empty, line join is empty.
    • If the previous line ends with [br], line join is empty.
    • Otherwise line join is one space.
    • Extra spaces must be removed.
  • Inside codeblock:
    • All spaces and newlines must be kept as is (except for the initial indent after ##).

For example, the following comment

## Line
## Continue[br]
## New Line[br]
## Test[br]Test
##   Test
## [codeblock]
## test
## test[br]
##     test[br]test
## [/codeblock]
## test

should be converted to

Line Continue[br]New Line[br]Test[br]Test Test
[codeblock]
test
test[br]
    test[br]test
[/codeblock]
test

Also, although this is not a recommended syntax, the following comment

## aaa[codeblock]bbb[/codeblock]ccc[codeblock]ddd[/codeblock]eee

should be converted to

aaa
[codeblock]
bbb
[/codeblock]
ccc
[codeblock]
ddd
[/codeblock]
eee

I recommend "Hide whitespace" to make diff easier.

@dalexeev dalexeev force-pushed the gds-fix-doc-comment-parsing branch from 3d43c68 to 430f0c8 Compare June 5, 2023 09:40
@dalexeev
Copy link
Member Author

dalexeev commented Jun 5, 2023

Added check for [code][/code] (for example [code][codeblock][/code]).

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.

LGTM, though TIWAGOS. I haven't reviewed in depth but it's also touching a non-critical part of the parser (only affects editor behavior) so it seems fairly safe to me to merge.

@anvilfolk
Copy link
Contributor

anvilfolk commented Jun 5, 2023

My apologies - I said I'd try to take a look but didn't. I am absolutely swamped with childcare and nightschool. I am definitely too tired to make sense of this right now.

The only thing I would say is that my personal preference is for a few more in-code comments. For instance, I would love to know ta a glance what the difference is between DOC_LINE_IN_CODE and DOC_LINE_IN_CODE_BLOCK. I assume it's the back-quote vs the actual [codeblock]?, thus allowing back-quotes to have multiline strings?

I'm taking a super quick look now to look for minor things since I definitely can't currently make sense of the logic, but I wouldn't really stop that from merging.

@dalexeev dalexeev force-pushed the gds-fix-doc-comment-parsing branch from 430f0c8 to 049a49c Compare June 5, 2023 13:00
@dalexeev
Copy link
Member Author

dalexeev commented Jun 5, 2023

For instance, I would love to know ta a glance what the difference is between DOC_LINE_IN_CODE and DOC_LINE_IN_CODE_BLOCK. I assume it's the back-quote vs the actual [codeblock]?, thus allowing back-quotes to have multiline strings?

DOC_LINE_IN_CODE - in [code][/code]
DOC_LINE_IN_CODEBLOCK - in [codeblock][/codeblock]

@anvilfolk
Copy link
Contributor

For instance, I would love to know ta a glance what the difference is between DOC_LINE_IN_CODE and DOC_LINE_IN_CODE_BLOCK. I assume it's the back-quote vs the actual [codeblock]?, thus allowing back-quotes to have multiline strings?

DOC_LINE_IN_CODE - in [code][/code] DOC_LINE_IN_CODEBLOCK - in [codeblock][/codeblock]

You're right, once I finally got through parsing some of the code it wasn't so hard to find :)

@akien-mga akien-mga merged commit bcdf3fe into godotengine:master Jun 6, 2023
@akien-mga
Copy link
Member

Thanks!

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.

Multi-line class documentation comments begin with an extra space
6 participants