feat(ask): start chat from selected code range - #1553
Conversation
WalkthroughThe editor context menu now sends selected file ranges to a new SourceBot chat. File-source validation, prompt slicing, line offsets, range metadata, explicit source propagation, and chat creation support the flow. ChangesSelected SourceBot Chat
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant EditorContextMenu
participant useCreateNewChatThread
participant createUIMessage
participant ChatNavigation
EditorContextMenu->>useCreateNewChatThread: createChatFromSource(selected file range)
useCreateNewChatThread->>createUIMessage: build message with explicit source
createUIMessage-->>useCreateNewChatThread: data-source message part
useCreateNewChatThread->>ChatNavigation: persist chat state and navigate
Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
closes #1534 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/web/src/ee/features/chat/agent.ts`:
- Around line 1033-1034: Update the files parameter type in createPrompt to
include the range and lineOffset properties accessed by the prompt template,
using types consistent with their existing usage in the files.map rendering and
addLineNumbers call.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ed24b0e1-853e-4d18-ac94-7a2ce45a6963
📒 Files selected for processing (7)
packages/web/src/app/(app)/components/editorContextMenu.tsxpackages/web/src/ee/features/chat/agent.test.tspackages/web/src/ee/features/chat/agent.tspackages/web/src/features/chat/useCreateNewChatThread.tspackages/web/src/features/chat/utils.test.tspackages/web/src/features/chat/utils.tspackages/web/src/features/tools/types.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit eedef3a. Configure here.
| }); | ||
|
|
||
| router.push(`/chat/${response.id}`); | ||
| }, [router, setChatState, toast]); |
There was a problem hiding this comment.
MCP prefs ignored on Ask
Medium Severity
createChatFromSource hardcodes disabledMcpServerIds to [] in both the message metadata and session state, so chats started from a code selection always re-enable every MCP server. createNewChatThread still honors DISABLED_MCP_SERVER_IDS_LOCAL_STORAGE_KEY, so Ask-from-selection bypasses the user’s saved connector preferences.
Reviewed by Cursor Bugbot for commit eedef3a. Configure here.


Summary
Adds an “Ask Sourcebot” action to the existing code-selection popover in Browse and search previews.
When code is selected, Ask Sourcebot:
Explain this selected code.This implements issue #1534 Option A only. Side panels and inline conversations are out of scope.
Screenshots
Testing
reports that limitation.
Use the first screenshot for Screenshots. Put the entitlement-error screenshot under Testing or omit it if you want
the PR to look cleaner.
Note
Low Risk
Changes are scoped to Ask UX and prompt assembly for optional line ranges; invalid ranges fail safe and existing full-file behavior remains when no range is set.
Overview
Adds Ask SourceBot to the code-selection popover in Browse (and shared code previews): alongside Share selection, users can open a new Ask chat seeded with
Explain this selected code.and a ranged file source for the current repo, revision, path, and selected lines.Chat creation uses new
createChatFromSourceonuseCreateNewChatThread, which builds the user message viacreateUIMessagewith optionalexplicitSources(not only file mentions).Agent / prompt path introduces
sliceFileSourceForPromptso the server still loads the file at the chosen revision but injects only the selected slice into the dynamic<files>block, withselected_linesmetadata andaddLineNumbersusing the real start line. Invalid ranges are dropped with a warning.Types extend
FileSourcewith an optional validatedrange(startLine/endLine) in chat and tools schemas.Reviewed by Cursor Bugbot for commit eedef3a. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
New Features
Bug Fixes
Tests