Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

The language server panics when processing code action requests containing diagnostics with nil Code fields. The LSP protocol allows Diagnostic.Code to be omitted, but the handler attempted to dereference it without a nil check.

Changes

  • internal/ls/codeactions.go: Add nil check for diag.Code before accessing diag.Code.Integer

Example

// Before: panics when diag.Code is nil
if diag.Code.Integer == nil {
    continue
}

// After: safely handles nil Code
if diag.Code == nil || diag.Code.Integer == nil {
    continue
}

[!WARNING]

Original prompt

This section details on the original issue you should resolve

<filter_complete></filter_complete>

<issue_title>codeactions - panic</issue_title>
<issue_description>## Stack trace

[11:17:53.127] Updated watches in 0s
panic handling request textDocument/codeAction runtime error: invalid memory address or nil pointer dereference goroutine 557015 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc0000ecdc0, 0xc183e63260)
	github.com/microsoft/typescript-go/internal/lsp/server.go:572 +0x58
panic({0x7ff658ba41e0?, 0x7ff6595197a0?})
	runtime/panic.go:783 +0x132
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideCodeActions(0xc183b9a180, {0x7ff658f0d860, 0xc183b748c0}, 0xc114034cc0)
	github.com/microsoft/typescript-go/internal/ls/codeactions.go:67 +0x18d
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleCodeAction(0xc0002a0b40?, {0x7ff658f0d860?, 0xc183b748c0?}, 0xc0c8c1c900?, 0x82?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:931 +0x25
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].28({0x7ff658f0d860, 0xc183b748c0}, 0xc183e63260)
	github.com/microsoft/typescript-go/internal/lsp/server.go:558 +0x11a
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc0000ecdc0, {0x7ff658f0d860, 0xc183b748c0}, 0xc183e63260)
	github.com/microsoft/typescript-go/internal/lsp/server.go:451 +0x10d
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:356 +0x3a
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 10
	github.com/microsoft/typescript-go/internal/lsp/server.go:376 +0x9ad

[Error - 11:17:54 AM] Request textDocument/codeAction failed.
  Message: InternalError: panic handling request textDocument/codeAction: runtime error: invalid memory address or nil pointer dereference
  Code: -32603 

</issue_description>

Comments on the Issue (you are @copilot in this section)

Original prompt

This section details on the original issue you should resolve

<issue_title>codeactions - panic</issue_title>
<issue_description>## Stack trace

[11:17:53.127] Updated watches in 0s
panic handling request textDocument/codeAction runtime error: invalid memory address or nil pointer dereference goroutine 557015 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc0000ecdc0, 0xc183e63260)
	github.com/microsoft/typescript-go/internal/lsp/server.go:572 +0x58
panic({0x7ff658ba41e0?, 0x7ff6595197a0?})
	runtime/panic.go:783 +0x132
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideCodeActions(0xc183b9a180, {0x7ff658f0d860, 0xc183b748c0}, 0xc114034cc0)
	github.com/microsoft/typescript-go/internal/ls/codeactions.go:67 +0x18d
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleCodeAction(0xc0002a0b40?, {0x7ff658f0d860?, 0xc183b748c0?}, 0xc0c8c1c900?, 0x82?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:931 +0x25
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].28({0x7ff658f0d860, 0xc183b748c0}, 0xc183e63260)
	github.com/microsoft/typescript-go/internal/lsp/server.go:558 +0x11a
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc0000ecdc0, {0x7ff658f0d860, 0xc183b748c0}, 0xc183e63260)
	github.com/microsoft/typescript-go/internal/lsp/server.go:451 +0x10d
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:356 +0x3a
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 10
	github.com/microsoft/typescript-go/internal/lsp/server.go:376 +0x9ad

[Error - 11:17:54 AM] Request textDocument/codeAction failed.
  Message: InternalError: panic handling request textDocument/codeAction: runtime error: invalid memory address or nil pointer dereference
  Code: -32603 

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic in codeactions handling request Fix nil pointer dereference in code actions when diagnostic code is nil Nov 14, 2025
Copilot AI requested a review from jakebailey November 14, 2025 12:26
Copilot finished work on behalf of jakebailey November 14, 2025 12:26
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@jakebailey jakebailey marked this pull request as ready for review November 14, 2025 22:23
Copilot AI review requested due to automatic review settings November 14, 2025 22:23
Copilot AI requested a review from jakebailey November 14, 2025 22:23
Copilot finished work on behalf of jakebailey November 14, 2025 22:23
Copilot finished reviewing on behalf of jakebailey November 14, 2025 22:24
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 fixes a nil pointer dereference panic in the code actions handler that occurs when a diagnostic has a nil Code field. The panic was happening when the code attempted to access diag.Code.Integer without first checking if diag.Code itself was nil.

Key changes:

  • Added nil check for diag.Code before accessing diag.Code.Integer in the diagnostic processing loop

@jakebailey jakebailey added this pull request to the merge queue Nov 14, 2025
Merged via the queue into main with commit 77ea74f Nov 14, 2025
48 checks passed
@jakebailey jakebailey deleted the copilot/fix-codeactions-runtime-error branch November 14, 2025 22:48
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.

codeactions - panic

3 participants