Skip to content

Commit 6a93df3

Browse files
Vamsi-kluyuki-kakegawa
authored andcommitted
fix(vscode): recover lineage selection after failed lookups
Show an explicit model picker after ambiguous or failed active-file lookup, without arbitrarily choosing a model. Cover manual selection and stale RPCs. Signed-off-by: deepinsight coder <32898216+Vamsi-klu@users.noreply.github.com>
1 parent e449007 commit 6a93df3

2 files changed

Lines changed: 121 additions & 22 deletions

File tree

‎vscode/react/src/pages/lineage.spec.tsx‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
3+
import {
4+
act,
5+
cleanup,
6+
fireEvent,
7+
render,
8+
screen,
9+
waitFor,
10+
} from '@testing-library/react'
411
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
512
import type { PropsWithChildren } from 'react'
613
import { EventBusProvider } from '@/hooks/eventBus'
@@ -139,6 +146,59 @@ describe('lineage active-editor selection', () => {
139146
render(page())
140147
await act(async () => {})
141148
expect(screen.queryByTestId('selected-model')).toBeNull()
149+
expect(screen.queryByText('Loading models...')).toBeNull()
150+
fireEvent.change(screen.getByRole('combobox', { name: 'Select a model' }), {
151+
target: { value: 'lower' },
152+
})
153+
await selected('lower')
154+
})
155+
156+
it('offers model selection when the active-file lookup fails', async () => {
157+
rpc.mockRejectedValue(new Error('RPC unavailable'))
158+
render(page())
159+
await screen.findByText(
160+
'Unable to determine the active model. Select a model to view its lineage.',
161+
)
162+
expect(screen.queryByText('Loading models...')).toBeNull()
163+
fireEvent.change(screen.getByRole('combobox', { name: 'Select a model' }), {
164+
target: { value: 'second' },
165+
})
166+
await selected('second')
167+
})
168+
169+
it('ignores a rejected lookup after a newer focus selects a model', async () => {
170+
let reject!: (reason: Error) => void
171+
rpc.mockReturnValue(
172+
new Promise((_, fail) => {
173+
reject = fail
174+
}),
175+
)
176+
render(page())
177+
focus('c:/project/SECOND.SQL', true)
178+
await selected('second')
179+
await act(async () => {
180+
reject(new Error('RPC unavailable'))
181+
})
182+
await selected('second')
183+
expect(screen.queryByRole('combobox')).toBeNull()
184+
})
185+
186+
it('keeps a manual selection when a pending initial lookup finishes', async () => {
187+
let resolve!: (value: { fileUri: string; isWindows: boolean }) => void
188+
rpc.mockReturnValue(
189+
new Promise(done => {
190+
resolve = done
191+
}),
192+
)
193+
render(page())
194+
fireEvent.change(screen.getByRole('combobox', { name: 'Select a model' }), {
195+
target: { value: 'second' },
196+
})
197+
await selected('second')
198+
await act(async () => {
199+
resolve({ fileUri: models[0].full_path, isWindows: true })
200+
})
201+
await selected('second')
142202
})
143203

144204
it.each([undefined, 'C:/project/README.md'])(
@@ -161,6 +221,7 @@ describe('lineage active-editor selection', () => {
161221
api.mockReturnValue({ data: [], isLoading: false })
162222
const view = render(page())
163223
expect(rpc).not.toHaveBeenCalled()
224+
expect(screen.getByText('No models available.')).toBeTruthy()
164225
expect(screen.queryByTestId('selected-model')).toBeNull()
165226
api.mockReturnValue({ data: models, isLoading: false })
166227
view.rerender(page())

‎vscode/react/src/pages/lineage.tsx‎

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ export function LineagePage() {
7575
)
7676
}
7777

78+
/** Follow editor focus without choosing arbitrarily between ambiguous model paths. */
7879
function Lineage() {
7980
const [selectedModel, setSelectedModel] = useState<string | undefined>(
8081
undefined,
8182
)
83+
const [activeFileError, setActiveFileError] = useState(false)
8284
const { on } = useEventBus()
8385
const queryClient = useQueryClient()
8486

@@ -100,21 +102,27 @@ function Lineage() {
100102
let current = true
101103
const version = focusVersion.current
102104
// get_active_file uses a plain payload on the existing RPC wire protocol.
103-
rpc('get_active_file', {}).then(response => {
104-
if (!current || focusVersion.current !== version) return
105-
const activeFile =
106-
response as unknown as RPCMethods['get_active_file']['result']
107-
const matches = findModelsByPath(
108-
models,
109-
activeFile.fileUri,
110-
activeFile.isWindows,
111-
)
112-
setSelectedModel(
113-
previous =>
114-
previous ??
115-
(matches.length > 1 ? undefined : (matches[0] ?? models[0]).name),
116-
)
117-
})
105+
setActiveFileError(false)
106+
rpc('get_active_file', {})
107+
.then(response => {
108+
if (!current || focusVersion.current !== version) return
109+
const activeFile =
110+
response as unknown as RPCMethods['get_active_file']['result']
111+
const matches = findModelsByPath(
112+
models,
113+
activeFile.fileUri,
114+
activeFile.isWindows,
115+
)
116+
setSelectedModel(
117+
previous =>
118+
previous ??
119+
(matches.length > 1 ? undefined : (matches[0] ?? models[0]).name),
120+
)
121+
})
122+
.catch(() => {
123+
if (!current || focusVersion.current !== version) return
124+
setActiveFileError(true)
125+
})
118126
return () => {
119127
current = false
120128
}
@@ -172,18 +180,48 @@ function Lineage() {
172180
return <div>Error: {modelsError.message}</div>
173181
}
174182

175-
if (
176-
isLoadingModels ||
177-
models === undefined ||
178-
modelsRecord === false ||
179-
selectedModel === undefined
180-
) {
183+
if (isLoadingModels || models === undefined || modelsRecord === false) {
181184
return <div>Loading models...</div>
182185
}
183186
if (!Array.isArray(models)) {
184187
return <div>Error: Models data is not in the expected format</div>
185188
}
186189

190+
if (!models.length) {
191+
return <div>No models available.</div>
192+
}
193+
if (selectedModel === undefined) {
194+
return (
195+
<div>
196+
<p>
197+
{activeFileError
198+
? 'Unable to determine the active model. Select a model to view its lineage.'
199+
: 'Select a model to view its lineage.'}
200+
</p>
201+
<select
202+
aria-label="Select a model"
203+
value=""
204+
onChange={event => setSelectedModel(event.target.value)}
205+
>
206+
<option
207+
value=""
208+
disabled
209+
>
210+
Select a model
211+
</option>
212+
{models.map(model => (
213+
<option
214+
key={model.name}
215+
value={model.name}
216+
>
217+
{model.name}
218+
</option>
219+
))}
220+
</select>
221+
</div>
222+
)
223+
}
224+
187225
return (
188226
<LineageComponentFromWeb
189227
selectedModel={selectedModel}

0 commit comments

Comments
 (0)