-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: add automatic selection context to user messages #9213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add selection context fields to WebviewMessage and ExtensionMessage types - Implement selection capture in ChatView on component mount - Add backend message handler to capture editor selection with line numbers - Store selection context in Task instance for use in environment details - Include selection context at start of environment details sent to LLM - Automatically clear selection context after use to prevent persistence - Add comprehensive tests for selection context functionality - Convert VSCode 0-based line numbers to 1-based for user-friendly display - Handle both workspace-relative and absolute file paths This allows users to select text in the editor and ask questions like "fix this" or "what does this do" without explicitly pasting code. The selection is automatically included as hidden context for the LLM.
All previous issues resolved. No new issues found.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| useMount(() => { | ||
| textAreaRef.current?.focus() | ||
| // Request initial selection context when component mounts | ||
| vscode.postMessage({ type: "requestSelectionContext" }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale selection context can be sent with messages if the user changes their selection after component mount but before sending a message. The requestSelectionContext call on mount stores the selection in the task, but if the user then selects different text and sends a message, the old selection context will be included. Selection context should be captured at message send time, not at component mount time, to ensure it reflects the user's current selection.
Fix it with Roo Code or mention @roomote and request a fix.
Fixed the reported issues. All local checks passed. |
- Move selection context request from mount-time to send-time in ChatView - Remove storage of selection context in Task instance to prevent staleness - Pass selection context through message flow as ephemeral parameter - Add getAndClearSelectionContext() method to Task for one-time use - Update tests to reflect new architecture with mocked getter method - Add selectionContext to CreateTaskOptions interface This ensures selection context is always fresh when sent and automatically cleared after use, preventing context leakage between messages.
|
@roomote why does the webview need to get the selection context? Can't the extension just get it when it needs it? |
Refactored selection capture to be handled directly by the extension instead of the webview. All local checks passed. |
- Remove selection context state management from ChatView - Remove requestSelectionContext message type and handler - Extension now captures selection directly in newTask and askResponse handlers - Eliminates race condition between selection request and message send - Simplifies architecture by removing unnecessary webview complexity
Working on extracting the repeated selection context type definition into a shared type. |
This PR implements automatic capture of editor selection as hidden context for LLM messages, allowing users to select text and ask questions like "fix this" or "what does this do" without explicitly pasting code.
Changes
Type Definitions
WebviewMessageandExtensionMessagetypesselectedText,selectionFilePath,selectionStartLine,selectionEndLineFrontend (ChatView)
requestSelectionContextmessageBackend (Message Handler)
requestSelectionContextcase to capture active editor selectionTask Management
selectionContextproperty to Task classnewTaskandaskResponsecasesEnvironment Details
Testing
User Experience
Users can now:
The feature seamlessly integrates with the existing message flow and follows established patterns in the codebase.
Important
This PR adds automatic capture of editor selection as context for LLM messages, enhancing user interactions by including selected text and file details without manual input.
selectedText,selectionFilePath,selectionStartLine,selectionEndLine.requestSelectionContextmessage.requestSelectionContextto capture active editor selection.Taskinstance.selectionContextproperty toTaskclass.newTaskandaskResponsecases.This description was created by
for e25c2d6. You can customize this summary. It will automatically update as commits are pushed.