#6567 Code errors disappear when closing and reopening the editor (#7166)

* Fix error of not showing errors when reopening KCL code pane

* add test for errors not shown after reopening code pane

* rename test

* typo in e2e/playwright/editor-tests.spec.ts

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>

* lint

* fmt

* fix test: Opening and closing the code pane will consistently show error diagnostics

* PR feedback: use catch(reportRejection) for safeParse

* no need for lint rule

---------

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
This commit is contained in:
Andrew Varga
2025-05-23 18:41:37 +02:00
committed by GitHub
parent 4eee50d79e
commit 22f92942f6
3 changed files with 54 additions and 18 deletions

View File

@ -53,6 +53,7 @@ import {
kclEditorActor,
selectionEventSelector,
} from '@src/machines/kclEditorMachine'
import { reportRejection } from '@src/lib/trap'
export const editorShortcutMeta = {
formatCode: {
@ -210,12 +211,19 @@ export const KclEditorPane = () => {
editorManager.setEditorView(_editorView)
kclEditorActor.send({ type: 'setKclEditorMounted', data: true })
// On first load of this component, ensure we show the current errors
// in the editor.
// Make sure we don't add them twice.
if (diagnosticCount(_editorView.state) === 0) {
kclManager.setDiagnosticsForCurrentErrors()
}
// Update diagnostics as they are cleared when the editor is unmounted.
// Without this, errors would not be shown when closing and reopening the editor.
kclManager
.safeParse(codeManager.code)
.then(() => {
// On first load of this component, ensure we show the current errors
// in the editor.
// Make sure we don't add them twice.
if (diagnosticCount(_editorView.state) === 0) {
kclManager.setDiagnosticsForCurrentErrors()
}
})
.catch(reportRejection)
}}
/>
</div>