Skip to content

Add --context flag to show surrounding source code #85

@naheel0

Description

@naheel0

Title: Add --context flag to show surrounding source code

Problem

Users need immediate code context to diagnose errors faster without opening an editor.

Proposed change

Implement a --context [n] option that shows n lines of code before/after the error location (requires stack parsing for file/line extraction).

Files to change

  • lib/formatter.js (print source snippet when available)
  • lib/stack-parser.js (if not already added)
  • bin/index.js (expose --context flag)

Tasks

  • Respect repo root and ignore binary files.
  • Add safety checks for path traversal and very large files.
  • Add tests for snippet boundaries and missing files.

Acceptance criteria

  • errlens analyze --context 3 prints the requested snippet when location info is present.

Labels: enhancement, low-priority

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requestlow-priorityLow-priority work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions