-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
FR: Text proto format could support multi-line strings #1297
Comments
+1 this idea (whatever syntax it takes). Having the ability to write free-flowing text in the text protobuf is great for people who want to use protobufs but still have it be human readable when you have multiline text. |
FWIW, we did actually implement this as a crappy pre-processor over text proto (using the It also will do a python-style something: <
description: <<EOM
this
would
naturally be a
multiline string
EOM
...
> Which would be the equivalent of: something: <
description: "this\nwould\nnaturally be a\n multiline string"
...
> (note the beautiful indentation and lack of weird prefix spaces in the translated version 😉) |
Hmm...it does appear to be an option, but it's discouraged. I don't know the reasoning for it. |
This would be a great feature, we're looking at needing to do large blocks of text in a proto for api documentation, and it would be great to do this! In lieu of this we'll probably make a preprocessor as @riannucci is using, but that is much less elegant. Thanks! |
+1 for this. |
+1 again. |
So, what's the process to getting this implemented? Does someone simply submit a PR? |
I'm going to take a stab at this. I'm going to use backticks. Not sure when, or if, I'll get this done. Feel free to ping me. |
So, using backticks was a breeze to implement, but I realized it’s a huge pain for people who want to embed multi-line markdown strings. The current tokenizer only looks ahead one character; I suspect that this is why there's been no movement on this feature request. I’m extending it to look ahead three characters to accommodate triple single and double quotes. |
Multi-line string value is already supported as far as I can tell, see: You will need to format it like this:
Probably not as convenient as the proposed ones, but it's also less magical (i.e., don't magically remove indentation and line wraps here and there). @maguro Before you put more work into it, please make sure someone on protobuf-team is supportive of this feature (+a few other team members @acozzette @liujisi ). |
The unit test I understand that that one can use a list of multi-part strings with each part suffixed with My proposal is not to remove indentation, etc. Whatever is in the string is what you get; any formatting can and should be done after compilation. It also is backward compatible. I posted my comments are several weeks ago and the ticket is several years old. How can we proceed in a more timely manner? |
For changes that will affect multiple languages, there needs to be a formal proposal and it needs to be approved before proceeding. There is no fast path and the process is Google internal only. This change unfortunately falls into this category and has to be carried through by a Google engineer. It doesn't need to be a protobuf team member though. If you are a Google engineer and is motivated enough to push this feature through all the proto text parsers in Google, feel free to send us a proposal doc. When the proposal is approved, we will accept code changes (from anyone, internally or on github). For external contributors, your best bet is probably to convince someone in Google to go through the process on your behalf. My personal take on this proposal is that it doesn't provide enough benefit to justify the effort. To me multi-line strings aren't so different from multi-part strings, and there are a lot of text proto parsers we need to update if we are to support it. |
What are "text proto parsers"? |
@maguro Protobuf implementations that support text format apparently have implemented such parsers. Some implementations are opensourced (as in this github repository), but many of them are not and only exist inside Google. Also protobuf implementations are not the only text proto parsers. We have tools that process/convert/format text protos. For example, if you check-in a text proto file in our internal code base, a tool will parse and format the file according to a formatting guideline, which by the way has specific rules about how to format multi-part strings. |
So, these tools parse raw proto source files? If that is the case, then if a proto file did not use the new multi-line string, then they should be fine, correct? |
@maguro If nobody uses the new multi-line string, they will be fine. |
So, there doesn't seem to be a problem on that front then; if there is then one could add a flag to turn it off. I'll try to find a Google engineer to shepherd this on your side. FWIW, I really don't how one would prefer
over the much cleaner
|
Good news. I got a Google manager to shepherd this. I was also able to maintain the zero-copy stream semantics. I'll try to get the patch submitted later this week, more likely the weekend. |
From your example, what would this become?
Would the description be: And what about this?
|
It would be the latter. The compiler should not make any asssumptions about the intentions of the author. |
What is the conclusion on this? Does this feature get implemented? |
Yeah, let me dust this off and chat w/ our lawyers. |
Ok, as you can see above, it supports both backtick and triple-double-quotes to delimit multiline strings. I'm just making that clear. |
Coming from a Python background, I was surprised by the backtick syntax. Then I read about the JavaScript Template Strings. But wouldn't it be confusing for users, since this is not really a template? |
One is free to use Seriously though, I'm not married to backticks and I'm happy to remove them if that's the consensus here. |
Interested in this. @maguro was this agreed on internally inside of google in the end? For others, more info here: #1297 (comment) |
Please first sign cla for #6078 to move further. |
@maguro, I'm a little confused that what you are describing, as well as the PR (#6078) is about adding a new syntax for multi-line string literals in the protobuf source syntax. However, this issue is about adding multi-line string literal support to the protobuf text format. I guess you only looked at changing the compiler since that is the only piece that can be changed without impacting all of the languages/runtimes (which all have their own implementation of the text format)? |
Ahh, yeah. Sorry about the confusion; mea culpa. The problem I need to solve is on the compiler end. |
Would be a great value add in developer experience to have this feature! |
As stated above, unfortunately this work will not be prioritized by the protobuf team in the near future. |
In a text proto file like:
It would be awesome if we could e.g.:
This could be used for e.g. attaching markdown documentation to configuration entries which could then be displayed nicely. I'm not 100% on backticks (implies quoting in the parser)... Other things like a bash style
<<EOM .... EOM
demarcation could also work and would be easier to parse.Thoughts?
The text was updated successfully, but these errors were encountered: