Skip to content

Commit f975935

Browse files
committed
gopls/internal/lsp: update telemetry prompt and add a follow-up message
Update the telemetry prompt per discussion, and add a follow up message with more information after telemetry is enabled. For golang/go#62576 Change-Id: If03cade72b27a765da43db293c74d53d19b95a9c Reviewed-on: https://go-review.googlesource.com/c/tools/+/530459 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 64beb95 commit f975935

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

gopls/internal/lsp/prompt.go

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const (
2828
TelemetryPromptWorkTitle = "Checking telemetry prompt" // progress notification title, for awaiting in tests
2929
GoplsConfigDirEnvvar = "GOPLS_CONFIG_DIR" // overridden for testing
3030
FakeTelemetryModefileEnvvar = "GOPLS_FAKE_TELEMETRY_MODEFILE" // overridden for testing
31+
TelemetryYes = "Yes, I'd like to help."
32+
TelemetryNo = "No, thanks."
3133
)
3234

3335
// getenv returns the effective environment variable value for the provided
@@ -203,35 +205,50 @@ Would you like to enable Go telemetry?
203205
params := &protocol.ShowMessageRequestParams{
204206
Type: protocol.Info,
205207
Message: prompt,
206-
Actions: []protocol.MessageActionItem{{Title: "Yes"}, {Title: "No"}},
208+
Actions: []protocol.MessageActionItem{
209+
{Title: TelemetryYes},
210+
{Title: TelemetryNo},
211+
},
207212
}
213+
208214
item, err := s.client.ShowMessageRequest(ctx, params)
209215
if err != nil {
210216
errorf("ShowMessageRequest failed: %v", err)
211217
// Defensive: ensure item == nil for the logic below.
212218
item = nil
213219
}
214220

221+
message := func(typ protocol.MessageType, msg string) {
222+
if err := s.client.ShowMessage(ctx, &protocol.ShowMessageParams{
223+
Type: typ,
224+
Message: msg,
225+
}); err != nil {
226+
errorf("ShowMessage(unrecognize) failed: %v", err)
227+
}
228+
}
229+
215230
result := pFailed
216231
if item == nil {
217232
// e.g. dialog was dismissed
218233
errorf("no response")
219234
} else {
220235
// Response matches MessageActionItem.Title.
221236
switch item.Title {
222-
case "Yes":
237+
case TelemetryYes:
223238
result = pYes
224-
s.setTelemetryMode("on")
225-
case "No":
239+
if err := s.setTelemetryMode("on"); err == nil {
240+
message(protocol.Info, telemetryOnMessage())
241+
} else {
242+
errorf("enabling telemetry failed: %v", err)
243+
msg := fmt.Sprintf("Failed to enable Go telemetry: %v\nTo enable telemetry manually, please run `go run golang.org/x/telemetry/cmd/gotelemetry@latest on`", err)
244+
message(protocol.Error, msg)
245+
}
246+
247+
case TelemetryNo:
226248
result = pNo
227249
default:
228250
errorf("unrecognized response %q", item.Title)
229-
if err := s.client.ShowMessage(ctx, &protocol.ShowMessageParams{
230-
Type: protocol.Error,
231-
Message: fmt.Sprintf("Unrecognized response %q", item.Title),
232-
}); err != nil {
233-
errorf("ShowMessage failed: %v", err)
234-
}
251+
message(protocol.Error, fmt.Sprintf("Unrecognized response %q", item.Title))
235252
}
236253
}
237254
resultContent := []byte(fmt.Sprintf("%s %d", result, attempts))
@@ -240,6 +257,17 @@ Would you like to enable Go telemetry?
240257
}
241258
}
242259

260+
func telemetryOnMessage() string {
261+
reportDate := time.Now().AddDate(0, 0, 7).Format("2006-01-02")
262+
return fmt.Sprintf(`Telemetry uploading is now enabled and may be sent to https://telemetry.go.dev/ starting %s. Uploaded data is used to help improve the Go toolchain and related tools, and it will be published as part of a public dataset.
263+
264+
For more details, see https://telemetry.go.dev/privacy.
265+
This data is collected in accordance with the Google Privacy Policy (https://policies.google.com/privacy).
266+
267+
To disable telemetry uploading, run %s.
268+
`, reportDate, "`go run golang.org/x/telemetry/cmd/gotelemetry@latest off`")
269+
}
270+
243271
// acquireLockFile attempts to "acquire a lock" for writing to path.
244272
//
245273
// This is achieved by creating an exclusive lock file at <path>.lock. Lock

gopls/internal/regtest/misc/prompt_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ func main() {
8282
`
8383

8484
tests := []struct {
85-
response string
86-
wantMode string
85+
response string // response to choose for the telemetry dialog
86+
wantMode string // resulting telemetry mode
87+
wantMsg string // substring contained in the follow-up popup (if empty, no popup is expected)
8788
}{
88-
{"Yes", "on"},
89-
{"No", ""},
90-
{"", ""},
89+
{lsp.TelemetryYes, "on", "uploading is now enabled"},
90+
{lsp.TelemetryNo, "", ""},
91+
{"", "", ""},
9192
}
9293
for _, test := range tests {
9394
t.Run(fmt.Sprintf("response=%s", test.response), func(t *testing.T) {
@@ -117,8 +118,13 @@ func main() {
117118
},
118119
MessageResponder(respond),
119120
).Run(t, src, func(t *testing.T, env *Env) {
120-
env.Await(
121+
var postConditions []Expectation
122+
if test.wantMsg != "" {
123+
postConditions = append(postConditions, ShownMessage(test.wantMsg))
124+
}
125+
env.OnceMet(
121126
CompletedWork(lsp.TelemetryPromptWorkTitle, 1, true),
127+
postConditions...,
122128
)
123129
gotMode := ""
124130
if contents, err := os.ReadFile(modeFile); err == nil {

0 commit comments

Comments
 (0)