Skip to content

Conversation

@andrewbranch
Copy link
Member

No description provided.

Copy link
Contributor

Copilot AI left a 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 ProfileSession in internal/pprof/pprof.go to support both existing and new profiling workflows
  • Added new profiling functions: SaveHeapProfile, SaveAllocProfile, RunGC, and a thread-safe CPUProfiler type
  • 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",
Copy link
Member

@jakebailey jakebailey Jan 12, 2026

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?

@andrewbranch andrewbranch added this pull request to the merge queue Jan 12, 2026
Merged via the queue into microsoft:main with commit cfbe2fe Jan 12, 2026
22 checks passed
@andrewbranch andrewbranch deleted the profiling-commands branch January 12, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants