ksprojects / protobuf-jetbrains-plugin

Protobuf Support for JetBrains IDEs
https://plugins.jetbrains.com/plugin/8277
Apache License 2.0
259 stars 45 forks source link

Support using `optional` in proto3 #160

Open ByteGen opened 3 years ago

ByteGen commented 3 years ago

Describe the bug Since protoc version 3.15, it enabled the use of optional in proto3 by default. See field_presence. But this plugin still reports errors when using optional.

To Reproduce Steps to reproduce the behavior:

syntax = "proto3";
message Msg {
  optional int32 foo = 1;
}

Expected behavior No error, no warning.

Screenshots image

Plugin (please complete the following information):

Additional context The check action may be as follows:

    private void checkFieldLabelProto3(FieldNode field) {
        Optional<FieldLabel> fieldLabel = field.getFieldLabel();
        fieldLabel.ifPresent(label -> {
            if (label == FieldLabel.OPTIONAL
                    || label == FieldLabel.REQUIRED) {
                String message = message("error.illegal.field.label", label.getName());
                markError(field.getFieldLabelNode(), null, message);
            }
        });
    }
davidmankin commented 3 years ago

Yes please! I was under the mistaken impression that proto3 doesn't support has_field for primitives, until I found out that they added support as long as the field is marked optional. Now that I want to use it, I have this amazing plugin complaining about my .protos.

FWIW I have the same issue in v 0.13 (and some recent reviews on IJ marketplace complain about the same).