Display KCL errors as CodeMirror diagnostics in the editor's gutter (#197)

Also updates the CodeMirror version
This commit is contained in:
Adam Chalmers
2023-08-03 15:56:11 -05:00
committed by GitHub
parent 231371fb16
commit 8c5d7bf648
3 changed files with 25 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import { Diagnostic } from '@codemirror/lint'
export class KCLError {
kind: string | undefined
sourceRanges: [number, number][]
@ -55,3 +57,15 @@ export class KCLUndefinedValueError extends KCLError {
Object.setPrototypeOf(this, KCLUndefinedValueError.prototype)
}
}
/**
* Maps the KCL errors to an array of CodeMirror diagnostics.
* Currently the diagnostics are all errors, but in the future they could include lints.
* */
export function kclErrToDiagnostic(errors: KCLError[]): Diagnostic[] {
return errors.flatMap((err) => {
return err.sourceRanges.map(([from, to]) => {
return { from, to, message: err.msg, severity: 'error' }
})
})
}