Skip to content

Avoid "Cannot add name" error for ParamArray and Optional arguments#2

Merged
DecimalTurn merged 3 commits into
plusfrom
dev-cannot-add-name
Mar 1, 2026
Merged

Avoid "Cannot add name" error for ParamArray and Optional arguments#2
DecimalTurn merged 3 commits into
plusfrom
dev-cannot-add-name

Conversation

@DecimalTurn
Copy link
Copy Markdown
Owner

This pull request adds vbaListener.test.ts with 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 via this.pushNameElement(ctx);.

…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.
Copy link
Copy Markdown

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 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 NameExpressionElement for OptionalParam and ParamArray contexts before adding identifier contexts.
  • Extend NameExpressionContext to include OptionalParamContext and ParamArrayContext.
  • 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.

Comment thread server/src/project/parser/vbaListener.ts
Comment thread server/src/test/vbaListener.test.ts
@DecimalTurn DecimalTurn merged commit c3b486a into plus Mar 1, 2026
7 checks passed
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