microsoft / microsoft/language-server-protocol
Capturing quick fix telemetry
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13k
- Forks
- 1k
- Avg merge
- 6d 1h
- Merged PRs (30d)
- 10
Description
If you're working on a language server with a lot of stuff computed, you may be including the WorkspaceEdit when you send CodeAction items back to the client. This unfortunately means that the server can send actions back to the client until the cows come home without ever realizing the user has accepted any of them. How are other language server authors capturing this kind of usage telemetry? I see a few options...and none of them seem very attractive.
- Server parses
textDocument/didChangeand determines which code action was applied. I presume people are not using this option. - Client uses
codeAction.commandand then self-calls a localtelemetry.callback.commandand sends telemetry back home. This means every LSP client will have to add this code when integrating with said language server which is not ideal. - Server declares
telemetry.callback.commandin its server capabilities ({"executeCommandProvider": ["telemetry.callback.command"}) so thatworkspace/executeCommandcan be used. There's a lot of back and forth to achieve this but it does at least keep the telemetry code in the server and the client does not have to do anything extra (assuming the client supportsworkspace/executeCommandin the first place).
It feels to me like 3 is the best choice even if it means there are a lot of round trips but I wanted to open this up for discussion to see if I just missed something obvious...? 🤔
Option 1:
sequenceDiagram
user->>client: opens a document
client->>server: textDocument/didOpen (notification)
client->>server: textDocument/codeAction (request 1)
server->>client: textDocument/codeAction (response 1)
user->>client: accepts a quick fix code action
client->>document: applies the codeAction.WorkspaceEdit
client->>server: textDocument/didChange (notification)
server->>telemetryServer: parses content change and then sends telemetry
Option 2:
sequenceDiagram
user->>client: starts the client
client->>server: initialize (request 1)
server->>client: initialize (response 1) with telemetry.callback.command as ExecuteCommandOptions
user->>client: opens a document
client->>server: textDocument/didOpen (notification)
client->>server: textDocument/codeAction (request 2)
server->>client: textDocument/codeAction (response 2)
user->>client: accepts a quick fix code action
client->>document: applies the codeAction.WorkspaceEdit
client->>telemetryServer: looks up codeAction.command and uses telemetry.callback.command locally and sends telemetry back
Option 3:
sequenceDiagram
user->>client: starts the client
client->>server: initialize (request 1)
server->>client: initialize (response 1) with telemetry.callback.command as ExecuteCommandOptions
user->>client: opens a document
client->>server: textDocument/didOpen (notification)
client->>server: textDocument/codeAction (request 2)
server->>client: textDocument/codeAction (response 2)
user->>client: accepts a quick fix code action
client->>document: applies the codeAction.WorkspaceEdit
client->>server: textDocument/didChange (notification)
client->>server: look up codeAction.comand, request workspace/executeCommand with telemetry.callback.command (request 3)
server->>telemetryServer: sends telemetry event
server->>client: workspace/executeCommand (response 3)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the issue's three telemetry approaches and the referenced LSP concepts: CodeAction, WorkspaceEdit, codeAction.command, and workspace/executeCommand. Compare the trade-offs described in the sequence diagrams and consult the protocol definitions; done would require a decided, documented approach rather than an implementation target currently named in the issue.
Written by the indexing model from the issue text.
Assessment
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100