Jump to error not lint (#3271)

* dont jump to lints

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2024-08-04 19:44:33 -07:00
committed by GitHub
parent a0167f6ba6
commit f4848d7dea
5 changed files with 110 additions and 9 deletions

View File

@ -1020,7 +1020,7 @@ test.describe('Editor tests', () => {
|> line([0, -10], %, $revolveAxis) |> line([0, -10], %, $revolveAxis)
|> close(%) |> close(%)
|> extrude(10, %) |> extrude(10, %)
const sketch001 = startSketchOn(box, revolveAxis) const sketch001 = startSketchOn(box, revolveAxis)
|> startProfileAt([5, 10], %) |> startProfileAt([5, 10], %)
|> line([0, -10], %) |> line([0, -10], %)
@ -8366,6 +8366,83 @@ test.describe('Code pane and errors', () => {
await badge.click() await badge.click()
// Ensure we have an error diagnostic. // 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()
}) })
}) })

View File

@ -337,7 +337,24 @@ fn svg = (surface, origin, depth) => {
|> close(%) |> close(%)
|> extrude(depth, %) |> 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 return 0
} }

View File

@ -22,7 +22,7 @@ import {
historyKeymap, historyKeymap,
history, history,
} from '@codemirror/commands' } from '@codemirror/commands'
import { lintGutter, lintKeymap } from '@codemirror/lint' import { diagnosticCount, lintGutter, lintKeymap } from '@codemirror/lint'
import { import {
foldGutter, foldGutter,
foldKeymap, foldKeymap,
@ -196,7 +196,10 @@ export const KclEditorPane = () => {
// On first load of this component, ensure we show the current errors // On first load of this component, ensure we show the current errors
// in the editor. // in the editor.
kclManager.setDiagnosticsForCurrentErrors() // Make sure we don't add them twice.
if (diagnosticCount(_editorView.state) === 0) {
kclManager.setDiagnosticsForCurrentErrors()
}
}} }}
/> />
</div> </div>

View File

@ -63,7 +63,7 @@ export const sidebarPanes: SidebarPane[] = [
}, },
onClick: (e) => { onClick: (e) => {
e.preventDefault() e.preventDefault()
editorManager.scrollToFirstDiagnosticIfExists() editorManager.scrollToFirstErrorDiagnosticIfExists()
}, },
}, },
}, },

View File

@ -141,14 +141,14 @@ export default class EditorManager {
}) })
} }
scrollToFirstDiagnosticIfExists() { scrollToFirstErrorDiagnosticIfExists() {
if (!this._editorView) return if (!this._editorView) return
let firstDiagnosticPos: [number, number] | null = null let firstDiagnosticPos: [number, number] | null = null
forEachDiagnostic( forEachDiagnostic(
this._editorView.state, this._editorView.state,
(d: Diagnostic, from: number, to: number) => { (d: Diagnostic, from: number, to: number) => {
if (!firstDiagnosticPos) { if (!firstDiagnosticPos && d.severity === 'error') {
firstDiagnosticPos = [from, to] firstDiagnosticPos = [from, to]
} }
} }
@ -161,7 +161,11 @@ export default class EditorManager {
selection: EditorSelection.create([ selection: EditorSelection.create([
EditorSelection.cursor(firstDiagnosticPos[0]), EditorSelection.cursor(firstDiagnosticPos[0]),
]), ]),
effects: [EditorView.scrollIntoView(firstDiagnosticPos[0])], effects: [
EditorView.scrollIntoView(
EditorSelection.range(firstDiagnosticPos[0], firstDiagnosticPos[1])
),
],
annotations: [ annotations: [
updateOutsideEditorEvent, updateOutsideEditorEvent,
Transaction.addToHistory.of(false), Transaction.addToHistory.of(false),