Search results: configurable truncation and size threshold #273450
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.
Summary
Improves readability of search result previews by making truncation behavior configurable.
Adds options to show full lines, truncate from the start, end, or both sides (keeping the match centered).
Keeps default behavior unchanged for existing users.
New Settings
search.resultsTruncation: 'start' | 'end' | 'both' | 'off' (default: 'start')
search.allowedSizeBeforeTruncation: number of characters before truncating (default: 1000; regex searches enforce a minimum of 10000 internally for replace correctness)
Example:
"search.resultsTruncation": "both"
"search.allowedSizeBeforeTruncation": 80
Behavior
start: elides the beginning (“⟪ N characters skipped ⟫”), match remains in view.
end: shows the start, elides the tail with the same elision token.
both: elides both sides to center the match for context.
off: no elision (full line preview; UI may still visually clip).
Scope
Applies to Search view, Quick Text Search, and Search Editor.
Works with both ripgrep and non-rg (in-memory) result paths.
Implementation Notes
Uses existing elision token (unchanged): “⟪ N characters skipped ⟫” to preserve Search Editor offset parsing.
Honors regex replace constraints by using >= 10000 chars per line for regex queries.
Default behavior remains identical to current (truncation at the start).
Test Plan
Unit tests: src/vs/workbench/services/search/test/common/search.test.ts
Manual:
Create a file with a very long single line containing the search term.
Toggle search.resultsTruncation through all options and validate:
start → left elision only
end → trailing elision only
both → both sides elide, match centered
off → full line shown
Adjust search.allowedSizeBeforeTruncation to a small value (e.g., 40) to see clear effects.
Verify in Search view, Quick Text Search (%), and Search Editor.
Release Notes
Fixes #273410