Skip to content

Commit d758b4c

Browse files
Vamsi-kluclaude
authored andcommitted
fix(vscode): show the lineage model picker only after lookup settles
Keep "Loading models..." while get_active_file is pending and show the picker only when the active file misses, matches ambiguously, or the lookup fails, instead of falling back to the first model. A focus on a non-model file no longer cancels a pending lookup, and a models refetch keeps an open picker visible. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Vamsi-klu <nrvamsi13@gmail.com>
1 parent 6a93df3 commit d758b4c

3 files changed

Lines changed: 72 additions & 33 deletions

File tree

‎vscode/extension/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
77
## [Unreleased]
88

99
- Fixed lineage selection when Windows paths differ in casing or separators, using the extension host's platform for remote workspaces.
10+
- Lineage no longer defaults to the first model; it asks you to pick one when the active file does not match exactly one model or cannot be determined.
1011
- Initial release

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

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,55 @@ describe('lineage active-editor selection', () => {
183183
expect(screen.queryByRole('combobox')).toBeNull()
184184
})
185185

186-
it('keeps a manual selection when a pending initial lookup finishes', async () => {
186+
it('shows loading rather than the picker while the lookup is pending', async () => {
187187
let resolve!: (value: { fileUri: string; isWindows: boolean }) => void
188188
rpc.mockReturnValue(
189189
new Promise(done => {
190190
resolve = done
191191
}),
192192
)
193193
render(page())
194-
fireEvent.change(screen.getByRole('combobox', { name: 'Select a model' }), {
195-
target: { value: 'second' },
196-
})
197-
await selected('second')
194+
await act(async () => {})
195+
expect(screen.getByText('Loading models...')).toBeTruthy()
196+
expect(screen.queryByRole('combobox')).toBeNull()
198197
await act(async () => {
199-
resolve({ fileUri: models[0].full_path, isWindows: true })
198+
resolve({ fileUri: models[1].full_path, isWindows: true })
200199
})
201200
await selected('second')
202201
})
203202

204203
it.each([undefined, 'C:/project/README.md'])(
205-
'falls back to the first model at initialization for %s',
204+
'offers model selection without selecting one when the initial file is %s',
206205
async fileUri => {
207206
rpc.mockResolvedValue({ fileUri, isWindows: true })
208207
render(page())
209-
await selected('first')
208+
await screen.findByRole('combobox', { name: 'Select a model' })
209+
expect(screen.queryByTestId('selected-model')).toBeNull()
210+
expect(screen.queryByText('Loading models...')).toBeNull()
211+
expect(
212+
screen.getByText('Select a model to view its lineage.'),
213+
).toBeTruthy()
210214
},
211215
)
212216

217+
it('keeps the picker visible while a models refetch repeats the lookup', async () => {
218+
rpc.mockResolvedValueOnce({
219+
fileUri: 'C:/project/README.md',
220+
isWindows: true,
221+
})
222+
const view = render(page())
223+
await screen.findByRole('combobox', { name: 'Select a model' })
224+
rpc.mockReturnValue(new Promise(() => {}))
225+
api.mockReturnValue({ data: [...models], isLoading: false })
226+
view.rerender(page())
227+
await act(async () => {})
228+
expect(rpc).toHaveBeenCalledTimes(2)
229+
expect(
230+
screen.getByRole('combobox', { name: 'Select a model' }),
231+
).toBeTruthy()
232+
expect(screen.queryByText('Loading models...')).toBeNull()
233+
})
234+
213235
it('keeps selection when focusing a non-model file', async () => {
214236
render(page())
215237
await selected('first')
@@ -263,7 +285,7 @@ describe('lineage active-editor selection', () => {
263285
await selected('second')
264286
})
265287

266-
it('does not revive an initial match after focus moves to a non-model file', async () => {
288+
it('lets a late lookup select the model after a non-model focus', async () => {
267289
let resolve!: (value: { fileUri: string; isWindows: boolean }) => void
268290
rpc.mockReturnValue(
269291
new Promise(done => {
@@ -272,26 +294,39 @@ describe('lineage active-editor selection', () => {
272294
)
273295
render(page())
274296
focus('C:/project/README.md', true)
275-
await selected('first')
297+
await act(async () => {})
298+
expect(screen.queryByTestId('selected-model')).toBeNull()
299+
expect(screen.queryByRole('combobox')).toBeNull()
276300
await act(async () => {
277301
resolve({ fileUri: models[1].full_path, isWindows: true })
278302
})
279-
await selected('first')
303+
await selected('second')
280304
})
281305

282-
it('disposes an initial lookup on unmount', async () => {
283-
let resolve!: (value: { fileUri: string }) => void
306+
it('shows the picker for an ambiguous focus and ignores the stale lookup', async () => {
307+
const candidates = [
308+
{ name: 'upper', full_path: 'C:/A.sql' },
309+
{ name: 'lower', full_path: 'c:/a.sql' },
310+
{ name: 'other', full_path: 'C:/other.sql' },
311+
]
312+
api.mockReturnValue({ data: candidates, isLoading: false })
313+
let resolve!: (value: { fileUri: string; isWindows: boolean }) => void
284314
rpc.mockReturnValue(
285315
new Promise(done => {
286316
resolve = done
287317
}),
288318
)
289-
const view = render(page())
290-
view.unmount()
319+
render(page())
320+
expect(screen.getByText('Loading models...')).toBeTruthy()
321+
focus('C:/a.SQL', true)
322+
await screen.findByRole('combobox', { name: 'Select a model' })
291323
await act(async () => {
292-
resolve({ fileUri: models[0].full_path })
324+
resolve({ fileUri: 'C:/other.sql', isWindows: true })
293325
})
294326
expect(screen.queryByTestId('selected-model')).toBeNull()
327+
expect(
328+
screen.getByRole('combobox', { name: 'Select a model' }),
329+
).toBeTruthy()
295330
})
296331

297332
it('preserves original paths for graph navigation and invalidates on save', async () => {

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ function Lineage() {
8080
const [selectedModel, setSelectedModel] = useState<string | undefined>(
8181
undefined,
8282
)
83-
const [activeFileError, setActiveFileError] = useState(false)
83+
const [lookupStatus, setLookupStatus] = useState<
84+
'pending' | 'unmatched' | 'failed'
85+
>('pending')
8486
const { on } = useEventBus()
8587
const queryClient = useQueryClient()
8688

@@ -102,7 +104,6 @@ function Lineage() {
102104
let current = true
103105
const version = focusVersion.current
104106
// get_active_file uses a plain payload on the existing RPC wire protocol.
105-
setActiveFileError(false)
106107
rpc('get_active_file', {})
107108
.then(response => {
108109
if (!current || focusVersion.current !== version) return
@@ -113,15 +114,15 @@ function Lineage() {
113114
activeFile.fileUri,
114115
activeFile.isWindows,
115116
)
116-
setSelectedModel(
117-
previous =>
118-
previous ??
119-
(matches.length > 1 ? undefined : (matches[0] ?? models[0]).name),
120-
)
117+
if (matches.length === 1) {
118+
setSelectedModel(matches[0].name)
119+
} else {
120+
setLookupStatus('unmatched')
121+
}
121122
})
122123
.catch(() => {
123124
if (!current || focusVersion.current !== version) return
124-
setActiveFileError(true)
125+
setLookupStatus('failed')
125126
})
126127
return () => {
127128
current = false
@@ -143,19 +144,18 @@ function Lineage() {
143144
fileUri: string
144145
isWindows?: boolean
145146
}) => {
146-
focusVersion.current += 1
147147
const matches = findModelsByPath(
148148
Object.values(modelsRecord),
149149
file.fileUri,
150150
file.isWindows,
151151
)
152-
if (matches.length < 2) {
153-
setSelectedModel(
154-
previous =>
155-
matches[0]?.name ??
156-
previous ??
157-
(Array.isArray(models) ? models[0]?.name : undefined),
158-
)
152+
// A miss changes nothing, so a pending lookup stays in charge.
153+
if (!matches.length) return
154+
focusVersion.current += 1
155+
if (matches.length === 1) {
156+
setSelectedModel(matches[0].name)
157+
} else {
158+
setLookupStatus('unmatched')
159159
}
160160
}
161161

@@ -191,10 +191,13 @@ function Lineage() {
191191
return <div>No models available.</div>
192192
}
193193
if (selectedModel === undefined) {
194+
if (lookupStatus === 'pending') {
195+
return <div>Loading models...</div>
196+
}
194197
return (
195198
<div>
196199
<p>
197-
{activeFileError
200+
{lookupStatus === 'failed'
198201
? 'Unable to determine the active model. Select a model to view its lineage.'
199202
: 'Select a model to view its lineage.'}
200203
</p>

0 commit comments

Comments
 (0)