diff --git a/e2e/playwright/editor-tests.spec.ts b/e2e/playwright/editor-tests.spec.ts index 80c5cbb7f..82c5e8488 100644 --- a/e2e/playwright/editor-tests.spec.ts +++ b/e2e/playwright/editor-tests.spec.ts @@ -84,6 +84,63 @@ test.describe('Editor tests', () => { |> close(%)`) }) + test('if you click the format button it formats your code and executes so lints are still there', async ({ + page, + }) => { + const u = await getUtils(page) + await page.setViewportSize({ width: 1000, height: 500 }) + + await u.waitForAuthSkipAppStart() + + // check no error to begin with + await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() + + await u.codeLocator.click() + await page.keyboard.type(`const sketch_001 = startSketchOn('XY') + |> startProfileAt([-10, -10], %) + |> line([20, 0], %) + |> line([0, 20], %) + |> line([-20, 0], %) + |> close(%)`) + + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + // error in guter + await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible() + + // error text on hover + await page.hover('.cm-lint-marker-info') + await expect( + page.getByText('Identifiers must be lowerCamelCase').first() + ).toBeVisible() + + await page.locator('#code-pane button:first-child').click() + await page.locator('button:has-text("Format code")').click() + + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await expect(page.locator('.cm-content')) + .toHaveText(`const sketch_001 = startSketchOn('XY') + |> startProfileAt([-10, -10], %) + |> line([20, 0], %) + |> line([0, 20], %) + |> line([-20, 0], %) + |> close(%)`) + + // error in guter + await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible() + + // error text on hover + await page.hover('.cm-lint-marker-info') + await expect( + page.getByText('Identifiers must be lowerCamelCase').first() + ).toBeVisible() + }) + test('fold gutters work', async ({ page }) => { const u = await getUtils(page) @@ -241,6 +298,67 @@ test.describe('Editor tests', () => { |> close(%)`) }) + test('if you use the format keyboard binding it formats your code and executes so lints are shown', async ({ + page, + }) => { + const u = await getUtils(page) + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `const sketch_001 = startSketchOn('XY') + |> startProfileAt([-10, -10], %) + |> line([20, 0], %) + |> line([0, 20], %) + |> line([-20, 0], %) + |> close(%)` + ) + localStorage.setItem('disableAxis', 'true') + }) + await page.setViewportSize({ width: 1000, height: 500 }) + + await u.waitForAuthSkipAppStart() + + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + // error in guter + await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible() + + // error text on hover + await page.hover('.cm-lint-marker-info') + await expect( + page.getByText('Identifiers must be lowerCamelCase').first() + ).toBeVisible() + + // focus the editor + await u.codeLocator.click() + + // Hit alt+shift+f to format the code + await page.keyboard.press('Alt+Shift+KeyF') + + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + await expect(page.locator('.cm-content')) + .toHaveText(`const sketch_001 = startSketchOn('XY') + |> startProfileAt([-10, -10], %) + |> line([20, 0], %) + |> line([0, 20], %) + |> line([-20, 0], %) + |> close(%)`) + + // error in guter + await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible() + + // error text on hover + await page.hover('.cm-lint-marker-info') + await expect( + page.getByText('Identifiers must be lowerCamelCase').first() + ).toBeVisible() + }) + test('if you write kcl with lint errors you get lints', async ({ page }) => { const u = await getUtils(page) await page.setViewportSize({ width: 1000, height: 500 }) @@ -399,7 +517,7 @@ test.describe('Editor tests', () => { const width = 0.500 const height = 0.500 const dia = 4 - + fn squareHole = (l, w) => { const squareHoleSketch = startSketchOn('XY') |> startProfileAt([-width / 2, -length / 2], %) diff --git a/src/lang/KclSingleton.ts b/src/lang/KclSingleton.ts index 4a7604b3a..959ba598f 100644 --- a/src/lang/KclSingleton.ts +++ b/src/lang/KclSingleton.ts @@ -399,6 +399,9 @@ export class KclManager { codeManager.updateCodeStateEditor(code) // Write back to the file system. codeManager.writeToFile() + + // execute the code. + this.executeCode() } // There's overlapping responsibility between updateAst and executeAst. // updateAst was added as it was used a lot before xState migration so makes the port easier.