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

feat: better comment parse #1419

Merged
merged 5 commits into from
Jun 26, 2020

Conversation

recih
Copy link
Contributor

@recih recih commented Jun 9, 2020

  1. fix trailing comment in last line can be recognized as leading comment for current field by mistake.
  2. new preferTrailingComment option in IParseOptions, user can choose the priority of trailing comments and leading commnets
  3. test updated.

@murgatroid99
Copy link
Contributor

Can you explain a bit more what the incorrect previous behavior was and how your fix changes it?

@recih
Copy link
Contributor Author

recih commented Jun 15, 2020

Can you explain a bit more what the incorrect previous behavior was and how your fix changes it?

message Example {
  /// leading comment A
  a = 1; /// trailing comment A
  b = 2; /// trailing comment B
}

when there is no extra new line between two fields, you will get Example.fields['b'].comment === "trailing comment A", the trailing comment of field a is considered as the leading comment of field b, which makes no sense.

after my fix, you will get:

Example.fields['a'].comment === "leading comment A"
Example.fields['b'].comment === "trailing comment B"

also there is an option preferTrailingComment, when its true, you will get:

Example.fields['a'].comment === "trailing comment A"
Example.fields['b'].comment === "trailing comment B"

@recih
Copy link
Contributor Author

recih commented Jun 19, 2020

@murgatroid99 will you review my PR, please ❤️

@alexander-fenster alexander-fenster changed the title Better comment parse fix: better comment parse Jun 26, 2020
@alexander-fenster alexander-fenster changed the title fix: better comment parse feat: better comment parse Jun 26, 2020
@alexander-fenster alexander-fenster merged commit 7fd2e18 into protobufjs:master Jun 26, 2020
@recih recih deleted the better_comment_parse branch June 27, 2020 17:22
taylorcode pushed a commit to taylorcode/protobuf.js that referenced this pull request Oct 16, 2020
* fix trailing comment in last line recognized as leading comment for current token.

* add preferTrailingComment to IParseOptions

Co-authored-by: Alexander Fenster <fenster@google.com>
This was referenced May 20, 2022
@github-actions github-actions bot mentioned this pull request Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants