Skip to content

Fix signature help crash on malformed function declarations#1536

Merged
TwitchBronBron merged 4 commits intomasterfrom
copilot/fix-1467
Jul 18, 2025
Merged

Fix signature help crash on malformed function declarations#1536
TwitchBronBron merged 4 commits intomasterfrom
copilot/fix-1467

Conversation

Copy link
Contributor

Copilot AI commented Jul 18, 2025

This PR fixes a crash that occurs when signature help is triggered on malformed function declarations with trailing commas but missing closing parentheses.

Issue Description

The crash happened when users were defining a function and added a comma at the end without having a closing parenthesis:

sub test(p1 = invalid, <-- adding this comma causes the crash
  result = 1
end sub

When signature help was triggered (by typing comma or opening parenthesis), the language server would crash with a TypeError: Cannot read properties of undefined (reading 'parent').

Root Cause

The crash occurred in CallExpressionInfo.ts when the code tried to access expression.parent without checking if it was null/undefined. For malformed function declarations, the AST parser creates partial nodes where some parent relationships might not be established, leading to null reference errors.

Solution

Added comprehensive null safety checks in CallExpressionInfo.ts:

  1. Fixed null reference in ascertainCallExpression(): Added optional chaining for expression.parent?.findAncestor()
  2. Added safety check in isPositionBetweenParentheses(): Return false early if callExpression is null
  3. Fixed null reference in process(): Added null check before accessing callExpression.parent
  4. Enhanced getParameterIndex(): Added safety checks for null callExpression or args

Testing

Added three comprehensive test cases covering:

  • Malformed function declaration with trailing comma (original issue)
  • Incomplete function calls
  • Malformed function declaration with missing closing parenthesis

All existing tests continue to pass (2441 passing), ensuring no regressions were introduced.

Verification

Manual testing confirms that signature help no longer crashes on malformed code and returns an empty array gracefully instead of throwing an exception.

Fixes #1467.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Crash during signature help Fix signature help crash on malformed function declarations Jul 18, 2025
Copilot AI requested a review from TwitchBronBron July 18, 2025 16:29
@TwitchBronBron TwitchBronBron marked this pull request as ready for review July 18, 2025 17:55
@TwitchBronBron TwitchBronBron merged commit 3ef0a61 into master Jul 18, 2025
7 checks passed
@TwitchBronBron TwitchBronBron deleted the copilot/fix-1467 branch July 18, 2025 18:02
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.

Crash during signature help

2 participants