Skip to content

Commit e449007

Browse files
Vamsi-kluyuki-kakegawa
authored andcommitted
fix(vscode): follow active model paths on Windows
Signed-off-by: Vamsi-klu <nrvamsi13@gmail.com>
1 parent ca3f919 commit e449007

10 files changed

Lines changed: 576 additions & 48 deletions

File tree

‎vscode/bus/src/callbacks.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type VSCodeCallbackShape = Record<string, any>
2929
export type VSCodeCallback = {
3030
changeFocusOnFile: {
3131
path: string
32+
isWindows?: boolean
3233
}
3334
savedFile: {
3435
fileUri: string
@@ -47,6 +48,7 @@ export type RPCMethods = {
4748
params: {}
4849
result: {
4950
fileUri?: string
51+
isWindows?: boolean
5052
}
5153
}
5254
api_query: {

‎vscode/extension/CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66

77
## [Unreleased]
88

9-
- Initial release
9+
- Fixed lineage selection when Windows paths differ in casing or separators, using the extension host's platform for remote workspaces.
10+
- Initial release
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
import { beforeEach, describe, expect, it, vi } from 'vitest'
4+
import type { TextEditor, Uri, WebviewView } from 'vscode'
5+
import type { LSPClient } from '../lsp/lsp'
6+
import { LineagePanel } from './lineagePanel'
7+
8+
const state = vi.hoisted(() => ({
9+
isWindows: true,
10+
editor: undefined as TextEditor | undefined,
11+
focus: undefined as ((editor: TextEditor | undefined) => void) | undefined,
12+
saved: undefined as
13+
| ((document: { uri: { toString: () => string } }) => void)
14+
| undefined,
15+
receive: undefined as ((message: unknown) => Promise<void>) | undefined,
16+
post: vi.fn(),
17+
dispose: vi.fn(),
18+
}))
19+
20+
vi.mock('vscode', () => ({
21+
Uri: { joinPath: () => 'asset' },
22+
window: {
23+
get activeTextEditor() {
24+
return state.editor
25+
},
26+
onDidChangeActiveTextEditor: (callback: typeof state.focus) => {
27+
state.focus = callback
28+
return { dispose: state.dispose }
29+
},
30+
},
31+
workspace: {
32+
onDidSaveTextDocument: (callback: typeof state.saved) => {
33+
state.saved = callback
34+
return { dispose: state.dispose }
35+
},
36+
},
37+
}))
38+
vi.mock('@bus/result', () => ({ isErr: () => false }))
39+
vi.mock('../utilities/isWindows', () => ({
40+
get IS_WINDOWS() {
41+
return state.isWindows
42+
},
43+
}))
44+
45+
function editor(fsPath: string): TextEditor {
46+
return { document: { uri: { fsPath } } } as TextEditor
47+
}
48+
49+
function panel() {
50+
const instance = new LineagePanel({} as Uri, {} as LSPClient)
51+
instance.resolveWebviewView({
52+
webview: {
53+
postMessage: state.post,
54+
asWebviewUri: (uri: unknown) => uri,
55+
onDidReceiveMessage: (callback: typeof state.receive) => {
56+
state.receive = callback
57+
return { dispose: state.dispose }
58+
},
59+
},
60+
} as unknown as WebviewView)
61+
return instance
62+
}
63+
64+
describe('lineage editor path messages', () => {
65+
beforeEach(() => {
66+
vi.clearAllMocks()
67+
state.editor = undefined
68+
})
69+
70+
it.each([true, false])(
71+
'sends extension-host platform %s with active-file RPC and focus events',
72+
async isWindows => {
73+
state.isWindows = isWindows
74+
state.editor = editor('C:\\Project\\A %20#.sql')
75+
const instance = panel()
76+
await state.receive?.({
77+
key: 'rpcRequest',
78+
payload: { method: 'get_active_file', requestId: 'active', params: {} },
79+
})
80+
expect(state.post).toHaveBeenLastCalledWith({
81+
key: 'rpcResponse',
82+
payload: {
83+
requestId: 'active',
84+
result: { fileUri: 'C:\\Project\\A %20#.sql', isWindows },
85+
},
86+
})
87+
state.focus?.(editor('C:\\Project\\B.sql'))
88+
expect(state.post).toHaveBeenLastCalledWith({
89+
key: 'vscode_send',
90+
payload: {
91+
key: 'changeFocusOnFile',
92+
payload: { path: 'C:\\Project\\B.sql', isWindows },
93+
},
94+
})
95+
instance.dispose()
96+
expect(state.dispose).toHaveBeenCalledTimes(3)
97+
},
98+
)
99+
100+
it('reports no editor and preserves saved-file URI payloads', async () => {
101+
state.isWindows = true
102+
const instance = panel()
103+
await state.receive?.({
104+
key: 'rpcRequest',
105+
payload: { method: 'get_active_file', requestId: 'none', params: {} },
106+
})
107+
expect(state.post).toHaveBeenLastCalledWith({
108+
key: 'rpcResponse',
109+
payload: {
110+
requestId: 'none',
111+
result: { fileUri: undefined, isWindows: true },
112+
},
113+
})
114+
state.focus?.(undefined)
115+
expect(state.post).toHaveBeenCalledOnce()
116+
state.saved?.({
117+
uri: { toString: () => 'file:///c%3A/Project/A%20%23.sql' },
118+
})
119+
expect(state.post).toHaveBeenLastCalledWith({
120+
key: 'vscode_send',
121+
payload: {
122+
key: 'savedFile',
123+
payload: { fileUri: 'file:///c%3A/Project/A%20%23.sql' },
124+
},
125+
})
126+
instance.dispose()
127+
})
128+
})

‎vscode/extension/src/webviews/lineagePanel.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { getWorkspaceFolders } from '../utilities/common/vscodeapi'
1212
import { LSPClient } from '../lsp/lsp'
1313
import { isErr } from '@bus/result'
14+
import { IS_WINDOWS } from '../utilities/isWindows'
1415

1516
export class LineagePanel implements WebviewViewProvider, Disposable {
1617
public static readonly viewType = 'sqlmesh.lineage'
@@ -47,7 +48,10 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
4748
key: 'vscode_send',
4849
payload: {
4950
key: 'changeFocusOnFile',
50-
payload: { path: editor.document.uri.fsPath },
51+
payload: {
52+
path: editor.document.uri.fsPath,
53+
isWindows: IS_WINDOWS,
54+
},
5155
},
5256
})
5357
}
@@ -144,6 +148,7 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
144148
requestId,
145149
result: {
146150
fileUri: active_file,
151+
isWindows: IS_WINDOWS,
147152
},
148153
},
149154
}

‎vscode/extension/tests/lineage.spec.ts‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { test, Page } from './fixtures'
1+
import { test, expect, Page } from './fixtures'
22
import path from 'path'
33
import fs from 'fs-extra'
44
import os from 'os'
55
import {
66
openLineageView,
7+
openFile,
78
openServerPage,
89
SUSHI_SOURCE_PATH,
910
waitForLoadedSQLMesh,
@@ -19,7 +20,7 @@ async function testLineageWithProjectPath(page: Page): Promise<void> {
1920
await waitForLoadedSQLMesh(page)
2021
}
2122

22-
test('Lineage panel renders correctly - no project path config (default)', async ({
23+
test('Lineage panel follows the initial editor and model switches - no project path config (default)', async ({
2324
page,
2425
sharedCodeServer,
2526
tempDir,
@@ -28,7 +29,28 @@ test('Lineage panel renders correctly - no project path config (default)', async
2829
await createPythonInterpreterSettingsSpecifier(tempDir)
2930

3031
await openServerPage(page, tempDir, sharedCodeServer)
31-
await testLineageWithProjectPath(page)
32+
await openFile(page, 'models/waiters.py')
33+
await waitForLoadedSQLMesh(page)
34+
await openLineageView(page)
35+
36+
// The main model has the brand ring; checking it distinguishes selection
37+
// from a model that merely appears as a dependency in the graph.
38+
const expectMainModel = async (name: string) => {
39+
await expect
40+
.poll(async () => {
41+
for (const frame of page.frames()) {
42+
const main = frame.locator('.react-flow__node .ring-brand-50')
43+
if (await main.locator(`[title*="${name}"]`).count()) return true
44+
}
45+
return false
46+
})
47+
.toBe(true)
48+
}
49+
await expectMainModel('waiters')
50+
await openFile(page, 'models/orders.py')
51+
await expectMainModel('orders')
52+
await openFile(page, 'models/waiters.py')
53+
await expectMainModel('waiters')
3254
})
3355

3456
test('Lineage panel renders correctly - relative project path', async ({
@@ -129,7 +151,6 @@ test('Lineage panel renders correctly - absolute path project outside of workspa
129151
await testLineageWithProjectPath(page)
130152
})
131153

132-
// These work on local machine when debuggin but not on CI, so skipping for now
133154
test('Lineage panel renders correctly - multiworkspace setup', async ({
134155
page,
135156
sharedCodeServer,
@@ -174,7 +195,12 @@ test('Lineage panel renders correctly - multiworkspace setup', async ({
174195
)
175196

176197
await openServerPage(page, workspaceFilePath, sharedCodeServer)
177-
await page.reload()
198+
await expect(
199+
page.getByRole('treeitem', { name: 'sushi1', exact: true }),
200+
).toBeVisible()
201+
await expect(
202+
page.getByRole('treeitem', { name: 'sushi2', exact: true }),
203+
).toBeVisible()
178204
await testLineageWithProjectPath(page)
179205
})
180206

@@ -228,6 +254,11 @@ test('Lineage panel renders correctly - multiworkspace setup reversed', async ({
228254
)
229255

230256
await openServerPage(page, workspaceFilePath, sharedCodeServer)
231-
await page.reload()
257+
await expect(
258+
page.getByRole('treeitem', { name: 'sushi1', exact: true }),
259+
).toBeVisible()
260+
await expect(
261+
page.getByRole('treeitem', { name: 'sushi2', exact: true }),
262+
).toBeVisible()
232263
await testLineageWithProjectPath(page)
233264
})

‎vscode/react/src/hooks/eventBus.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
export type EventMap = {
1515
changeFocusedFile: {
1616
fileUri: string
17+
isWindows?: boolean
1718
}
1819
savedFile: {
1920
fileUri: string

0 commit comments

Comments
 (0)