Skip to content
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

(protobuf) service definition seems to break highlighting #2351

Closed
YamiOdymel opened this issue Jan 14, 2020 · 10 comments · Fixed by #2388
Closed

(protobuf) service definition seems to break highlighting #2351

YamiOdymel opened this issue Jan 14, 2020 · 10 comments · Fixed by #2388
Assignees
Labels
bug help welcome Could use help from community language

Comments

@YamiOdymel
Copy link

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;
}
@joshgoebel
Copy link
Member

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

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

@YamiOdymel
Copy link
Author

@joshgoebel joshgoebel added bug language help welcome Could use help from community labels Jan 15, 2020
@joshgoebel
Copy link
Member

@YamiOdymel Thanks so much!

@joshgoebel joshgoebel changed the title Incorrect gRPC / Protobuf highlighting (protobuf) service definition seems to break highlighting Jan 15, 2020
@joshgoebel
Copy link
Member

joshgoebel commented Jan 31, 2020

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

@YamiOdymel
Copy link
Author

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

example from: golang/protobuf#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;
  }
}

@joshgoebel
Copy link
Member

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?

@YamiOdymel
Copy link
Author

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: "*"
		};
	}
}

@joshgoebel
Copy link
Member

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 ;.

@YamiOdymel
Copy link
Author

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.

@joshgoebel
Copy link
Member

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.

@joshgoebel joshgoebel self-assigned this Feb 1, 2020
joshgoebel added a commit to joshgoebel/highlight.js that referenced this issue Feb 2, 2020
joshgoebel added a commit that referenced this issue Feb 6, 2020
* fix(protobuf) Fix `rpc` when followed by a block

Resolves #2351.
taufik-nurrohman pushed a commit to taufik-nurrohman/highlight.js that referenced this issue Feb 18, 2020
* fix(protobuf) Fix `rpc` when followed by a block

Resolves highlightjs#2351.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants