diff --git a/e2e/playwright/flow-tests.spec.ts b/e2e/playwright/flow-tests.spec.ts index 1e5536cc2..52555a36e 100644 --- a/e2e/playwright/flow-tests.spec.ts +++ b/e2e/playwright/flow-tests.spec.ts @@ -8226,8 +8226,8 @@ test('Typing KCL errors induces a badge on the error logs pane button', async ({ await u.closeDebugPanel() // Ensure no badge is present - const errorLogsButton = page.getByRole('button', { name: 'KCL Code pane' }) - await expect(errorLogsButton).not.toContainText('notification') + const codePaneButton = page.getByRole('button', { name: 'KCL Code pane' }) + await expect(codePaneButton).not.toContainText('notification') // Delete a character to break the KCL await u.openKclCodePanel() @@ -8235,5 +8235,69 @@ test('Typing KCL errors induces a badge on the error logs pane button', async ({ await page.keyboard.press('Backspace') // Ensure that a badge appears on the button - await expect(errorLogsButton).toContainText('notification') + await expect(codePaneButton).toContainText('notification') +}) + +test('Opening and closing the code pane will consistently show error diagnostics', async ({ + page, +}) => { + const u = await getUtils(page) + + // Load the app with the working starter code + await page.addInitScript((code) => { + localStorage.setItem('persistCode', code) + }, bracket) + + await page.setViewportSize({ width: 1200, height: 900 }) + await u.waitForAuthSkipAppStart() + + // wait for execution done + await u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + // Ensure we have no errors in the gutter. + await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() + + // Ensure no badge is present + const codePaneButton = page.getByRole('button', { name: 'KCL Code pane' }) + await expect(codePaneButton).not.toContainText('notification') + + // Delete a character to break the KCL + await u.openKclCodePanel() + await page.getByText('extrude(').click() + await page.keyboard.press('Backspace') + + // Ensure that a badge appears on the button + await expect(codePaneButton).toContainText('notification') + + // Ensure we have an error diagnostic. + await expect(page.locator('.cm-lint-marker-error')).toBeVisible() + + // error text on hover + await page.hover('.cm-lint-marker-error') + await expect(page.getByText('Unexpected token').first()).toBeVisible() + + // Close the code pane + u.closeKclCodePanel() + + await page.waitForTimeout(500) + + // Ensure that a badge appears on the button + await expect(codePaneButton).toContainText('notification') + // Ensure we have no errors in the gutter. + await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() + + // Open the code pane + u.openKclCodePanel() + + // Ensure that a badge appears on the button + await expect(codePaneButton).toContainText('notification') + + // Ensure we have an error diagnostic. + await expect(page.locator('.cm-lint-marker-error')).toBeVisible() + + // error text on hover + await page.hover('.cm-lint-marker-error') + await expect(page.getByText('Unexpected token').first()).toBeVisible() }) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index f54da0591..79928e0c4 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2775,7 +2775,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -4638,9 +4638,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.121" +version = "1.0.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" +checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" dependencies = [ "indexmap 2.2.6", "itoa 1.0.11", diff --git a/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx b/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx index 7d1c3bc27..a83b2c8a8 100644 --- a/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx @@ -193,6 +193,10 @@ export const KclEditorPane = () => { if (_editorView === null) return editorManager.setEditorView(_editorView) + + // On first load of this component, ensure we show the current errors + // in the editor. + kclManager.setDiagnosticsForCurrentErrors() }} /> diff --git a/src/lang/KclSingleton.ts b/src/lang/KclSingleton.ts index 82219c4bb..e9da9ceb8 100644 --- a/src/lang/KclSingleton.ts +++ b/src/lang/KclSingleton.ts @@ -91,12 +91,16 @@ export class KclManager { set kclErrors(kclErrors) { if (kclErrors === this._kclErrors && this.lints.length === 0) return this._kclErrors = kclErrors - let diagnostics = kclErrorsToDiagnostics(kclErrors) + this.setDiagnosticsForCurrentErrors() + this._kclErrorsCallBack(kclErrors) + } + + setDiagnosticsForCurrentErrors() { + let diagnostics = kclErrorsToDiagnostics(this.kclErrors) if (this.lints.length > 0) { diagnostics = diagnostics.concat(this.lints) } editorManager.setDiagnostics(diagnostics) - this._kclErrorsCallBack(kclErrors) } addKclErrors(kclErrors: KCLError[]) {