slb: allow line selection - #267
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.