Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 23, 2025

Some linters report character offsets instead of line/column coordinates for issues. This PR adds comprehensive support for offset-based location coordinates to the Cake.Issues library while maintaining full backward compatibility.

Key Features Added

Core Interface Extensions:

  • Extended IIssue interface with Offset and EndOffset properties
  • Updated IIssueProperty enum with new offset property flags
  • Added offset parameters to Issue class constructor with proper validation

Builder Pattern Support:

  • Added InFileAtOffset(filePath, offset) method to IssueBuilder
  • Added InFileAtOffset(filePath, startOffset, endOffset) method for offset ranges
  • Maintains existing fluent API design patterns

Configuration & Conversion:

  • Created LocationCoordinates enum with options: LineColumn, Offset, Both
  • Added PreferredLocationCoordinates property to IssueProviderSettings
  • Implemented LocationCoordinateConverter utility class with methods to convert between line/column ↔ character offsets
  • Proper handling of both Unix (\n) and Windows (\r\n) line endings

Usage Examples

// Using offset coordinates with IssueBuilder
var issue = IssueBuilder
    .NewIssue("Syntax error", providerType, providerName)
    .InFileAtOffset("src/Program.cs", 150)  // Character offset 150
    .Create();

// Using offset ranges
var issue2 = IssueBuilder
    .NewIssue("Unused variable", providerType, providerName)  
    .InFileAtOffset("src/Program.cs", 150, 175)  // From offset 150 to 175
    .Create();

// Converting between coordinate systems
var offset = LocationCoordinateConverter.LineColumnToOffset(fileContent, 5, 10);
var (line, col) = LocationCoordinateConverter.OffsetToLineColumn(fileContent, 150);

// Configure preferred coordinate format for an issue provider
var settings = new IssueProviderSettings(logFile);
settings.PreferredLocationCoordinates = LocationCoordinates.Offset;

Backward Compatibility

All existing functionality continues to work unchanged. The new offset properties are optional and existing code that uses line/column coordinates will work exactly as before. Issue providers can now optionally provide offset information alongside or instead of line/column coordinates.

Testing

Added comprehensive test coverage including:

  • 26 tests for LocationCoordinateConverter functionality
  • 14 tests for IssueBuilder offset methods
  • Edge case handling for different line ending formats
  • Validation of offset parameter constraints

Fixes #254.


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

- Add Offset and EndOffset properties to IIssue interface
- Add LocationCoordinates enum for preferred coordinate format
- Add offset support to IssueBuilder with InFileAtOffset methods
- Add LocationCoordinateConverter utility for offset↔line/column conversion
- Update IssueProviderSettings with PreferredLocationCoordinates property
- Update IIssueProperty enum with offset properties
- Update all serialization classes to handle new constructor parameters
- Add comprehensive tests for offset functionality
- Maintain full backward compatibility

Co-authored-by: pascalberger <2190718+pascalberger@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for location offsets Add comprehensive support for location offsets in issues Sep 24, 2025
Copilot AI requested a review from pascalberger September 24, 2025 00:38
Copilot finished work on behalf of pascalberger September 24, 2025 00:38
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.

Add support for location offsets

2 participants