-
Notifications
You must be signed in to change notification settings - Fork 804
Add pprof commands to VS Code extension #2474
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds developer/debugging commands to the VS Code extension that enable on-demand profiling of the language server. The changes expose Go's pprof profiling capabilities through LSP custom requests, allowing developers to trigger garbage collection and capture CPU, heap, and allocation profiles.
Changes:
- Refactored
ProfileSessionininternal/pprof/pprof.goto support both existing and new profiling workflows - Added new profiling functions:
SaveHeapProfile,SaveAllocProfile,RunGC, and a thread-safeCPUProfilertype - Integrated profiling commands into the LSP server with proper handlers and protocol definitions
- Added VS Code extension commands with UI prompts for directory selection and context state management
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/pprof/pprof.go | Refactored ProfileSession to support optional memory profiling; added CPUProfiler with mutex-based concurrency control; added SaveHeapProfile, SaveAllocProfile, and RunGC functions |
| internal/lsp/server.go | Added cpuProfiler field to Server struct; registered handlers for 5 new debugging commands (runGC, saveHeapProfile, saveAllocProfile, startCPUProfile, stopCPUProfile) |
| internal/lsp/lsproto/lsp_generated.go | Added ProfileParams and ProfileResult types with JSON unmarshaling; added 5 new custom LSP methods with proper request/response type mappings |
| internal/lsp/lsproto/_generate/generate.mts | Added custom request and structure definitions for profiling commands to the code generator |
| _extension/src/commands.ts | Registered 5 new developer commands with error handling and user prompts; added promptForProfileDirectory helper function |
| _extension/src/client.ts | Added 5 client methods to send profiling requests to the language server; reset cpuProfileRunning context on server stop |
| _extension/package.json | Added 5 command definitions with proper enablement conditions based on server and CPU profiling state |
| // Custom requests to add to the model (tsgo-specific) | ||
| const customRequests: Request[] = [ | ||
| { | ||
| method: "$/runGC", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think $/ is intended to be used like this; the spec says that requests made with $/ prefixes are supposed to be rejected by a server: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#dollarRequests (and notifications are allowed to be ignored)
If we just need a custom prefix, we probably just want to align this PR and #2399?
No description provided.