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
Merged

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

@murgatroid99 murgatroid99 commented Jun 12, 2020

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

Loading

@recih
Copy link
Contributor Author

@recih 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"

Loading

@recih
Copy link
Contributor Author

@recih recih commented Jun 19, 2020

@murgatroid99 will you review my PR, please ❤️

Loading

@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
9 checks passed
Loading
@recih recih deleted the better_comment_parse branch Jun 27, 2020
taylorcode added a commit to taylorcode/protobuf.js that referenced this issue 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants