
protobuf-dt - issue #111
Extensions and complete enum literal support for custom options
A few issues & fixes are bundled together here as they are interrelated and are better solved together...
What steps will reproduce the problem? 1. Custom Field options do not support various types of enum literals...
1) Literals present in MessageNotation / FieldNotation form (results in missing reference error)
import "descriptor.proto";
extend google.protobuf.FieldOptions { optional MyCustomOptionType myoptionfield = 50000; } message MyCustomOptionType { optional MyEnum myoptionfield = 1; } enum MyEnum { MyEnumLiteral = 1; } message MyMessage { optional int32 foo = 1 [(myoption)= { myoptionfield: MyEnumLiteral } ]; }
"MyEnumLiteral" results in an error
2) Option fields from other namespaces are not supported
import "descriptor.proto";
package firstfile;
extend google.protobuf.FieldOptions { optional MyCustomOptionType myoptionfield = 50000; } message MyCustomOptionType { optional MyEnum myoptionfield = 1; extensions 5 to 10; } enum MyEnum { MyEnumLiteral = 1; }
...
import "ExtensionInNotationFirstFile.proto";
package secondfile;
extend firstfile.MyCustomOptionType { optional MyNewEnum myextensionfield = 5; } enum MyNewEnum { MyNewEnumLiteral = 1; } message MyMessage { optional int32 foo = 1 [(myoption)= { [secondfile.myextensionfield]: MyNewEnumLiteral } ]; }
"[secondfile.myextensionfield]" results in a syntax error (QualifiedName was not used for the FieldNotation element, no '[<name>]' was included for extensions)
A hidden issue here is also that Enum Literals are not being pulled from imported files for MessageNotation... that is also taken care of in the provided fix.
What is the expected output? What do you see instead?
These valid proto files should not have any errors.
What version of the product are you using? On what operating system? 1.0.1 Windows 7 x64
Please provide any additional information below.
I've attached the three test files called out above.
I have also attaches an updated XText Grammar (only change is to FieldNotation) and an updated source file for com.google.eclipse.protobuf.scoping.ProtobufScopeProvider that correctly locates and uses Enum's for validation.
Notably, the solution provided in the Scope Provider may be an excellent start to complete MessageNotation validation as well as having actual references (hot-linked back to the correct field).
This solution does not update the UI Proposal Provider... I will have to take a look at that another day and update it to add content assist for Literals in MessageNotation.
Comment #1
Posted on Sep 13, 2011 by Grumpy Cat(No comment was entered for this change.)
Comment #2
Posted on Sep 13, 2011 by Grumpy Cat(No comment was entered for this change.)
Comment #3
Posted on Sep 14, 2011 by Grumpy RhinoSorry the test files were no good, i had a typo in there, fixed in the new upload.
Comment #4
Posted on Sep 14, 2011 by Grumpy RhinoUpdated the proposal provider to be consistent with validating / scoping...
needed two added components...
@Inject private ProtobufScopeProvider scopeProvider;
and
@Override public void completeLiteralRef_Literal(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { Enum enumType = scopeProvider.enumTypeOfOption(model); if (enumType != null) { proposeAndAccept(enumType, context, acceptor); return; } }
I also had to make ..."scopeProvider.enumTypeOfOption()" public to share access.
This definitely has the feel of a partial solution begging to be fully implemented for the rest of MessageNotation... I might take a shot at that when I have some free time unless someone else is already looking into solutions for that...
- ProtobufProposalProvider.java 18.79KB
Comment #5
Posted on Sep 14, 2011 by Grumpy RhinoTacking on two more issues to this issue... if preferred I can make separate issues but I tend to be of the "related issues in one issue > issue spam" court...
Repeated fields result in a syntax error in MessageNotation
using a repeated field such as
import "descriptor.proto";
extend google.protobuf.FieldOptions { optional MyCustomOptionType myoption = 50000; } message MyCustomOptionType { repeated int32 myrepeatedfield = 1; } message MyMessage { optional int32 foo = 1 [(myoption)= { myrepeatedfield: 12 , myrepeatedfield: 24 , myrepeatedfield: 48 } ];
results in a syntax error due to unique name enforcement by XText
This is fixed simply by not using the special "name" variable in XText: FieldNotation: (fieldName=QualifiedName | extension?='[' fieldName=QualifiedName ']') ':' value=SimpleRef;
Lack of commas between fields in MessageNotation result in a syntax error
Commas are not required between fields in message notation by protoc. This should be reflected in protobuf-dt.
optional int32 bar = 2 [(myoption)= { myrepeatedfield: 12 myrepeatedfield: 24 myrepeatedfield: 48 } ];
optional int32 badprogrammer = 3 [(myoption)= { myrepeatedfield: 12 myrepeatedfield: 24 , //this is still 'valid'... myrepeatedfield: 48 } ];
Simple fix is to make commas optional...
MessageNotation:
'{'
fields+=FieldNotation (','? fields+=FieldNotation)*
'}'
;
- Protobuf.xtext 4.33KB
- ProtobufScopeProvider.java 15.35KB
Comment #6
Posted on Sep 14, 2011 by Grumpy RhinoAlso, I updated to the 1.0.2 release - the changes had no effect on the problem nor solution.
Comment #7
Posted on Sep 14, 2011 by Grumpy RhinoAs an added note here, with these proposed changes implemented all valid message notation in custom options should be free of errors in the editor. That is not to say that all message notation will be properly validated - invalid notation could still appear valid (use int instead of string, etc).
Comment #8
Posted on Sep 15, 2011 by Grumpy RhinoCorrection to my previous note... nested message types in custom options are not supported by the grammar. This issue is addressed separately in https://code.google.com/p/protobuf-dt/issues/detail?id=121
Comment #9
Posted on Sep 30, 2011 by Grumpy RhinoI believe this issue and solution are superseded by https://code.google.com/p/protobuf-dt/issues/detail?id=125 and should be closed / rejected if and when that addresses the issues raised here.
Comment #10
Posted on Sep 30, 2011 by Grumpy RhinoI believe this issue and solution are superseded by https://code.google.com/p/protobuf-dt/issues/detail?id=125 and should be closed / rejected if and when that addresses the issues raised here.
Comment #11
Posted on Oct 12, 2011 by Grumpy CatPostponing fix to next release.
Comment #12
Posted on Oct 18, 2011 by Grumpy Cat(No comment was entered for this change.)
Comment #13
Posted on Nov 3, 2011 by Grumpy Cat(No comment was entered for this change.)
Comment #14
Posted on Nov 22, 2011 by Grumpy CatFixed as Issue 155. I started working on full support of custom options based on bugs filed internally at Google, as I kept working on it I ended fixing this issue as well.
r3bc2f7ac4c7c, r96a713437062, r3216303da8e9, reca7b70fcd9a, r2f429441e726, r90b9a83fd09c, r12ee03ab3bfb, r5268fff7f929, rc209d861a5b7, rde0f3163a72d, r170e19933ee3, rb7bf6780440a, rfdb47648d534, r60501de66435
Status: Fixed
Labels:
Type-Defect
Priority-Medium
Milestone-Release-1.0.13