Skip to content

Comments

[WIP] Add diagnostic range to flow model diagnostics#713

Draft
kanushka wants to merge 2 commits intoballerina-platform:1.6.xfrom
kanushka:codex/add-diagnostic-range-flow-model
Draft

[WIP] Add diagnostic range to flow model diagnostics#713
kanushka wants to merge 2 commits intoballerina-platform:1.6.xfrom
kanushka:codex/add-diagnostic-range-flow-model

Conversation

@kanushka
Copy link
Contributor

@kanushka kanushka commented Feb 17, 2026

Summary

This change adds source code range information to flow-model diagnostics returned by flowDesignService/getFlowModel and related flow diagnostics responses.

Related issue: wso2/product-ballerina-integrator#2447

Problem

Flow model diagnostics previously exposed severity and message, but not the diagnostic location range. Without the range, clients cannot reliably invoke diagnostic-based code actions against the exact compiler-reported location.

Root Cause

DiagnosticHandler was only copying severity/message into Diagnostics.Info. The underlying compiler diagnostic line range was available but not propagated into the serialized flow model diagnostic object.

Fix

  • Extended Diagnostics.Info to carry range (LineRange).
  • Updated DiagnosticHandler to populate range from currentDiagnostic.location().lineRange().
  • Updated flow-model LS extension tests to:
    • Assert diagnostic ranges are present where diagnostics are emitted.
    • Keep existing snapshot assertions stable by normalizing out range during equality comparison.
    • Add a focused test for getFlowModel range presence.

Validation

Executed focused tests:

  • ./gradlew :flow-model-generator:flow-model-generator-ls-extension:test --tests io.ballerina.flowmodelgenerator.extension.ModelGeneratorTest.testDiagnosticRangesInFlowModel --tests io.ballerina.flowmodelgenerator.extension.FlowModelDiagnosticsTest.testMultipleRequests

Both passed in this environment.

Summary

This pull request adds source code range information to flow-model diagnostics returned by the flow design service, improving the precision of diagnostic locations provided to users.

Changes

Core Functionality:

  • Extended the Diagnostics.Info record to include a LineRange field for capturing diagnostic location information
  • Updated DiagnosticHandler to propagate source code ranges from compiler diagnostics to the diagnostic information structure
  • Added method overloads in Diagnostics.Builder to support range parameters when creating diagnostic entries

Testing and Validation:

  • Updated flow-model LS extension tests to verify that diagnostic ranges are properly included in responses
  • Introduced helper methods to normalize diagnostic ranges in test comparisons, enabling stable snapshot testing
  • Added a focused test method (testDiagnosticRangesInFlowModel) to validate that the flow model generation API correctly returns diagnostics with range information
  • Verified tests pass with focused test runs

Outcome

Diagnostic information now includes precise source code location details, enhancing the flow model service's diagnostic feedback to users and enabling better error/warning localization in integrated development environments.

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The changes extend the diagnostic system to include location information (LineRange) alongside severity and message. The DiagnosticHandler, Diagnostics model, and corresponding test files are updated to support diagnostic range context throughout the system.

Changes

Cohort / File(s) Summary
Diagnostic Core Model Enhancement
DiagnosticHandler.java, Diagnostics.java
Extended diagnostic information to include LineRange. Updated Diagnostics.Info record with new range field, added convenience constructor, and introduced Builder.diagnostic method overload accepting LineRange as third parameter.
Test Coverage for Diagnostic Ranges
FlowModelDiagnosticsTest.java, ModelGeneratorTest.java
Added test utilities to handle diagnostic ranges: stripDiagnosticRanges and assertDiagnosticsIncludeRange helper methods. Tests now normalize diagnostics during comparison and verify that generated flow models include range information in diagnostics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A range now marks each diagnostic found,
From line to column, context all around,
The tests are thorough, stripping what we don't need,
Comparing flow and form with careful heed,
Location matters in this rabbit's feed! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description comprehensively covers key sections: summary, problem statement, root cause analysis, implementation details, and validation results. However, it does not follow the repository's standard template structure (missing sections like Purpose/Goals/Approach format, Release notes, Documentation, etc.).
Title check ✅ Passed The title clearly and specifically describes the main change: adding diagnostic range information to flow model diagnostics, which aligns with all file modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kanushka kanushka changed the title [codex] Add diagnostic range to flow model diagnostics Add diagnostic range to flow model diagnostics Feb 17, 2026
@kanushka kanushka changed the base branch from main to 1.6.x February 17, 2026 18:21
@kanushka kanushka changed the base branch from 1.6.x to main February 17, 2026 18:22
@kanushka kanushka force-pushed the codex/add-diagnostic-range-flow-model branch from f7d0088 to 87735d1 Compare February 17, 2026 18:31
@kanushka kanushka changed the base branch from main to 1.6.x February 17, 2026 18:31
@kanushka kanushka marked this pull request as ready for review February 17, 2026 18:31
@kanushka
Copy link
Contributor Author

@coderabbitai review

@kanushka kanushka requested a review from nipunayf February 17, 2026 18:33
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/java/io/ballerina/flowmodelgenerator/extension/ModelGeneratorTest.java (1)

130-196: Duplicate helper methods - same as FlowModelDiagnosticsTest.

As noted in the review of FlowModelDiagnosticsTest.java, these helper methods are duplicated. Consider extracting them to a shared location to maintain DRY principles.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/java/io/ballerina/flowmodelgenerator/extension/ModelGeneratorTest.java`
around lines 130 - 196, The two helper methods stripDiagnosticRanges and
assertDiagnosticsIncludeRange are duplicated from FlowModelDiagnosticsTest;
extract them into a shared utility class (e.g., DiagnosticTestUtils) and update
ModelGeneratorTest and FlowModelDiagnosticsTest to call
DiagnosticTestUtils.stripDiagnosticRanges(...) and
DiagnosticTestUtils.assertDiagnosticsIncludeRange(...). Ensure the new utility
class is package-visible or public as needed, include the same method signatures
and any required imports, and remove the duplicate method definitions from
ModelGeneratorTest so both tests reuse the single implementation.
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/java/io/ballerina/flowmodelgenerator/extension/FlowModelDiagnosticsTest.java (1)

117-182: Consider extracting duplicate helper methods to the existing TestUtils class.

Both stripDiagnosticRanges (lines 117–148) and assertDiagnosticsIncludeRange (lines 150–182) are duplicated in ModelGeneratorTest.java. Since TestUtils.java already exists in this test package, these methods should be moved there to reduce duplication and centralize maintenance.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/java/io/ballerina/flowmodelgenerator/extension/FlowModelDiagnosticsTest.java`
around lines 117 - 182, The two duplicated helper methods
stripDiagnosticRanges(JsonElement) and
assertDiagnosticsIncludeRange(JsonElement, String) should be moved into the
existing TestUtils class and the duplicates removed from
FlowModelDiagnosticsTest and ModelGeneratorTest; create corresponding public
static methods in TestUtils with the same signatures, update both test classes
to call TestUtils.stripDiagnosticRanges(...) and
TestUtils.assertDiagnosticsIncludeRange(...)/(or static-import them) instead of
their local copies, and run tests to ensure no references remain to the removed
local methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/java/io/ballerina/flowmodelgenerator/extension/FlowModelDiagnosticsTest.java`:
- Around line 117-182: The two duplicated helper methods
stripDiagnosticRanges(JsonElement) and
assertDiagnosticsIncludeRange(JsonElement, String) should be moved into the
existing TestUtils class and the duplicates removed from
FlowModelDiagnosticsTest and ModelGeneratorTest; create corresponding public
static methods in TestUtils with the same signatures, update both test classes
to call TestUtils.stripDiagnosticRanges(...) and
TestUtils.assertDiagnosticsIncludeRange(...)/(or static-import them) instead of
their local copies, and run tests to ensure no references remain to the removed
local methods.

In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/java/io/ballerina/flowmodelgenerator/extension/ModelGeneratorTest.java`:
- Around line 130-196: The two helper methods stripDiagnosticRanges and
assertDiagnosticsIncludeRange are duplicated from FlowModelDiagnosticsTest;
extract them into a shared utility class (e.g., DiagnosticTestUtils) and update
ModelGeneratorTest and FlowModelDiagnosticsTest to call
DiagnosticTestUtils.stripDiagnosticRanges(...) and
DiagnosticTestUtils.assertDiagnosticsIncludeRange(...). Ensure the new utility
class is package-visible or public as needed, include the same method signatures
and any required imports, and remove the duplicate method definitions from
ModelGeneratorTest so both tests reuse the single implementation.

@kanushka kanushka changed the title Add diagnostic range to flow model diagnostics [WIP] Add diagnostic range to flow model diagnostics Feb 20, 2026
@kanushka kanushka marked this pull request as draft February 20, 2026 08:32
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.

1 participant