-
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?
Changes from 2 commits
bb8d44d
e25c2d6
338d8d0
3c7a510
5065844
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| const textAreaRef = useRef<HTMLTextAreaElement>(null) | ||
| const [sendingDisabled, setSendingDisabled] = useState(false) | ||
| const [selectedImages, setSelectedImages] = useState<string[]>([]) | ||
| const [selectionContext, setSelectionContext] = useState<{ | ||
| selectedText?: string | ||
| selectionFilePath?: string | ||
| selectionStartLine?: number | ||
| selectionEndLine?: number | ||
| } | null>(null) | ||
|
|
||
| // We need to hold on to the ask because useEffect > lastMessage will always | ||
| // let us know when an ask comes in and handle it, but by the time | ||
|
|
@@ -563,7 +569,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| userRespondedRef.current = true | ||
|
|
||
| if (messagesRef.current.length === 0) { | ||
| vscode.postMessage({ type: "newTask", text, images }) | ||
| vscode.postMessage({ | ||
| type: "newTask", | ||
| text, | ||
| images, | ||
| ...(selectionContext || {}), | ||
| }) | ||
| } else if (clineAskRef.current) { | ||
| if (clineAskRef.current === "followup") { | ||
| markFollowUpAsAnswered() | ||
|
|
@@ -588,19 +599,26 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| askResponse: "messageResponse", | ||
| text, | ||
| images, | ||
| ...(selectionContext || {}), | ||
| }) | ||
| break | ||
| // There is no other case that a textfield should be enabled. | ||
| } | ||
| } else { | ||
| // This is a new message in an ongoing task. | ||
| vscode.postMessage({ type: "askResponse", askResponse: "messageResponse", text, images }) | ||
| vscode.postMessage({ | ||
| type: "askResponse", | ||
| askResponse: "messageResponse", | ||
| text, | ||
| images, | ||
| ...(selectionContext || {}), | ||
| }) | ||
| } | ||
|
|
||
| handleChatReset() | ||
| } | ||
| }, | ||
| [handleChatReset, markFollowUpAsAnswered, sendingDisabled, isStreaming, messageQueue.length], // messagesRef and clineAskRef are stable | ||
| [handleChatReset, markFollowUpAsAnswered, sendingDisabled, isStreaming, messageQueue.length, selectionContext], // messagesRef and clineAskRef are stable | ||
| ) | ||
|
|
||
| const handleSetChatBoxMessage = useCallback( | ||
|
|
@@ -743,6 +761,15 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| break | ||
| } | ||
| break | ||
| case "selectionContext": | ||
| // Update selection context when received from extension | ||
| setSelectionContext({ | ||
| selectedText: message.selectedText, | ||
| selectionFilePath: message.selectionFilePath, | ||
| selectionStartLine: message.selectionStartLine, | ||
| selectionEndLine: message.selectionEndLine, | ||
| }) | ||
| break | ||
| case "selectedImages": | ||
| // Only handle selectedImages if it's not for editing context | ||
| // When context is "edit", ChatRow will handle the images | ||
|
|
@@ -809,7 +836,11 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| useEvent("message", handleMessage) | ||
|
|
||
| // NOTE: the VSCode window needs to be focused for this to work. | ||
| useMount(() => textAreaRef.current?.focus()) | ||
| useMount(() => { | ||
| textAreaRef.current?.focus() | ||
| // Request initial selection context when component mounts | ||
| vscode.postMessage({ type: "requestSelectionContext" }) | ||
| }) | ||
|
Comment on lines
811
to
813
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Fix it with Roo Code or mention @roomote and request a fix. |
||
|
|
||
| const visibleMessages = useMemo(() => { | ||
| // Pre-compute checkpoint hashes that have associated user messages for O(1) lookup | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.