Show context snippets for content searches#213
Draft
franciscoxc wants to merge 1 commit into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR proposes an MVP/proof-of-concept for displaying per-result context snippets when a search query uses the content: filter, by conditionally adding a Context column and lazily hydrating snippets for visible rows via get_nodes_info.
Changes:
- Adds frontend parsing for
content:terms and threads them through the virtualized results pipeline to request snippet context. - Adds a conditional Context column in the files results table (rendered only when
content:is present) and supports end-ellipsis highlighting for snippets. - Extends the Tauri
get_nodes_infocommand to optionally read and return a short content snippet around the first match.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| cardinal/src/utils/contentQuery.ts | New helper to extract content: terms from the user query. |
| cardinal/src/utils/tests/contentQuery.test.ts | Unit tests for extractContentTerms. |
| cardinal/src/types/search.ts | Adds contentContext to node/result typings. |
| cardinal/src/i18n/resources/ar-SA.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/de-DE.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/en-US.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/es-ES.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/fr-FR.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/hi-IN.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/it-IT.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/ja-JP.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/ko-KR.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/pt-BR.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/ru-RU.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/tr-TR.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/uk-UA.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/zh-CN.json | Adds columns.context translation key. |
| cardinal/src/i18n/resources/zh-TW.json | Adds columns.context translation key. |
| cardinal/src/hooks/useDataLoader.ts | Threads content-term options through get_nodes_info hydration. |
| cardinal/src/hooks/tests/useDataLoader.test.ts | Verifies content snippet options are passed to get_nodes_info. |
| cardinal/src/components/VirtualList.tsx | Passes content-term options into useDataLoader. |
| cardinal/src/components/MiddleEllipsisHighlight.tsx | Adds an ellipsisMode="end" option for snippet-friendly truncation. |
| cardinal/src/components/FilesTabContent.tsx | Toggles a context-aware layout class and passes snippet options to VirtualList. |
| cardinal/src/components/FileRow.tsx | Renders the Context cell and highlights content terms within the snippet. |
| cardinal/src/components/ColumnHeader.tsx | Conditionally renders the Context column header label. |
| cardinal/src/App.tsx | Detects content: terms, toggles Context column layout, and passes snippet options down. |
| cardinal/src/App.css | Adds grid/CSS variable support for a context-first column layout. |
| cardinal/src-tauri/src/commands.rs | Extends get_nodes_info to optionally read and return a context snippet. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+13
| const char = query[index]; | ||
| if (char === '\\' && index + 1 < query.length) { | ||
| value += query[index + 1]; | ||
| index += 2; | ||
| continue; | ||
| } |
Comment on lines
+42
to
+47
| while (index < query.length) { | ||
| const matchIndex = lowerQuery.indexOf(CONTENT_PREFIX, index); | ||
| if (matchIndex === -1) { | ||
| break; | ||
| } | ||
|
|
Comment on lines
+471
to
+479
| let desired_after = match_index + needle.len() + CONTENT_CONTEXT_AFTER_BYTES; | ||
| let mut has_suffix = after_end < chunk_len; | ||
| if desired_after > chunk_len { | ||
| let mut extra = vec![0u8; desired_after - chunk_len]; | ||
| if let Ok(extra_read) = file.read(&mut extra) { | ||
| snippet.extend_from_slice(&extra[..extra_read]); | ||
| has_suffix = extra_read == extra.len(); | ||
| } | ||
| } |
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.
Hi! I noticed this issue is already assigned, so please treat this PR as a proposed implementation / proof of concept rather than an assumption about the final direction.
I tested this locally and wanted to share it in case it helps, or in case parts of it match what you had in mind for content search results.
What this changes
content:terms in the current query on the frontend.Contextcolumn only when acontent:query is active.Notes
get_nodes_info, so they are fetched with row metadata rather than changing the search result contract.content:searches, the table layout remains unchanged.Implementation map
contentQuery.ts: extractscontent:terms from the current search query.useDataLoader.ts: passes content terms toget_nodes_info.commands.rs: reads a small snippet around the first content match.ColumnHeader.tsx/FileRow.tsx: render the conditionalContextcolumn.MiddleEllipsisHighlight.tsx: supports end ellipsis for snippets.Testing
npm test -- --run src/components/MiddleEllipsisHighlight.test.ts src/utils/__tests__/contentQuery.test.ts src/hooks/__tests__/useDataLoader.test.tsnpm run typecheckcargo fmt -- --checkcargo check --all-targetsRelated to #212.