Skip to content

Search results: configurable truncation and size threshold - #273450

Closed
Yonas650 wants to merge 3 commits into
microsoft:mainfrom
Yonas650:feat/search-truncation-273410
Closed

Yonas650 wants to merge 3 commits into
microsoft:mainfrom
Yonas650:feat/search-truncation-273410

Conversation

@Yonas650

Copy link
Copy Markdown

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

    • Covers off, end, and both modes in addition to existing behavior.
  • 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

  • New: Control how search results are truncated with search.resultsTruncation and search.allowedSizeBeforeTruncation for improved readability and context.

Fixes #273410

- Add search.resultsTruncation: 'start' | 'end' | 'both' | 'off' (default 'start')
- Add search.allowedSizeBeforeTruncation (default 1000; regex min 10000)
- Wire truncationMode + charsPerLine through Search view, Quick Text Search, Search Editor
- Implement modes in TextSearchMatch and align non-rg path (getFileResults)
- Add tests for new modes

Refs microsoft#273410
@Yonas650

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@osortega Osvaldo Ortega (osortega) left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what problem this PR is trying to fix, when we do search we can truncate both beginning or end depending on where the term that was searched for.
Example: searching for interface you can see truncation in all places.
Image

With this change the search results are pretty much impossible to parse
Image

@shoulders

Copy link
Copy Markdown

Osvaldo Ortega (@osortega)

I'm not sure I understand what problem this PR is trying to fix, when we do search we can truncate both beginning or end depending on where the term that was searched for. Example: searching for interface you can see truncation in all places.

It is all about context. when searching for certain things you sometimes need to see search term in the whole line to find the actual line you want.

Because everyone searching needs different requirements I am of the opinion that the truncation needs to be configurable to at least

  • show the whole line
  • set the truncation length
  • set whether the truncation is left only, right only, both

An Example

image

I search for the term qStr( which is a function that takes a PHP variable and encapsulates as a string ready for SQL insertion.

If you look in the search panel you can see the line

...`      =". $this->app->db->qStr( $page_permission['Clerical']         ).",
  • You can see that the first part of the statement is missing which is very important as it defines what name string data will be inserted as.
  • So now I have to actually open the file and read the line to make sure it is what I want. But this can potential take a long time as I would have to verify each line in the search one by one.

The solution is to not have truncation on so I can now see that the SQL variable name is Clerical

`Clerical`      =". $this->app->db->qStr( $page_permission['Clerical']         ).",

@osortega

Copy link
Copy Markdown
Contributor

shoulders (@shoulders) I see, so this is more like amount of characters of context that you would like to have at the beginning or end of the truncation. Given that we actually truncate today at the beginning and end, having a setting like this will be very confusing.

Could you change the PR so that the setting is referring to the amount of characters to the left or right that users would like to have as context with an option of allowing all characters en each direction? And instead of doing < 98 characters skipped> we just keep using ...

@shoulders

Copy link
Copy Markdown

Osvaldo Ortega (@osortega) it is not my PR and my level of programming is not at that level.

For me, the most important thing is to disable truncation.

The ability to also control the truncation amounts, left and right, is important to have a flexible workflow.

@shoulders

Copy link
Copy Markdown

Osvaldo Ortega (@osortega) Why was this closed?

@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search Results - Improve truncation - Show full line, Truncate on the Left or the Right

3 participants