Avoid "Cannot add name" error for ParamArray and Optional arguments#2
Merged
Conversation
…ay name handling This test verifies that enterOptionalParam and enterParamArray correctly push a name element before calling addNameElementContext, preventing spurious 'Cannot add name' errors for parameter identifiers.
There was a problem hiding this comment.
Pull request overview
This PR prevents the “Cannot add name …” LSP error during parsing of Optional parameters and ParamArray arguments by ensuring the listener always pushes an active NameExpressionElement context before recording parameter identifiers, and adds integration tests to guard against regressions.
Changes:
- Push a
NameExpressionElementforOptionalParamandParamArraycontexts before adding identifier contexts. - Extend
NameExpressionContextto includeOptionalParamContextandParamArrayContext. - Add Mocha integration tests that parse representative VBA snippets and assert no error-level LSP logs are emitted.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server/src/test/vbaListener.test.ts | Adds integration tests that parse VBA code containing Optional and ParamArray parameters and assert no error logs are emitted. |
| server/src/project/parser/vbaListener.ts | Fixes missing name-element push for enterOptionalParam and enterParamArray, preventing “Cannot add name” errors. |
| server/src/project/elements/naming.ts | Broadens NameExpressionContext union to allow using OptionalParamContext/ParamArrayContext as NameExpressionElement containers. |
| package.json | Adds dedent for tests and formats activationEvents as a multi-line array. |
| package-lock.json | Locks the newly added dedent dev dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request adds
vbaListener.test.tswith 2 tests to ensure that no LSP related errors occur during parsing of ParamArray and Optional argument statements. The fix is also included: ensuring that we push a name to the context viathis.pushNameElement(ctx);.