Skip to content

Triple Slash comments produce comment offset in generated files. #762

Closed

Description

@ehallander9591

protobuf.js version: 6.7.3

This is similar to an issue I had reported concerning, I think, a blank line before an enum offset the comments.

It would seem that a triple slash comment on the message definition line also causes subsequent triple slash comments to offset as well.

message Location {     /// A geo location on Earth
	float latitude = 1;  			/// Latitude in decimal degrees.  Must be >= -90.0 and <= 90.0
	float longitude = 2; 			/// Longitude in decimal degrees.  Must be >= -180.0 and <= 180.0
	int32 altitude_in_meters = 3; 	/// Altitude in meters above ground
}

produces the following

        /**
         * Constructs a new Location.
         * @exports mpxs.model.Location
         * @constructor
         * @param {mpxs.model.Location$Properties=} [properties] Properties to set
         */
        class Location {

            /**
             * Constructs a new Location.
             * @exports mpxs.model.Location
             * @constructor
             * @param {mpxs.model.Location$Properties=} [properties] Properties to set
             */
            constructor(properties?: mpxs.model.Location$Properties);

            /**
             * A geo location on Earth
             * @type {number}
             */
            public latitude: number;

            /**
             * Latitude in decimal degrees.  Must be >= -90.0 and <= 90.0
             * @type {number}
             */
            public longitude: number;

            /**
             * Longitude in decimal degrees.  Must be >= -180.0 and <= 180.0
             * @type {number}
             */
            public altitudeInMeters: number;

.
.
.
<please paste the stack trace of the error if applicable>

Activity

  1. ehallander9591 commented on Apr 18, 2017

    @ehallander9591
    Author

    It's probably fair to note that we will probably switch to having /** */ comments on the messages at some point anyway, but for now we have the simple /// line.

    Cheers

  2. dcodeIO commented on Apr 18, 2017

    @dcodeIO
    Member

    The parser looks at trailing comments only for non-block structures (anything that doesn't use { ... } blocks).

    You can see this here: https://github.com/dcodeIO/protobuf.js/blob/master/src/parse.js#L297

    In your example, this leads to misinterpretation where comments belong, which certainly needs some improvements in detecting compatible comment types. However, your first comment (message Location { /// A geo location on Earth) still won't work even with a fix for wrong offsets.

  3. ehallander9591 commented on Apr 18, 2017

    @ehallander9591
    Author

    We will change to the block comments which is what we should have used for the message anyway. I thought it might be related, but it only looked related.

    Cheers

  4. dcodeIO commented on Apr 18, 2017

    @dcodeIO
    Member

    This adds a little more knowledge about trailing comments to the parser. It should accept:

    /** Comment */
    message A { ...
    
    /// Comment
    message A { ...
    
    {
      string id = 1; /// Comment
    }
    

    plus, it prefers comments on top over trailing comments:

    {
      /// Preferred
      string id = 1; /// Discarded
    }
    

    and, of course, it shouldn't confuse trailing comments anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions