-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] Add helpful messages for invalid expression diagnostics #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…s, comments) Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
|
@copilot Please continue the previous task. |
…rors Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Continued the task. Fixed the failing tests by updating them to match the actual parser error messages. Also added |
There was a problem hiding this 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 pull request extends the language service diagnostics to detect and report syntax errors in expressions. The implementation leverages the existing parser's error detection capabilities to provide helpful error messages for common syntax errors such as unclosed strings, unmatched brackets, unknown characters, and other parsing failures.
Changes:
- Added syntax error detection by calling
parser.parse()and catching thrown errors - Created helper functions
createDiagnosticFromParseErrorandcreateDiagnosticFromErrorto convert parser errors into LSP diagnostics - Added comprehensive test coverage for various syntax error scenarios including unclosed strings, brackets, braces, and unknown characters
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/language-service/diagnostics.ts | Added two new exported functions to create diagnostics from ParseError and generic Error objects, with appropriate position calculation and range highlighting |
| src/language-service/language-service.ts | Modified getDiagnostics to parse expressions and catch syntax errors, importing the new diagnostic creation functions and handling tokenization failures gracefully |
| test/language-service/language-service.ts | Added comprehensive test suite for syntax error diagnostics, covering unclosed delimiters, unknown characters, and valid expressions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| createDiagnosticFromError, | ||
| TokenSpan |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TokenSpan type is being imported from the diagnostics module, but it's only used internally within getDiagnostics and getDiagnosticsForDocument. Consider whether this export is necessary at the language-service module level, as it increases the API surface area without clear external usage.
| createDiagnosticFromError, | |
| TokenSpan | |
| createDiagnosticFromError |
| * Analyzes the document for function calls and checks if they have the correct number of arguments. | ||
| * Returns diagnostics for function calls with incorrect argument counts. | ||
| * Returns diagnostics for function calls with incorrect argument counts, as well as | ||
| * syntax errors detected by the parser (unclosed strings, brackets, unknown characters, etc.). |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states that this function returns diagnostics for "function calls with incorrect argument counts, as well as syntax errors detected by the parser" but it doesn't mention that it returns early without checking function arguments when tokenization fails. Consider updating the documentation to clarify that function argument checking is skipped when syntax errors prevent tokenization.
| * syntax errors detected by the parser (unclosed strings, brackets, unknown characters, etc.). | |
| * syntax errors detected by the parser (unclosed strings, brackets, unknown characters, etc.). | |
| * If tokenization fails due to syntax errors, only syntax-error diagnostics are returned and | |
| * function argument checking is skipped. |
createDiagnosticFromParseErrorto convert parser errors to diagnosticscreateDiagnosticFromErrorto handle generic Error exceptionsgetDiagnosticsto callparser.parse()and capture any thrown errorsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.