pathutil

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pathutil provides utilities for converting between absolute and relative paths.

Architecture Pattern: Lightning Code Index uses absolute paths internally for consistency and to avoid ambiguity. However, user-facing output should use relative paths for readability and portability. This package provides the conversion layer between internal (absolute) and external (relative) representations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToRelative

func ToRelative(absPath, rootDir string) string

ToRelative converts an absolute path to relative based on a root directory. Falls back to the original path if conversion fails or path is already relative.

Examples:

  • ToRelative("/home/user/project/src/main.go", "/home/user/project") → "src/main.go"
  • ToRelative("/other/location/file.go", "/home/user/project") → "/other/location/file.go" (outside root)
  • ToRelative("src/main.go", "/home/user/project") → "src/main.go" (already relative)

func ToRelativeGrepResults

func ToRelativeGrepResults(results []searchtypes.GrepResult, rootDir string) []searchtypes.GrepResult

ToRelativeGrepResults converts paths in GrepResult slice from absolute to relative. Creates a new slice without modifying the original results.

This function is designed for use at output boundaries where results are displayed to users:

  • CLI grep output
  • JSON serialization
  • Test result parsing

func ToRelativeStandardResults

func ToRelativeStandardResults(results []searchtypes.StandardResult, rootDir string) []searchtypes.StandardResult

ToRelativeStandardResults converts paths in StandardResult slice from absolute to relative. Creates a new slice without modifying the original results.

This function is designed for use at output boundaries where results are displayed to users:

  • CLI standard search output
  • JSON serialization
  • MCP server responses

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL