Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Dec 16, 2025

This PR attempts to address Issue #10085.

Summary

Implements a feature to show code context as compact chips in the chat input box rather than displaying full code text. When selecting code and adding to context via the "Add to Roo Code" code action, it now appears as a collapsed chip showing the file path and line range (e.g., file.ts:1-10).

Changes

New Files

  • packages/types/src/code-snippet.ts - CodeSnippet type and helper functions for:
    • Creating unique IDs
    • Formatting labels (fileName:startLine-endLine)
    • Expanding snippets to full markdown code blocks
  • webview-ui/src/components/chat/CodeSnippetChip.tsx - Compact chip component for collapsed display

Modified Files

  • packages/types/src/index.ts - Export code-snippet module
  • src/shared/ExtensionMessage.ts - Add addCodeSnippet invoke type and codeSnippet field
  • src/core/webview/ClineProvider.ts - Send structured CodeSnippet instead of formatted text
  • webview-ui/src/components/chat/ChatView.tsx - Handle code snippet state and expand on send
  • webview-ui/src/components/chat/ChatTextArea.tsx - Display code snippet chips

Features

  • Code snippets appear as compact chips showing fileName:startLine-endLine
  • Multiple code snippets can be added
  • Each chip has a remove button
  • Full code content is expanded when sending to AI
  • Prevents duplicate snippets (same file/lines)

How It Works

  1. User selects code and uses "Add to Roo Code" context menu
  2. Extension creates a CodeSnippet object with file path, line range, and content
  3. Chip is displayed in the chat input area
  4. When sending message, snippets are expanded to full markdown code blocks and prepended

Feedback and guidance are welcome!


Important

Adds feature to display code snippets as compact chips in chat input, enhancing UI by preventing clutter from large code blocks.

  • Behavior:
    • Code snippets added via "Add to Roo Code" appear as collapsed chips in chat input, showing fileName:startLine-endLine.
    • Multiple snippets can be added, each with a remove button.
    • Full code content is expanded when sending to AI.
    • Prevents duplicate snippets (same file/lines).
  • Components:
    • CodeSnippetChip and CodeSnippetChips in CodeSnippetChip.tsx for displaying and managing snippet chips.
    • ChatTextArea.tsx and ChatView.tsx updated to handle code snippet state and display.
  • Types and Functions:
    • CodeSnippet type and helper functions in code-snippet.ts for ID creation, label formatting, and snippet expansion.
    • Tests for code-snippet.ts in code-snippet.test.ts.
  • Integration:
    • ClineProvider.ts modified to send structured CodeSnippet objects.
    • ExtensionMessage.ts updated to include addCodeSnippet invoke type and codeSnippet field.

This description was created by Ellipsis for b760452. You can customize this summary. It will automatically update as commits are pushed.

@roomote
Copy link
Contributor Author

roomote bot commented Dec 16, 2025

Rooviewer Clock   See task on Roo Cloud

Re-reviewed the changes since commit 5e9ea62. All previously flagged issues have been resolved. No new issues found.

  • Use substring instead of deprecated substr in packages/types/src/code-snippet.ts
  • Replace unsafe type casting with proper Number() conversion in src/core/webview/ClineProvider.ts
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

* Creates a unique ID for a code snippet
*/
export function createCodeSnippetId(): string {
return `snippet-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

String.prototype.substr() is deprecated. Use substring(2, 11) instead since substr(start, length) is equivalent to substring(start, start + length).

Suggested change
return `snippet-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
return `snippet-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`

Fix it with Roo Code or mention @roomote and request a fix.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 16, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jan 7, 2026
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 7, 2026
@hannesrudolph hannesrudolph reopened this Jan 7, 2026
@github-project-automation github-project-automation bot moved this from Done to Triage in Roo Code Roadmap Jan 7, 2026
@github-project-automation github-project-automation bot moved this from Done to New in Roo Code Roadmap Jan 7, 2026
@hannesrudolph hannesrudolph marked this pull request as ready for review January 7, 2026 21:48
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jan 7, 2026
@roomote
Copy link
Contributor Author

roomote bot commented Jan 7, 2026

Rooviewer Clock   See task on Roo Cloud

Re-reviewed the PR. The 2 previously flagged issues remain unresolved:

  • Use substring instead of deprecated substr in packages/types/src/code-snippet.ts
  • Replace unsafe type casting with proper Number() conversion in src/core/webview/ClineProvider.ts

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@dosubot dosubot bot added the Enhancement New feature or request label Jan 7, 2026
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jan 7, 2026
@roomote
Copy link
Contributor Author

roomote bot commented Jan 7, 2026

Rooviewer Clock   See task on Roo Cloud

Re-reviewed the PR. No new issues found. The 2 previously flagged issues remain unresolved:

  • Use substring instead of deprecated substr in packages/types/src/code-snippet.ts
  • Replace unsafe type casting with proper Number() conversion in src/core/webview/ClineProvider.ts

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

roomote and others added 3 commits January 7, 2026 14:52
Implements a feature to show code context as compact chips in the chat
input box rather than displaying full code text. When selecting code and
adding to context, it now appears as a collapsed chip showing the file
path and line range.

Features:
- CodeSnippet type for structured code references
- CodeSnippetChip component for compact display of code references
- Multiple code snippets can be added and displayed as chips
- Full code content is expanded when sending to AI
- Remove button on each chip to remove snippets

Relates to #10085
Based on user feedback in Issue #10085, the code reference chip
now displays only line numbers (e.g., "lines 10-25") instead of
file path and line numbers (e.g., "file.ts:10-25") since the code
is always from the current page.

Also adds test coverage for code-snippet module.
@hannesrudolph hannesrudolph force-pushed the feature/collapsed-code-snippets-10085 branch from 5e9ea62 to b760452 Compare January 7, 2026 21:55
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: PR [Needs Prelim Review]

Development

Successfully merging this pull request may close these issues.

3 participants