Skip to content

Commit 2a413a0

Browse files
committed
godoc/static: let client use vet check returned by /compile endpoint
(Forked off Yury Smolsky's CL 176618) With this change, the playground.js client now asks the server to do a vet check in the same HTTP request as the /compile (and run) step. If the server replies that it understands the request (VetErrors or VetOK in the repsonse), then the client can avoid the latency of a second HTTP roundtrip. We'll remove the /vet handler after we see it fall out of use from older clients. Updates golang/go#31970 Change-Id: I5b123883e19cbc6a8ec30c50705e6b945a4d322d Reviewed-on: https://go-review.googlesource.com/c/tools/+/176939 Reviewed-by: Andrew Bonventre <[email protected]>
1 parent d81a07b commit 2a413a0

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

godoc/static/playground.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function HTTPTransport(enableVet) {
117117
var playing;
118118
$.ajax('/compile', {
119119
type: 'POST',
120-
data: {'version': 2, 'body': body},
120+
data: {'version': 2, 'body': body, 'withVet': enableVet},
121121
dataType: 'json',
122122
success: function(data) {
123123
if (seq != cur) return;
@@ -132,21 +132,31 @@ function HTTPTransport(enableVet) {
132132
}
133133
return;
134134
}
135+
if (!data.Events) {
136+
data.Events = [];
137+
}
138+
if (data.VetErrors) {
139+
// Inject errors from the vet as the first events in the output.
140+
data.Events.unshift({Message: 'Go vet exited.\n\n', Kind: 'system', Delay: 0});
141+
data.Events.unshift({Message: data.VetErrors, Kind: 'stderr', Delay: 0});
142+
}
135143

136-
if (!enableVet) {
144+
if (!enableVet || data.VetOK || data.VetErrors) {
137145
playing = playback(output, data);
138146
return;
139147
}
140148

149+
// In case the server support doesn't support
150+
// compile+vet in same request signaled by the
151+
// 'withVet' parameter above, also try the old way.
152+
// TODO: remove this when it falls out of use.
153+
// It is 2019-05-13 now.
141154
$.ajax("/vet", {
142155
data: {"body": body},
143156
type: "POST",
144157
dataType: "json",
145158
success: function(dataVet) {
146159
if (dataVet.Errors) {
147-
if (!data.Events) {
148-
data.Events = [];
149-
}
150160
// inject errors from the vet as the first events in the output
151161
data.Events.unshift({Message: 'Go vet exited.\n\n', Kind: 'system', Delay: 0});
152162
data.Events.unshift({Message: dataVet.Errors, Kind: 'stderr', Delay: 0});

0 commit comments

Comments
 (0)