Highlight.js: (protobuf) service definition seems to break highlighting

Created on 14 Jan 2020  路  10Comments  路  Source: highlightjs/highlight.js

A service definition became a non-closed function that cause the comment is not well highlighted. (the // The request message containing the user's name. part)

image

The original picture without DOM tooltip.

image

The example code is from the official example.

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}
bug help welcome language

All 10 comments

Would it be possible to get this as a jsfiddle reproducible sample please? You can use my template:

https://jsfiddle.net/ajoshguy/qhpL58ec/

@YamiOdymel Thanks so much!

Don't you need a ; to end the rpc line? What are the line ending rules for protobuf?

It seems like when a line ended with a }, the ; can be omitted.

example from: https://github.com/golang/protobuf/issues/205

package example;

enum FOO { X = 17; }

message Test {
  required string label = 1;
  optional int32  type  = 2 [default=77];
  repeated int64  reps  = 3;
  optional group OptionalGroup = 4 {
    required string RequiredField = 5;
  }
  oneof union {
    int32  number = 6;
    string name   = 7;
  }
}

All the examples I find look like:

service StatsService {
    rpc Push(PushRequest) returns (PushResponse);
}

What is the {} doing there? I'm not sure i Understand this syntax well enough yet to suggest a proper fix. Can you show me some additional variants of what rpc can look like or point me to some samples?

Well, I think it's a little bit complex, but I've seen people put the metadata in the {}.

https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/proto/examplepb/stream.proto

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "examples/proto/examplepb/a_bit_of_everything.proto";
import "examples/proto/sub/message.proto";

// Defines some more operations to be added to ABitOfEverythingService
service StreamService {
    rpc BulkCreate(stream ABitOfEverything) returns (google.protobuf.Empty) {
        option (google.api.http) = {
            post: "/v1/example/a_bit_of_everything/bulk"
            body: "*"
        };
    }
    rpc List(google.protobuf.Empty) returns (stream ABitOfEverything) {
        option (google.api.http) = {
            get: "/v1/example/a_bit_of_everything"
        };
    }
    rpc BulkEcho(stream grpc.gateway.examples.sub.StringMessage) returns (stream grpc.gateway.examples.sub.StringMessage) {
        option (google.api.http) = {
            post: "/v1/example/a_bit_of_everything/echo"
            body: "*"
        };
    }
}

Screen Shot 2020-02-01 at 6 34 23 AM

Screen Shot 2020-02-01 at 6 36 21 AM

How does that look? We could just end the function when we hit either a ; or {... right now it only counts ;.

Oh, that looks great.

I'd also like to ask, will it also be highlighted as well if I put the metadata inside of the {}? It's fine if it doesn't since it's another issue.

I'd also like to ask, will it also be highlighted as well if I put the metadata inside of the {}? It's fine if it doesn't since it's another issue.

It would be highlighted with whatever rules were typically used for code inside a {} block. The function part would still be highlighted the same.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vad1mo picture Vad1mo  路  7Comments

gskinner picture gskinner  路  4Comments

zhouxy666 picture zhouxy666  路  3Comments

kkeundotnet picture kkeundotnet  路  3Comments

Suyash2810 picture Suyash2810  路  8Comments