Skip to content

Commit ab504df

Browse files
committed
Implement a warning tooltip for the @ context button when no context files are available
1 parent 8e50316 commit ab504df

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.module.scss‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
display: flex;
209209

210210
&__button {
211+
position: relative;
211212
--size: 20px;
212213
display: flex;
213214
align-items: center;
@@ -226,6 +227,41 @@
226227
fill: var(--vscode-icon-foreground);
227228
}
228229
}
230+
231+
&__at-sign-warning {
232+
position: absolute;
233+
z-index: 1;
234+
bottom: calc(100% + 3px);
235+
left: 0;
236+
transform: translateX(-4px);
237+
font-size: var(--font-size-12px);
238+
white-space: nowrap;
239+
display: flex;
240+
align-items: center;
241+
gap: var(--padding-4px);
242+
padding: var(--padding-3px) var(--padding-6px);
243+
border-radius: var(--border-radius-6px);
244+
background-color: var(--vscode-quickInput-background);
245+
border: 1px solid var(--vscode-widget-border);
246+
box-shadow: 0 0 8px 2px var(--vscode-widget-shadow);
247+
248+
&::before {
249+
font-family: 'codicon';
250+
content: '\ea6c';
251+
color: var(--vscode-problemsWarningIcon-foreground);
252+
}
253+
254+
&::after {
255+
content: '';
256+
position: absolute;
257+
bottom: -5px;
258+
left: 8px;
259+
border-left: 5px solid transparent;
260+
border-right: 5px solid transparent;
261+
border-top: 5px solid var(--vscode-quickInput-background);
262+
filter: drop-shadow(0 1px 0.5px var(--vscode-widget-border));
263+
}
264+
}
229265
}
230266

231267
&__right {

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.tsx‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
5353
const input_ref = useRef<HTMLDivElement>(null)
5454
const container_ref = useRef<HTMLDivElement>(null)
5555
const [caret_position, set_caret_position] = useState(0)
56+
const [show_at_sign_tooltip, set_show_at_sign_tooltip] = useState(false)
5657
const {
5758
is_dropdown_open,
5859
toggle_dropdown,
@@ -217,6 +218,15 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
217218
document.removeEventListener('selectionchange', on_selection_change)
218219
}, [props.on_caret_position_change, props.value, props.context_file_paths])
219220

221+
useEffect(() => {
222+
if (show_at_sign_tooltip) {
223+
const timer = setTimeout(() => {
224+
set_show_at_sign_tooltip(false)
225+
}, 2000)
226+
return () => clearTimeout(timer)
227+
}
228+
}, [show_at_sign_tooltip])
229+
220230
const placeholder = useMemo(() => {
221231
const active_history = props.chat_history
222232

@@ -439,11 +449,25 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
439449
}}
440450
>
441451
<button
442-
onClick={() => props.on_at_sign_click()}
452+
onClick={() => {
453+
if (
454+
!props.context_file_paths ||
455+
props.context_file_paths.length === 0
456+
) {
457+
set_show_at_sign_tooltip(true)
458+
} else {
459+
props.on_at_sign_click()
460+
}
461+
}}
443462
className={cn(styles['footer__left__button'])}
444463
title="Reference file"
445464
>
446465
<Icon variant="AT_SIGN" />
466+
{show_at_sign_tooltip && (
467+
<div className={styles['footer__left__at-sign-warning']}>
468+
Nothing is selected in context.
469+
</div>
470+
)}
447471
</button>
448472
{!props.is_in_code_completions_mode && (
449473
<button

0 commit comments

Comments
 (0)