Display KCL errors as CodeMirror diagnostics in the editor's gutter (#197)
Also updates the CodeMirror version
This commit is contained in:
@ -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' }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user