Add test reproducing panic on out-of-bounds textDocument/definition request #1982
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
The LSP server panics when receiving a textDocument/definition request with a line number exceeding the file's line count. This occurs during client/server synchronization issues where the client's position data is stale.
Changes
TestPanicOnOutOfBoundsDefinitionthat sends a definition request for line 65 in an 8-line fileSendDefinitionRequestAtPosition()to fourslash framework to bypass bounds checking for error handling testsCurrent Behavior
The server recovers and returns InternalError (-32603). The test fails as expected, documenting the bug without fixing it.
Original prompt
This section details on the original issue you should resolve
<issue_title>Panic on textDocument/definition</issue_title>
<issue_description>## Stack trace
Steps to reproduce
I couldn't easily reproduce again. I was commenting out some code and then it appeared to error when the editor lost focus. I tried re-doing edits and it didn't occur.
The file I am in has 44 lines so not sure where bad line number 65 or line map length 33 came from.
Checking the LSP logs:
so It seems it is a vscode issue - asking for a wrong line number?!
Feel free to close - I guess when this is production it will ignore errors like this instead of popping up.</issue_description>
<agent_instructions>Create a fourslash test for this issue in internal/fourslash/tests. Do not attempt to fix the issue. Only create a test that fails, reproducing the bug.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@iisaduan Do other files in the same folder have the same name but different extensions? @jakebailey ``` panic handling request textDocument/definition bad line number. Line: 24, lineMap length: 23 goroutine 43742 [running]: runtime/debug.Stack() runtime/debug/stack.go:26 +0x5e github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc00017cdc0, 0xc02ea55800) github.com/microsoft/typescript-go/internal/lsp/server.go:567 +0x58 panic({0xb147a0?, 0xc017495f00?}) runtime/panic.go:783 +0x132 github.com/microsoft/typescript-go/internal/ls.(*Converters).LineAndCharacterToPosition(0xc01695b8a8, {0xea6f90, 0xc01cfde908}, {0xf21dda8?, 0xc0?}) github.com/microsoft/typescript-go/internal/ls/converters.go:143 +0x2d9 github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideDefinition(0xc02d676900, {0xea88c0, 0xc01ba8a960}, {0xc01c5f6600?, 0x10000c02698b620?}, {0x0?, 0x0?}) github.com/microsoft/typescript-go/internal/ls/definition.go:17 +0xaf github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDefinition(0xc00031ca20?, {0xea88c0?, 0xc01ba8a960?}, 0xc01c5f6600?, 0x53?) github.com/microsoft/typescript-go/internal/lsp/server.go:815 +0x35 github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].14({0xea88c0, 0xc01ba8a960}, 0xc02ea55800) github.com/microsoft/typescript-go/internal/lsp/server.go:553 +0x13f github.com/microsoft/typescri...💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.