Add tools API and errors package#4
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces a comprehensive diagnostics framework and text processing utilities for a Go-based compiler toolchain. The implementation provides foundational abstractions for error reporting, location tracking, and text document manipulation in what appears to be a Ballerina language compiler port.
Key changes include:
- A complete diagnostics framework with severity levels, diagnostic codes, and related information handling
- Text processing utilities for document manipulation, line mapping, and character reading
- Custom error types for improved error handling in common scenarios
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tools/text/*.go | Text processing utilities including document representation, line/position mapping, text ranges, and character reading |
| tools/diagnostics/*.go | Diagnostic framework core with interfaces for diagnostics, severity levels, properties, and factory methods |
| common/errors/errors.go | Custom error types for index bounds and illegal argument errors |
heshanpadmasiri
left a comment
There was a problem hiding this comment.
Shall we also add any related prompt files as well?
tools/text/char-reader.go
Outdated
|
|
||
| // charReaderImpl is the concrete implementation of CharReader. | ||
| type charReaderImpl struct { | ||
| charBuffer []rune |
There was a problem hiding this comment.
Let's avoid holding utf32's in memory (it's okay to return them)
Added! |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| // IntersectionExists tests whether there exists an intersection of this range and the given range. | ||
| // The ranges R1(S1, E1) and R2(S2, E2) intersects if S1 is greater than or equal to E2 and |
There was a problem hiding this comment.
Corrected verb agreement from 'intersects' to 'intersect' and fixed the logic description which should state 'less than or equal to' for S1 and 'greater than or equal to' for S2.
| // The ranges R1(S1, E1) and R2(S2, E2) intersects if S1 is greater than or equal to E2 and | |
| // The ranges R1(S1, E1) and R2(S2, E2) intersect if S1 is less than or equal to E2 and |
heshanpadmasiri
left a comment
There was a problem hiding this comment.
Minor nits, also check anything copilot has generated (feel free to dismiss any false positive)
* Add tools API and errors package
* Delegate `TextLines` to the `Lines()` method
* Refactor `IndexOutOfBoundsError` and `IllegalArgumentError`
* Refactor `calculateTextLines` to ignore rune (int32)
* Refactor `String()` to drop the empty‐slice guard
* Return -1 instead of 0 on error
* Use `any` type instead of `interface{}`
* Add Copilot prompt file
* Use overflow-safe midpoint calc
* Use `string` instead of `[]rune`
* Address code review suggestions
This pull request introduces a foundational set of types, interfaces, and utility implementations for a diagnostics framework in Go, primarily aimed at supporting error reporting and location tracking in a compiler or similar tool. The changes add abstractions for diagnostics, their severity, properties, codes, related information, and text location handling, along with utility error types and a character reader for text processing.
The most important changes are:
Diagnostics Framework Core:
Diagnosticinterface and its base implementation indiagnostic.go, which defines the structure for diagnostics, including location, info, message, properties, and string representation.DiagnosticInfointerface and implementation indiagnostic-info.go, enabling abstract, comparable representations of diagnostic categories, codes, and severity.DiagnosticSeveritytype and constants indiagnostic-severity.go, standardizing severity levels (Internal, Hint, Info, Warning, Error) for diagnostics.DiagnosticPropertyinterface and its kind enum indiagnostic-property.goanddiagnostic-property-kind.go, allowing diagnostics to carry additional structured metadata. [1] [2]DiagnosticRelatedInformationinterface and implementation indiagnostic-related-information.gofor capturing supplementary messages and locations related to diagnostics.Diagnostic Creation and Codes:
diagnostic-factory.go, streamlining diagnostic instantiation.DiagnosticCodeinterface indiagnostic-code.gofor uniquely identifying diagnostics and associating them with severity and message keys.Location and Text Utilities:
Locationinterface inlocation.gofor representing source code positions, integrating with line and text ranges.CharReaderutility inchar-reader.gofor efficient character-level reading and lexeme marking in text documents, useful for lexers and parsers.Error Handling Utilities:
IndexOutOfBoundsErrorandIllegalArgumentErrorinerrors.gofor improved error reporting and handling in common scenarios.Diagnostics Implementation:
DefaultDiagnostictype indefault-diagnostic.go, providing a concrete diagnostic structure used by the factory methods, including formatted messages and string output.Closes #3