How to match a leading_comments value with the protobuf entity it is written next to?

3 views
Skip to first unread message

Rémy Léone

unread,
Feb 27, 2020, 3:48:04 AM2/27/20
to Protocol Buffers
Hello,

I want to match a leading_comments value with the related protobuf entity it is written next to.
Let suppose that I got the following protobuf:

syntax = "proto3";

enum Greeting {
    NONE = 0;
    MR = 1;
    MRS = 2;
    MISS = 3;
}

// Documentation for the message
message Hello {
    // Documentation for the greeting field
    Greeting greeting = 1;
    // Documentation for the name
    string name = 2;
}


I'm using protoc and writing a short plugin that looks like this: https://gist.github.com/remyleone/54725a5be6d152a406929036512981e4

It generates a request.txt that I print:


What I don't know is how to match the comments with the related protobuf entity. I'm not sure about how to use location with its span and path. Is there any helper to do the matching? Or a tutorial?

Do you know how to do this? Could I do with go?

Best regards

Rémy
Reply all
Reply to author
Forward
0 new messages