-
Notifications
You must be signed in to change notification settings - Fork 380
feat(vscode): allow the lsp loaded to be specified #5070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,213 @@ | ||
| import { test, expect } from './fixtures' | ||
| import { | ||
| createVirtualEnvironment, | ||
| openServerPage, | ||
| pipInstall, | ||
| REPO_ROOT, | ||
| SUSHI_SOURCE_PATH, | ||
| waitForLoadedSQLMesh, | ||
| } from './utils' | ||
| import path from 'path' | ||
| import fs from 'fs-extra' | ||
|
|
||
| async function setupPythonEnvironment(tempDir: string): Promise<void> { | ||
| // Create a temporary directory for the virtual environment | ||
| const venvDir = path.join(tempDir, '.venv') | ||
| fs.mkdirSync(venvDir, { recursive: true }) | ||
|
|
||
| // Create virtual environment | ||
| const pythonDetails = await createVirtualEnvironment(venvDir) | ||
|
|
||
| // Install sqlmesh from the local repository with LSP support | ||
| const customMaterializations = path.join( | ||
| REPO_ROOT, | ||
| 'examples', | ||
| 'custom_materializations', | ||
| ) | ||
| const sqlmeshWithExtras = `${REPO_ROOT}[lsp,bigquery]` | ||
| await pipInstall(pythonDetails, [sqlmeshWithExtras, customMaterializations]) | ||
| } | ||
|
|
||
| /** | ||
| * Creates an entrypoint file used to test the LSP configuration. | ||
| * | ||
| * The entrypoint file is a bash script that simply calls out to the | ||
| */ | ||
| const createEntrypointFile = ( | ||
| tempDir: string, | ||
| entrypointFileName: string, | ||
| bitToStripFromArgs = '', | ||
| ): { | ||
| entrypointFile: string | ||
| fileWhereStoredInputs: string | ||
| } => { | ||
| const entrypointFile = path.join(tempDir, entrypointFileName) | ||
| const fileWhereStoredInputs = path.join(tempDir, 'inputs.txt') | ||
| const sqlmeshLSPFile = path.join(tempDir, '.venv/bin/sqlmesh_lsp') | ||
|
|
||
| // Create the entrypoint file | ||
| fs.writeFileSync( | ||
| entrypointFile, | ||
| `#!/bin/bash | ||
| echo "$@" > ${fileWhereStoredInputs} | ||
| # Strip bitToStripFromArgs from the beginning of the args if it matches | ||
| if [[ "$1" == "${bitToStripFromArgs}" ]]; then | ||
| shift | ||
| fi | ||
| # Call the sqlmesh_lsp with the remaining arguments | ||
| ${sqlmeshLSPFile} "$@"`, | ||
| { mode: 0o755 }, // Make it executable | ||
| ) | ||
|
|
||
| return { | ||
| entrypointFile, | ||
| fileWhereStoredInputs, | ||
| } | ||
| } | ||
|
|
||
| test.describe('Test LSP Entrypoint configuration', () => { | ||
| test('specify single entrypoint relalative path', async ({ | ||
|
benfdking marked this conversation as resolved.
Outdated
|
||
| page, | ||
| sharedCodeServer, | ||
| tempDir, | ||
| }) => { | ||
| await fs.copy(SUSHI_SOURCE_PATH, tempDir) | ||
|
|
||
| await setupPythonEnvironment(tempDir) | ||
|
|
||
| const { fileWhereStoredInputs } = createEntrypointFile( | ||
| tempDir, | ||
| 'entrypoint.sh', | ||
| ) | ||
|
|
||
| const settings = { | ||
| 'sqlmesh.lspEntrypoint': './entrypoint.sh', | ||
| } | ||
| // Write the settings to the settings.json file | ||
| const settingsPath = path.join(tempDir, '.vscode', 'settings.json') | ||
| fs.mkdirSync(path.dirname(settingsPath), { recursive: true }) | ||
| fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2)) | ||
|
|
||
| await openServerPage(page, tempDir, sharedCodeServer) | ||
|
|
||
| // Wait for the models folder to be visible | ||
| await page.waitForSelector('text=models') | ||
|
|
||
| // Click on the models folder, excluding external_models | ||
| await page | ||
| .getByRole('treeitem', { name: 'models', exact: true }) | ||
| .locator('a') | ||
| .click() | ||
|
|
||
| // Open the customer_revenue_lifetime model | ||
| await page | ||
| .getByRole('treeitem', { name: 'customers.sql', exact: true }) | ||
| .locator('a') | ||
| .click() | ||
|
|
||
| await waitForLoadedSQLMesh(page) | ||
|
|
||
| // Check that the output file exists and contains the entrypoint script arguments | ||
| expect(fs.existsSync(fileWhereStoredInputs)).toBe(true) | ||
| expect(fs.readFileSync(fileWhereStoredInputs, 'utf8')).toBe(`--stdio | ||
| `) | ||
| }) | ||
|
|
||
| test('specify one entrypoint absolute path', async ({ | ||
| page, | ||
| sharedCodeServer, | ||
| tempDir, | ||
| }) => { | ||
| await fs.copy(SUSHI_SOURCE_PATH, tempDir) | ||
|
|
||
| await setupPythonEnvironment(tempDir) | ||
|
|
||
| const { entrypointFile, fileWhereStoredInputs } = createEntrypointFile( | ||
| tempDir, | ||
| 'entrypoint.sh', | ||
| ) | ||
| // Assert that the entrypoint file is an absolute path | ||
| expect(path.isAbsolute(entrypointFile)).toBe(true) | ||
|
|
||
| const settings = { | ||
| 'sqlmesh.lspEntrypoint': `${entrypointFile}`, | ||
| } | ||
| // Write the settings to the settings.json file | ||
| const settingsPath = path.join(tempDir, '.vscode', 'settings.json') | ||
| fs.mkdirSync(path.dirname(settingsPath), { recursive: true }) | ||
| fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2)) | ||
|
|
||
| await openServerPage(page, tempDir, sharedCodeServer) | ||
|
|
||
| // Wait for the models folder to be visible | ||
| await page.waitForSelector('text=models') | ||
|
|
||
| // Click on the models folder, excluding external_models | ||
| await page | ||
| .getByRole('treeitem', { name: 'models', exact: true }) | ||
| .locator('a') | ||
| .click() | ||
|
|
||
| // Open the customer_revenue_lifetime model | ||
| await page | ||
| .getByRole('treeitem', { name: 'customers.sql', exact: true }) | ||
| .locator('a') | ||
| .click() | ||
|
|
||
| await waitForLoadedSQLMesh(page) | ||
|
|
||
| // Check that the output file exists and contains the entrypoint script arguments | ||
| expect(fs.existsSync(fileWhereStoredInputs)).toBe(true) | ||
| expect(fs.readFileSync(fileWhereStoredInputs, 'utf8')).toBe(`--stdio | ||
| `) | ||
| }) | ||
|
|
||
| test('specify entrypoint with arguments', async ({ | ||
| page, | ||
| sharedCodeServer, | ||
| tempDir, | ||
| }) => { | ||
| await fs.copy(SUSHI_SOURCE_PATH, tempDir) | ||
|
|
||
| await setupPythonEnvironment(tempDir) | ||
|
|
||
| const { fileWhereStoredInputs } = createEntrypointFile( | ||
| tempDir, | ||
| 'entrypoint.sh', | ||
| '--argToIgnore', | ||
| ) | ||
|
|
||
| const settings = { | ||
| 'sqlmesh.lspEntrypoint': './entrypoint.sh --argToIgnore', | ||
| } | ||
| // Write the settings to the settings.json file | ||
| const settingsPath = path.join(tempDir, '.vscode', 'settings.json') | ||
| fs.mkdirSync(path.dirname(settingsPath), { recursive: true }) | ||
| fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2)) | ||
|
|
||
| await openServerPage(page, tempDir, sharedCodeServer) | ||
|
|
||
| // Wait for the models folder to be visible | ||
| await page.waitForSelector('text=models') | ||
|
|
||
| // Click on the models folder, excluding external_models | ||
| await page | ||
| .getByRole('treeitem', { name: 'models', exact: true }) | ||
| .locator('a') | ||
| .click() | ||
|
|
||
| // Open the customer_revenue_lifetime model | ||
| await page | ||
| .getByRole('treeitem', { name: 'customers.sql', exact: true }) | ||
| .locator('a') | ||
| .click() | ||
|
|
||
| await waitForLoadedSQLMesh(page) | ||
|
|
||
| // Check that the output file exists and contains the entrypoint script arguments | ||
| expect(fs.existsSync(fileWhereStoredInputs)).toBe(true) | ||
| expect(fs.readFileSync(fileWhereStoredInputs, 'utf8')) | ||
| .toBe(`--argToIgnore --stdio | ||
| `) | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.