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: Added support for RPC #2414

Merged
merged 2 commits into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions components/prism-protobuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
var builtinTypes = /\b(?:double|float|[su]?int(?:32|64)|s?fixed(?:32|64)|bool|string|bytes)\b/;

Prism.languages.protobuf = Prism.languages.extend('clike', {
'class-name': {
pattern: /(\b(?:enum|extend|message|service)\s+)[A-Za-z_]\w*(?=\s*\{)/,
lookbehind: true
},
'keyword': /\b(?:enum|extend|extensions|import|message|oneof|option|optional|package|public|repeated|required|reserved|service|syntax|to)\b/
'class-name': [
{
pattern: /(\b(?:enum|extend|message|service)\s+)[A-Za-z_]\w*(?=\s*\{)/,
lookbehind: true
},
{
pattern: /(\b(?:rpc\s+\w+|returns)\s*\(\s*(?:stream\s+)?)\.?[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*(?=\s*\))/,
lookbehind: true
}
],
'keyword': /\b(?:enum|extend|extensions|import|message|oneof|option|optional|package|public|repeated|required|reserved|returns|rpc(?=\s+\w)|service|stream|syntax|to)\b(?!\s*=\s*\d)/,
'function': /[a-z_]\w*(?=\s*\()/i
});

Prism.languages.insertBefore('protobuf', 'operator', {
'map': {
pattern: /\bmap<\s*[\w.]+\s*,\s*[\w.]+\s*>(?=\s+[A-Za-z_]\w*\s*[=;])/,
pattern: /\bmap<\s*[\w.]+\s*,\s*[\w.]+\s*>(?=\s+[a-z_]\w*\s*[=;])/i,
alias: 'class-name',
inside: {
'punctuation': /[<>.,]/,
Expand All @@ -21,14 +28,14 @@
},
'builtin': builtinTypes,
'positional-class-name': {
pattern: /(?:\b|\B\.)[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*(?=\s+[A-Za-z_]\w*\s*[=;])/,
pattern: /(?:\b|\B\.)[a-z_]\w*(?:\.[a-z_]\w*)*(?=\s+[a-z_]\w*\s*[=;])/i,
alias: 'class-name',
inside: {
'punctuation': /\./
}
},
'annotation': {
pattern: /(\[\s*)[A-Za-z_]\w*(?=\s*=)/,
pattern: /(\[\s*)[a-z_]\w*(?=\s*=)/i,
lookbehind: true
}
});
Expand Down
2 changes: 1 addition & 1 deletion components/prism-protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/languages/protobuf/keyword_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public
repeated
required
reserved
returns
rpc LotsOfReplies(
service
stream
syntax
to

Expand All @@ -31,7 +34,12 @@ to
["keyword", "repeated"],
["keyword", "required"],
["keyword", "reserved"],
["keyword", "returns"],
["keyword", "rpc"],
["function", "LotsOfReplies"],
["punctuation", "("],
["keyword", "service"],
["keyword", "stream"],
["keyword", "syntax"],
["keyword", "to"]
]
Expand Down
68 changes: 68 additions & 0 deletions tests/languages/protobuf/rcp_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse);
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
rpc BidiHello(stream HelloRequest) returns (stream HelloResponse);
rpc CancelOperation(CancelOperationRequest) returns (google.protobuf.Empty) {
option (google.api.http) = { post: "/v1/{name=operations/**}:cancel" body: "*" };
}

----------------------------------------------------

[
["keyword", "rpc"],
["function", "LotsOfReplies"],
["punctuation", "("],
["class-name", "HelloRequest"],
["punctuation", ")"],
["keyword", "returns"],
["punctuation", "("],
["keyword", "stream"],
["class-name", "HelloResponse"],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "rpc"],
["function", "BidiHello"],
["punctuation", "("],
["keyword", "stream"],
["class-name", "HelloRequest"],
["punctuation", ")"],
["keyword", "returns"],
["punctuation", "("],
["keyword", "stream"],
["class-name", "HelloResponse"],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "rpc"],
["function", "CancelOperation"],
["punctuation", "("],
["class-name", "CancelOperationRequest"],
["punctuation", ")"],
["keyword", "returns"],
["punctuation", "("],
["class-name", "google.protobuf.Empty"],
["punctuation", ")"],
["punctuation", "{"],
["keyword", "option"],
["punctuation", "("],
"google",
["punctuation", "."],
"api",
["punctuation", "."],
"http",
["punctuation", ")"],
["operator", "="],
["punctuation", "{"],
" post",
["punctuation", ":"],
["string", "\"/v1/{name=operations/**}:cancel\""],
" body",
["punctuation", ":"],
["string", "\"*\""],
["punctuation", "}"],
["punctuation", ";"],
["punctuation", "}"]
]

----------------------------------------------------

Check for RPC definitions.