Skip to content

slb: allow line selection - #267

Merged
Esgrove merged 2 commits into
mainfrom
slb-line-selection
Sep 15, 2026
Merged

Esgrove merged 2 commits into
mainfrom
slb-line-selection

Conversation

@Esgrove

@Esgrove Esgrove commented Sep 15, 2026

Copy link
Copy Markdown
Owner

No description provided.

Reflowing a whole file turns a small edit into a large diff, so the
formatter needs a way to work on only the lines that changed.

FormatOptions carries a LineRanges set, empty meaning the whole text. A
paragraph is taken as a unit, so the prose pass skips a paragraph the
selection misses entirely, which drops both its violations and its
changes. The trailing comment pass filters per line, since it works line
by line rather than per paragraph.

Moving a trailing comment above its code line adds a line, so the
selection is mapped onto the shifted numbering before the pass that
builds the fixed text uses it.

FormatResult also reports where the selection ended up in the fixed
text. Reflowing changes how many lines a paragraph needs, so a caller
checking the fixed text again would otherwise apply the original line
numbers to text that has moved, and miss a violation that is still
inside the selection.
An agent that edits a few lines and then runs slb gets a diff full of
reflows it did not ask for, so the tool needs to be told which lines to
work on.

A spec is either lines and ranges such as "10-25,40" for a single file,
or a location such as "src/main.rs:14" in the form the report prints, so
a reported violation can be pasted straight back in. A column after the
line is accepted and ignored for the same reason. Line numbers are read
from the end of a spec, one colon separated segment at a time, so a
Windows path keeps its drive letter.

Commas separate the specs of one value, and a range following a location
belongs to the file it named, so "src/main.rs:14,20" selects two lines
of one file and the path only has to be written once.

A location names the file to work on, which is what lets a single spec
stand on its own. An explicitly named file also bypasses the extension
filter, so a location works for a file type the config does not list.

Two combinations are refused rather than guessed at. Plain ranges with
more than one file would apply the same line numbers to every one of
them, and mixing plain ranges with locations leaves it unclear which
files the plain ranges are for.

The fixed text is checked again through the ranges the fix mapped it to,
so a violation that survives inside the selection is still reported when
the fix moved it further down the file.
@Esgrove
Esgrove merged commit 74a99a3 into main Sep 15, 2026
3 of 4 checks passed
@Esgrove
Esgrove deleted the slb-line-selection branch September 15, 2026 18:31
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.

1 participant