sourceheader

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package sourceheader extracts package and import header text from tree-sitter node strings. Tree-sitter Kotlin/Java sometimes attaches trailing comments and whitespace to header nodes; the helpers here strip that trivia so callers see only the dotted name.

The package was extracted from internal/rename and internal/scanner, which previously kept byte-identical copies of FirstSourceLine and FirstHeaderLine. See issue #44.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstHeaderLine

func FirstHeaderLine(raw, keyword string) string

FirstHeaderLine returns the first source line of raw with the given keyword (e.g. "package", "import") and any trailing semicolon stripped. Returns the empty string when raw has no source line.

func FirstSourceLine

func FirstSourceLine(raw string) string

FirstSourceLine returns the first non-empty, non-comment line of raw, trimmed. Used to ignore trailing trivia tree-sitter sometimes attaches to header nodes (line/block comments, blank lines).

Single-pass over raw: walks the line-delimited string in place so we don't allocate a slice covering every line for the typical one-or-two-line header.

Types

This section is empty.

Jump to

Keyboard shortcuts

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