Skip to content

Conversation

Copy link

Copilot AI commented Jan 23, 2026

  • Explore the repository structure and understand the codebase
  • Understand language service implementation
  • Implement function argument count validation in language service
    • Add ArityInfo interface for tracking function argument min/max
    • Add arityInfo() method to FunctionDetails class to return min/max args
    • Add getDiagnostics() method to LanguageServiceApi interface
    • Implement getDiagnostics() in createLanguageService() that validates function argument counts
    • Export GetDiagnosticsParams and ArityInfo types from language service
  • Add tests for the new getDiagnostics functionality (17 new tests)
  • Run tests to verify the implementation (all 1194 tests pass)
  • Address code review feedback
    • Extract getDiagnostics logic to separate diagnostics.ts file
    • Reduce complexity by extracting helper functions
    • Integrate diagnostics into playground
    • Update documentation on the language service
  • Run security scan with CodeQL (no alerts)
Original prompt

The language server should also indicate when a function has not the correct number of arguments (too few or too much).


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

Added getDiagnostics() method to the language service API that validates
function argument counts and returns LSP diagnostics when functions are
called with too few or too many arguments.

Changes:
- Added ArityInfo interface and GetDiagnosticsParams interface
- Added arityInfo() method to FunctionDetails class
- Implemented getDiagnostics() in createLanguageService()
- Exported new types from public API
- Added comprehensive tests for the new functionality

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copy link

@Sander-Toonen Sander-Toonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the logic for getDiagnostics to a seperate file and reduce the complexity of teh getDiagnostics function by extracting

Copilot AI and others added 2 commits January 23, 2026 16:02
Fixed the argument counting logic to correctly handle function calls
with multiple arguments. The issue was that markArgumentSeen() was
incorrectly resetting argCount to 1 even after commas had already
been counted. Now it only sets argCount = 1 if this is the first
argument (argCount === 0).

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
- Moved pluralize helper outside the nested loops to avoid repeated function creation
- Simplified the argument tracking by inlining the logic instead of using closures
- Converted isAtFunctionCallTopLevel from a closure to a computed variable
- Removed unused foundClosingParen variable

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add validation for correct number of function arguments Add function argument count validation to language service Jan 23, 2026
Copilot AI requested a review from Sander-Toonen January 23, 2026 16:07
Copy link

@Sander-Toonen Sander-Toonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the functionality can be demonstrated in the playground

- Created new diagnostics.ts module with extracted diagnostic logic
- Broke down complex argument counting into smaller, focused functions:
  - ArgumentCounterState interface for state management
  - createArgumentCounterState() for initialization
  - isAtTopLevel() for depth checking
  - markArgumentSeen() for argument tracking
  - processParenToken(), processBracketToken(), processBraceToken() for token handling
  - processCommaToken(), processOtherToken() for remaining tokens
  - countFunctionArguments() for argument counting
  - validateFunctionCall() for validation
  - createTooFewArgumentsDiagnostic(), createTooManyArgumentsDiagnostic() for diagnostic creation
- Simplified getDiagnostics() in language-service.ts to delegate to the new module
- Added TokenSpan interface and comprehensive documentation

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 23, 2026

Move the logic for getDiagnostics to a seperate file and reduce the complexity of teh getDiagnostics function by extracting

Done in 1c797cc. Extracted the diagnostics logic to a new diagnostics.ts file and reduced complexity by breaking down the argument counting into smaller, focused functions:

  • ArgumentCounterState interface for state management
  • createArgumentCounterState(), isAtTopLevel(), markArgumentSeen() for state operations
  • processParenToken(), processBracketToken(), processBraceToken(), processCommaToken(), processOtherToken() for token handling
  • countFunctionArguments() for the main counting logic
  • validateFunctionCall(), createTooFewArgumentsDiagnostic(), createTooManyArgumentsDiagnostic() for validation and diagnostic creation

- Added applyDiagnostics() function to app.js that calls ls.getDiagnostics()
  and displays error markers in Monaco editor using setModelMarkers
- Call applyDiagnostics() on initialization and on expression changes
- Added "Diagnostics Demo" example to examples.js that demonstrates
  function argument count validation with pow(2) and random(1, 2, 3)

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 23, 2026

Ensure that the functionality can be demonstrated in the playground

Done in 7d5a2a8. Integrated diagnostics into the playground:

  • Added applyDiagnostics() function in app.js that calls ls.getDiagnostics() and displays error markers in Monaco using setModelMarkers
  • Diagnostics are applied on initialization and whenever the expression changes
  • Added a "Diagnostics Demo" example that demonstrates the feature with pow(2) (too few args) and random(1, 2, 3) (too many args)

Run npm run playground and click the "Diagnostics Demo" example to see red squiggly underlines on function calls with incorrect argument counts.

@Sander-Toonen Sander-Toonen marked this pull request as ready for review January 23, 2026 16:25
Copilot AI review requested due to automatic review settings January 23, 2026 16:25
@Sander-Toonen
Copy link

@copilot Update documentation on the language server

Copy link

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

Adds function-argument-count diagnostics to the language service API and wires them into the playground sample so incorrect function calls surface as LSP-style errors.

Changes:

  • Extend LanguageServiceApi with getDiagnostics(params: GetDiagnosticsParams): Diagnostic[] and plumb this through createLanguageService.
  • Introduce ArityInfo and FunctionDetails.arityInfo() plus a new diagnostics.ts module that token-walks expressions, counts arguments (including nested/array/object/variadic/optional cases), and produces LSP diagnostics.
  • Integrate diagnostics into the Monaco playground with applyDiagnostics() and a new "Diagnostics Demo" example showcasing incorrect calls to pow and random.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/language-service/language-service.ts Adds comprehensive tests for getDiagnostics, covering correct/incorrect arity, nested calls, literals as arguments, severity, source, and range, plus a basic API-existence check.
src/language-service/language-service.types.ts Extends the public language service types with getDiagnostics, GetDiagnosticsParams, and ArityInfo to describe function arity.
src/language-service/language-service.ts Implements getDiagnostics on the language service by tokenizing the document, building a FunctionDetails map, and delegating to the new diagnostics module; returns it in the public API object.
src/language-service/language-service.models.ts Enhances FunctionDetails with arityInfo() that derives (min, max) argument counts from built-in docs (including variadic and optional parameters) or JS function arity as a fallback.
src/language-service/diagnostics.ts New module that walks token spans, counts function-call arguments with nesting/arrays/objects handled, compares against ArityInfo, and emits LSP Diagnostic objects with accurate ranges, messages, severity, and source.
samples/language-service-sample/examples.js Adds a "Diagnostics Demo" example expression intentionally using wrong argument counts to surface diagnostics in the playground.
samples/language-service-sample/app.js Adds applyDiagnostics() to convert LSP diagnostics to Monaco markers and invokes it on expression changes to show argument-count errors in the editor.
index.ts Re-exports new language service types (GetDiagnosticsParams, ArityInfo) from the package root for public consumption.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Added Diagnostics feature to the Features section
- Added getDiagnostics() to Basic Usage example
- Updated Monaco Editor sample description to mention diagnostics demo
- Added complete ls.getDiagnostics() API reference section
- Added Monaco Editor integration example for diagnostics
- Updated Exported Types to include GetDiagnosticsParams and ArityInfo
- Updated LSP Types to include Diagnostic and DiagnosticSeverity

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 23, 2026

@copilot Update documentation on the language server

Done in 1705043. Updated docs/language-service.md with:

  • Added Diagnostics to the Features section with details on argument validation
  • Added getDiagnostics() call to the Basic Usage example
  • Updated Monaco playground description to mention the "Diagnostics Demo" example
  • Added complete ls.getDiagnostics(params) API reference with parameters, return type, and examples
  • Added Monaco Editor integration example showing how to display diagnostics using setModelMarkers
  • Updated TypeScript Exported Types to include GetDiagnosticsParams and ArityInfo
  • Updated LSP Types to include Diagnostic and DiagnosticSeverity

@Sander-Toonen Sander-Toonen merged commit 361dec9 into master Jan 23, 2026
3 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