Skip to content

Commit 3732689

Browse files
committed
feat(vscode): allow configuring project path
1 parent 8028656 commit 3732689

2 files changed

Lines changed: 62 additions & 68 deletions

File tree

vscode/extension/src/utilities/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface SqlmeshConfiguration {
1616
export function getSqlmeshConfiguration(): SqlmeshConfiguration {
1717
const config = workspace.getConfiguration('sqlmesh')
1818
const projectPath = config.get<string>('projectPath', '')
19-
2019
return {
2120
projectPath,
2221
}

vscode/extension/tests/lineage.spec.ts

Lines changed: 62 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,8 @@ const SUSHI_SOURCE_PATH = path.join(__dirname, '..', '..', '..', 'examples', 'su
1414
* Helper function to launch VS Code and test lineage with given project path config
1515
*/
1616
async function testLineageWithProjectPath(
17-
workspaceDir: string,
18-
projectDir: string,
19-
projectPathConfig?: string
17+
window: Page,
2018
): Promise<void> {
21-
const ciArgs = process.env.CI ? [
22-
'--disable-gpu',
23-
'--headless',
24-
'--no-sandbox',
25-
'--disable-dev-shm-usage',
26-
'--window-position=-10000,0',
27-
] : [];
28-
29-
const userDataDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-user-data-'));
30-
31-
try {
32-
// If projectPathConfig is provided, create .vscode/settings.json in the workspace
33-
if (projectPathConfig !== undefined) {
34-
const vscodeDir = path.join(workspaceDir, '.vscode');
35-
await fs.ensureDir(vscodeDir);
36-
const settings = {
37-
"sqlmesh.projectPath": projectPathConfig
38-
};
39-
await fs.writeJson(path.join(vscodeDir, 'settings.json'), settings, { spaces: 2 });
40-
}
41-
42-
const args = [
43-
...ciArgs,
44-
`--extensionDevelopmentPath=${EXT_PATH}`,
45-
'--disable-workspace-trust',
46-
'--disable-telemetry',
47-
`--user-data-dir=${userDataDir}`,
48-
workspaceDir,
49-
];
50-
51-
const electronApp = await electron.launch({
52-
executablePath: VS_CODE_EXE,
53-
args,
54-
});
55-
56-
const window = await electronApp.firstWindow();
57-
await window.waitForLoadState('domcontentloaded');
58-
await window.waitForLoadState('networkidle');
59-
60-
// Wait a bit for the extension to fully initialize with the settings
61-
await window.waitForTimeout(2000);
62-
6319
// Trigger lineage command
6420
await window.keyboard.press(process.platform === 'darwin' ? 'Meta+Shift+P' : 'Control+Shift+P');
6521
await window.keyboard.type('Lineage: Focus On View');
@@ -68,56 +24,95 @@ async function testLineageWithProjectPath(
6824
// Wait for "Loaded SQLmesh Context" text to appear
6925
const loadedContextText = window.locator('text=Loaded SQLMesh Context');
7026
await expect(loadedContextText.first()).toBeVisible({ timeout: 15000 });
27+
}
7128

29+
/**
30+
* Launch VS Code and return the window and a function to close the app.
31+
* @param workspaceDir The workspace directory to open.
32+
* @returns The window and a function to close the app.
33+
*/
34+
export const startVSCode = async (workspaceDir: string): Promise<{
35+
window: Page,
36+
close: () => Promise<void>,
37+
}> => {
38+
const userDataDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-user-data-'));
39+
const ciArgs = process.env.CI ? [
40+
'--disable-gpu',
41+
'--headless',
42+
'--no-sandbox',
43+
'--disable-dev-shm-usage',
44+
'--window-position=-10000,0',
45+
] : [];
46+
const args = [
47+
...ciArgs,
48+
`--extensionDevelopmentPath=${EXT_PATH}`,
49+
'--disable-workspace-trust',
50+
'--disable-telemetry',
51+
`--user-data-dir=${userDataDir}`,
52+
workspaceDir,
53+
];
54+
const electronApp = await electron.launch({
55+
executablePath: VS_CODE_EXE,
56+
args,
57+
});
58+
const window = await electronApp.firstWindow();
59+
await window.waitForLoadState('domcontentloaded');
60+
await window.waitForLoadState('networkidle');
61+
await window.waitForTimeout(2000);
62+
return { window, close: async () => {
7263
await electronApp.close();
73-
} finally {
7464
await fs.remove(userDataDir);
75-
}
76-
}
77-
78-
export const startVSCode = async (workspaceDir: string) => {
79-
65+
} };
8066
}
8167

8268
test('Lineage panel renders correctly - no project path config (default)', async () => {
8369
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-sushi-'));
8470
await fs.copy(SUSHI_SOURCE_PATH, tempDir);
85-
8671
try {
87-
await testLineageWithProjectPath(tempDir, tempDir);
88-
} finally {
72+
const { window, close } = await startVSCode(tempDir);
73+
await testLineageWithProjectPath(window);
74+
await close();
75+
} finally {
8976
await fs.remove(tempDir);
9077
}
9178
});
9279

9380
test('Lineage panel renders correctly - relative project path', async () => {
94-
// Create workspace directory with subdirectory containing the project
9581
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-workspace-'));
96-
const projectSubdir = path.join(workspaceDir, 'projects', 'sushi');
97-
await fs.ensureDir(path.dirname(projectSubdir));
98-
await fs.copy(SUSHI_SOURCE_PATH, projectSubdir);
82+
const projectDir = path.join(workspaceDir, 'projects', 'sushi');
83+
await fs.copy(SUSHI_SOURCE_PATH, projectDir);
84+
85+
const settings = {
86+
"sqlmesh.projectPath": path.relative(workspaceDir, projectDir),
87+
};
88+
await fs.ensureDir(path.join(workspaceDir, '.vscode'));
89+
await fs.writeJson(path.join(workspaceDir, '.vscode', 'settings.json'), settings, { spaces: 2 });
9990

10091
try {
101-
// Test with relative path
102-
await testLineageWithProjectPath(workspaceDir, projectSubdir, 'projects/sushi');
92+
const { window, close } = await startVSCode(workspaceDir);
93+
await testLineageWithProjectPath(window);
94+
await close();
10395
} finally {
10496
await fs.remove(workspaceDir);
10597
}
10698
});
10799

108100
test('Lineage panel renders correctly - absolute project path', async () => {
109-
// Create workspace directory
110101
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-workspace-'));
111-
112-
// Create project directory outside workspace
113-
const projectDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-sushi-project-'));
102+
const projectDir = path.join(workspaceDir, 'projects', 'sushi');
103+
await fs.ensureDir(path.join(workspaceDir, '.vscode'));
114104
await fs.copy(SUSHI_SOURCE_PATH, projectDir);
105+
await fs.ensureDir(path.join(workspaceDir, '.vscode'));
106+
const settings = {
107+
"sqlmesh.projectPath": projectDir,
108+
};
109+
await fs.writeJson(path.join(workspaceDir, '.vscode', 'settings.json'), settings, { spaces: 2 });
115110

116111
try {
117-
// Test with absolute path
118-
await testLineageWithProjectPath(workspaceDir, projectDir, projectDir);
112+
const { window, close } = await startVSCode(workspaceDir);
113+
await testLineageWithProjectPath(window);
114+
await close();
119115
} finally {
120116
await fs.remove(workspaceDir);
121-
await fs.remove(projectDir);
122117
}
123118
});

0 commit comments

Comments
 (0)