|
| 1 | +// Copyright 2023 The Go Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package telemetry |
| 6 | + |
| 7 | +import ( |
| 8 | + "os" |
| 9 | + |
| 10 | + "golang.org/x/telemetry/counter" |
| 11 | + "golang.org/x/tools/gopls/internal/lsp/protocol" |
| 12 | +) |
| 13 | + |
| 14 | +// Start starts telemetry instrumentation. |
| 15 | +func Start() { |
| 16 | + if os.Getenv("GOPLS_TELEMETRY_EXP") != "" { |
| 17 | + counter.Open() |
| 18 | + // TODO: add upload logic. |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +// RecordClientInfo records gopls client info. |
| 23 | +func RecordClientInfo(params *protocol.ParamInitialize) { |
| 24 | + client := "gopls/client:other" |
| 25 | + if params != nil && params.ClientInfo != nil { |
| 26 | + switch params.ClientInfo.Name { |
| 27 | + case "Visual Studio Code": |
| 28 | + client = "gopls/client:vscode" |
| 29 | + case "VSCodium": |
| 30 | + client = "gopls/client:vscodium" |
| 31 | + case "code-server": |
| 32 | + // https://github.com/coder/code-server/blob/3cb92edc76ecc2cfa5809205897d93d4379b16a6/ci/build/build-vscode.sh#L19 |
| 33 | + client = "gopls/client:code-server" |
| 34 | + case "Eglot": |
| 35 | + // https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-03/msg00954.html |
| 36 | + client = "gopls/client:eglot" |
| 37 | + case "govim": |
| 38 | + // https://github.com/govim/govim/pull/1189 |
| 39 | + client = "gopls/client:govim" |
| 40 | + case "Neovim": |
| 41 | + // https://github.com/neovim/neovim/blob/42333ea98dfcd2994ee128a3467dfe68205154cd/runtime/lua/vim/lsp.lua#L1361 |
| 42 | + client = "gopls/client:neovim" |
| 43 | + case "coc.nvim": |
| 44 | + // https://github.com/neoclide/coc.nvim/blob/3dc6153a85ed0f185abec1deb972a66af3fbbfb4/src/language-client/client.ts#L994 |
| 45 | + client = "gopls/client:coc.nvim" |
| 46 | + case "Sublime Text LSP": |
| 47 | + // https://github.com/sublimelsp/LSP/blob/e608f878e7e9dd34aabe4ff0462540fadcd88fcc/plugin/core/sessions.py#L493 |
| 48 | + client = "gopls/client:sublimetext" |
| 49 | + } |
| 50 | + } |
| 51 | + counter.Inc(client) |
| 52 | +} |
0 commit comments