Skip to content

Comments

Add tools API and errors package#4

Merged
heshanpadmasiri merged 11 commits intoballerina-platform:mainfrom
snelusha:tools-api
Oct 27, 2025
Merged

Add tools API and errors package#4
heshanpadmasiri merged 11 commits intoballerina-platform:mainfrom
snelusha:tools-api

Conversation

@snelusha
Copy link
Contributor

@snelusha snelusha commented Aug 5, 2025

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:

  • Added the Diagnostic interface and its base implementation in diagnostic.go, which defines the structure for diagnostics, including location, info, message, properties, and string representation.
  • Introduced the DiagnosticInfo interface and implementation in diagnostic-info.go, enabling abstract, comparable representations of diagnostic categories, codes, and severity.
  • Implemented the DiagnosticSeverity type and constants in diagnostic-severity.go, standardizing severity levels (Internal, Hint, Info, Warning, Error) for diagnostics.
  • Defined the DiagnosticProperty interface and its kind enum in diagnostic-property.go and diagnostic-property-kind.go, allowing diagnostics to carry additional structured metadata. [1] [2]
  • Added the DiagnosticRelatedInformation interface and implementation in diagnostic-related-information.go for capturing supplementary messages and locations related to diagnostics.

Diagnostic Creation and Codes:

  • Provided factory functions for creating diagnostics and diagnostics with properties in diagnostic-factory.go, streamlining diagnostic instantiation.
  • Added the DiagnosticCode interface in diagnostic-code.go for uniquely identifying diagnostics and associating them with severity and message keys.

Location and Text Utilities:

  • Defined the Location interface in location.go for representing source code positions, integrating with line and text ranges.
  • Added a CharReader utility in char-reader.go for efficient character-level reading and lexeme marking in text documents, useful for lexers and parsers.

Error Handling Utilities:

  • Introduced custom error types IndexOutOfBoundsError and IllegalArgumentError in errors.go for improved error reporting and handling in common scenarios.

Diagnostics Implementation:

  • Implemented the internal DefaultDiagnostic type in default-diagnostic.go, providing a concrete diagnostic structure used by the factory methods, including formatted messages and string output.

Closes #3

@snelusha snelusha requested a review from Copilot August 5, 2025 08:48

This comment was marked as outdated.

This comment was marked as outdated.

@snelusha snelusha requested a review from Copilot August 6, 2025 06:35
Copy link
Contributor

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 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

Copy link
Member

@heshanpadmasiri heshanpadmasiri left a comment

Choose a reason for hiding this comment

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

Shall we also add any related prompt files as well?


// charReaderImpl is the concrete implementation of CharReader.
type charReaderImpl struct {
charBuffer []rune
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid holding utf32's in memory (it's okay to return them)

@snelusha
Copy link
Contributor Author

Shall we also add any related prompt files as well?

Added!

Copy link
Contributor

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

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
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
// 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

Copilot uses AI. Check for mistakes.
Copy link
Member

@heshanpadmasiri heshanpadmasiri left a comment

Choose a reason for hiding this comment

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

Minor nits, also check anything copilot has generated (feel free to dismiss any false positive)

Copy link
Member

@heshanpadmasiri heshanpadmasiri left a comment

Choose a reason for hiding this comment

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

LGTM

@heshanpadmasiri heshanpadmasiri merged commit c7a935b into ballerina-platform:main Oct 27, 2025
2 checks passed
heshanpadmasiri pushed a commit to heshanpadmasiri/ballerina-lang-go that referenced this pull request Dec 17, 2025
* 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
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.

Migrate ballerina-tools-api

2 participants