diff --git a/e2e/playwright/flow-tests.spec.ts b/e2e/playwright/flow-tests.spec.ts index 16536ebc6..1013b2c08 100644 --- a/e2e/playwright/flow-tests.spec.ts +++ b/e2e/playwright/flow-tests.spec.ts @@ -1020,7 +1020,7 @@ test.describe('Editor tests', () => { |> line([0, -10], %, $revolveAxis) |> close(%) |> extrude(10, %) - + const sketch001 = startSketchOn(box, revolveAxis) |> startProfileAt([5, 10], %) |> line([0, -10], %) @@ -8366,6 +8366,83 @@ test.describe('Code pane and errors', () => { await badge.click() // Ensure we have an error diagnostic. - await expect(page.locator('.cm-lint-marker-error')).toBeVisible() + await expect(page.locator('.cm-lint-marker-error').first()).toBeVisible() + + // Hover over the error to see the error message + await page.hover('.cm-lint-marker-error') + await expect( + page + .getByText( + 'sketch profile must lie entirely on one side of the revolution axis' + ) + .first() + ).toBeVisible() + }) + + test('When error is not in view WITH LINTS you can click the badge to scroll to it', async ({ + page, + }) => { + const u = await getUtils(page) + + // Load the app with the working starter code + await page.addInitScript((code) => { + localStorage.setItem('persistCode', code) + }, TEST_CODE_LONG_WITH_ERROR_OUT_OF_VIEW) + + await page.setViewportSize({ width: 1200, height: 500 }) + await u.waitForAuthSkipAppStart() + + await page.waitForTimeout(1000) + + // Ensure badge is present + const codePaneButtonHolder = page.locator('#code-button-holder') + await expect(codePaneButtonHolder).toContainText('notification') + + // Ensure we have no errors in the gutter, since error out of view. + await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() + + // click in the editor to focus it + await page.locator('.cm-content').click() + + await page.waitForTimeout(500) + + // go to the start of the editor and enter more text which will trigger + // a lint error. + // GO to the start of the editor. + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('ArrowUp') + await page.keyboard.press('Home') + await page.keyboard.type('const foo_bar = 1') + await page.waitForTimeout(500) + await page.keyboard.press('Enter') + + // ensure we have a lint error + await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible() + + // Click the badge. + const badge = page.locator('#code-badge') + await expect(badge).toBeVisible() + await badge.click() + + // Ensure we have an error diagnostic. + await expect(page.locator('.cm-lint-marker-error').first()).toBeVisible() + + // Hover over the error to see the error message + await page.hover('.cm-lint-marker-error') + await expect( + page + .getByText( + 'sketch profile must lie entirely on one side of the revolution axis' + ) + .first() + ).toBeVisible() }) }) diff --git a/e2e/playwright/storageStates.ts b/e2e/playwright/storageStates.ts index 2eee9f51c..399d73b37 100644 --- a/e2e/playwright/storageStates.ts +++ b/e2e/playwright/storageStates.ts @@ -337,7 +337,24 @@ fn svg = (surface, origin, depth) => { |> close(%) |> extrude(depth, %) - "thing";kajsnd;akjsnd +const box = startSketchOn('XY') + |> startProfileAt([0, 0], %) + |> line([0, 10], %) + |> line([10, 0], %) + |> line([0, -10], %, $revolveAxis) + |> close(%) + |> extrude(10, %) + + const sketch001 = startSketchOn(box, revolveAxis) + |> startProfileAt([5, 10], %) + |> line([0, -10], %) + |> line([2, 0], %) + |> line([0, -10], %) + |> close(%) + |> revolve({ + axis: revolveAxis, + angle: 90 + }, %) return 0 } diff --git a/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx b/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx index a83b2c8a8..9610a756c 100644 --- a/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx @@ -22,7 +22,7 @@ import { historyKeymap, history, } from '@codemirror/commands' -import { lintGutter, lintKeymap } from '@codemirror/lint' +import { diagnosticCount, lintGutter, lintKeymap } from '@codemirror/lint' import { foldGutter, foldKeymap, @@ -196,7 +196,10 @@ export const KclEditorPane = () => { // On first load of this component, ensure we show the current errors // in the editor. - kclManager.setDiagnosticsForCurrentErrors() + // Make sure we don't add them twice. + if (diagnosticCount(_editorView.state) === 0) { + kclManager.setDiagnosticsForCurrentErrors() + } }} /> diff --git a/src/components/ModelingSidebar/ModelingPanes/index.ts b/src/components/ModelingSidebar/ModelingPanes/index.ts index 377e7f9b0..74f61ebe5 100644 --- a/src/components/ModelingSidebar/ModelingPanes/index.ts +++ b/src/components/ModelingSidebar/ModelingPanes/index.ts @@ -63,7 +63,7 @@ export const sidebarPanes: SidebarPane[] = [ }, onClick: (e) => { e.preventDefault() - editorManager.scrollToFirstDiagnosticIfExists() + editorManager.scrollToFirstErrorDiagnosticIfExists() }, }, }, diff --git a/src/editor/manager.ts b/src/editor/manager.ts index 60ca907f2..da04a2526 100644 --- a/src/editor/manager.ts +++ b/src/editor/manager.ts @@ -141,14 +141,14 @@ export default class EditorManager { }) } - scrollToFirstDiagnosticIfExists() { + scrollToFirstErrorDiagnosticIfExists() { if (!this._editorView) return let firstDiagnosticPos: [number, number] | null = null forEachDiagnostic( this._editorView.state, (d: Diagnostic, from: number, to: number) => { - if (!firstDiagnosticPos) { + if (!firstDiagnosticPos && d.severity === 'error') { firstDiagnosticPos = [from, to] } } @@ -161,7 +161,11 @@ export default class EditorManager { selection: EditorSelection.create([ EditorSelection.cursor(firstDiagnosticPos[0]), ]), - effects: [EditorView.scrollIntoView(firstDiagnosticPos[0])], + effects: [ + EditorView.scrollIntoView( + EditorSelection.range(firstDiagnosticPos[0], firstDiagnosticPos[1]) + ), + ], annotations: [ updateOutsideEditorEvent, Transaction.addToHistory.of(false),