Skip to content

Validate #line directives with real debuggers (VS Code, Rider) #609

@antonsynd

Description

@antonsynd

Background

The Sharpy compiler emits #line directives in generated C# so that debuggers and stack traces reference .spy source files. Runtime tests exist in LineDirectiveRuntimeTests.cs verifying stack traces show .spy file paths and correct line numbers.

However, no real-debugger validation has been done — the directives have not been tested with actual debugger UIs.

Validation Plan

VS Code with C# Extension

  1. Create a sample multi-file Sharpy project with:
    • Classes, functions, conditionals, loops
    • Exception handling (try/except)
    • Module imports
  2. Compile to C# and run under the VS Code debugger
  3. Verify:
    • Breakpoints set in .spy files are hit correctly
    • Step-into navigates to the correct .spy line
    • Step-over advances to the next logical .spy line
    • Variable inspection shows correct values
    • Call stack shows .spy file paths and line numbers

JetBrains Rider

  1. Open the same project in Rider
  2. Verify the same breakpoint, stepping, and call stack behaviors

Stack Traces

  1. Trigger an unhandled exception and verify:
    • Stack trace references .spy file paths
    • Line numbers in stack trace match source .spy lines
    • Nested call chains show correct .spy origins

Edge Cases

  1. Test with:
    • Decorators (line mapping across decorator + def)
    • List comprehensions (single-line constructs mapped to multiple C# lines)
    • Lambda expressions
    • Multi-line expressions (string concatenation, method chaining)

Current Implementation

  • AttachLineDirective() in RoslynEmitter.Statements.cs (lines 227-240)
  • CreateLineDirectiveTrivia() helper at lines 246-251
  • Runtime tests: src/Sharpy.Compiler.Tests/Integration/LineDirectiveRuntimeTests.cs

Outcome

Document any adjustments needed to the directive format. If all checks pass, close this issue. If adjustments are needed, create follow-up issues for each fix.

Context

From the 2026-04-27 compiler health audit (O1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions