Add tracking of operations for the feature tree (#4746)
* Add operations tracking for the timeline * Change to only track certain stdlib functions as operations * Update gen files * Add operations to simulation snapshot tests * Add tracking of positional function calls * Fix generated field names to be camel case in TS * Fix generated TS field names to match and better docs * Fix order of ops with patternTransform * Fix sweep to be included * Add new expected test outputs * Add tracking for startSketchOn * Update ops output to include startSketchOn * Fix serde field name * Fix output field name * Add tracking of operations that fail * Add snapshots of operations even when there's a KCL execution error * Add ops output for error executions * Add operations output to executor error * Update op source ranges * Remove tracking of circle() and polygon() since they're not needed * Update output without circle and polygon * Fix to track patternCircular3d and patternLinear3d * Remove tracking for mirror2d * Update ops output * Fix to track the correct source range of function definitions --------- Co-authored-by: Frank Noirot <frank@zoo.dev>
This commit is contained in:
@ -6,85 +6,94 @@ import { Diagnostic as LspDiagnostic } from 'vscode-languageserver-protocol'
|
||||
import { Text } from '@codemirror/state'
|
||||
import { EditorView } from 'codemirror'
|
||||
import { SourceRange } from 'lang/wasm'
|
||||
import { Operation } from 'wasm-lib/kcl/bindings/Operation'
|
||||
|
||||
type ExtractKind<T> = T extends { kind: infer K } ? K : never
|
||||
export class KCLError extends Error {
|
||||
kind: ExtractKind<RustKclError> | 'name'
|
||||
sourceRange: SourceRange
|
||||
msg: string
|
||||
operations: Operation[]
|
||||
|
||||
constructor(
|
||||
kind: ExtractKind<RustKclError> | 'name',
|
||||
msg: string,
|
||||
sourceRange: SourceRange
|
||||
sourceRange: SourceRange,
|
||||
operations: Operation[]
|
||||
) {
|
||||
super()
|
||||
this.kind = kind
|
||||
this.msg = msg
|
||||
this.sourceRange = sourceRange
|
||||
this.operations = operations
|
||||
Object.setPrototypeOf(this, KCLError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLLexicalError extends KCLError {
|
||||
constructor(msg: string, sourceRange: SourceRange) {
|
||||
super('lexical', msg, sourceRange)
|
||||
constructor(msg: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super('lexical', msg, sourceRange, operations)
|
||||
Object.setPrototypeOf(this, KCLSyntaxError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLInternalError extends KCLError {
|
||||
constructor(msg: string, sourceRange: SourceRange) {
|
||||
super('internal', msg, sourceRange)
|
||||
constructor(msg: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super('internal', msg, sourceRange, operations)
|
||||
Object.setPrototypeOf(this, KCLSyntaxError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLSyntaxError extends KCLError {
|
||||
constructor(msg: string, sourceRange: SourceRange) {
|
||||
super('syntax', msg, sourceRange)
|
||||
constructor(msg: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super('syntax', msg, sourceRange, operations)
|
||||
Object.setPrototypeOf(this, KCLSyntaxError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLSemanticError extends KCLError {
|
||||
constructor(msg: string, sourceRange: SourceRange) {
|
||||
super('semantic', msg, sourceRange)
|
||||
constructor(msg: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super('semantic', msg, sourceRange, operations)
|
||||
Object.setPrototypeOf(this, KCLSemanticError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLTypeError extends KCLError {
|
||||
constructor(msg: string, sourceRange: SourceRange) {
|
||||
super('type', msg, sourceRange)
|
||||
constructor(msg: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super('type', msg, sourceRange, operations)
|
||||
Object.setPrototypeOf(this, KCLTypeError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLUnimplementedError extends KCLError {
|
||||
constructor(msg: string, sourceRange: SourceRange) {
|
||||
super('unimplemented', msg, sourceRange)
|
||||
constructor(msg: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super('unimplemented', msg, sourceRange, operations)
|
||||
Object.setPrototypeOf(this, KCLUnimplementedError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLUnexpectedError extends KCLError {
|
||||
constructor(msg: string, sourceRange: SourceRange) {
|
||||
super('unexpected', msg, sourceRange)
|
||||
constructor(msg: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super('unexpected', msg, sourceRange, operations)
|
||||
Object.setPrototypeOf(this, KCLUnexpectedError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLValueAlreadyDefined extends KCLError {
|
||||
constructor(key: string, sourceRange: SourceRange) {
|
||||
super('name', `Key ${key} was already defined elsewhere`, sourceRange)
|
||||
constructor(key: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super(
|
||||
'name',
|
||||
`Key ${key} was already defined elsewhere`,
|
||||
sourceRange,
|
||||
operations
|
||||
)
|
||||
Object.setPrototypeOf(this, KCLValueAlreadyDefined.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class KCLUndefinedValueError extends KCLError {
|
||||
constructor(key: string, sourceRange: SourceRange) {
|
||||
super('name', `Key ${key} has not been defined`, sourceRange)
|
||||
constructor(key: string, sourceRange: SourceRange, operations: Operation[]) {
|
||||
super('name', `Key ${key} has not been defined`, sourceRange, operations)
|
||||
Object.setPrototypeOf(this, KCLUndefinedValueError.prototype)
|
||||
}
|
||||
}
|
||||
@ -100,11 +109,12 @@ export function lspDiagnosticsToKclErrors(
|
||||
return diagnostics
|
||||
.flatMap(
|
||||
({ range, message }) =>
|
||||
new KCLError('unexpected', message, [
|
||||
posToOffset(doc, range.start)!,
|
||||
posToOffset(doc, range.end)!,
|
||||
true,
|
||||
])
|
||||
new KCLError(
|
||||
'unexpected',
|
||||
message,
|
||||
[posToOffset(doc, range.start)!, posToOffset(doc, range.end)!, true],
|
||||
[]
|
||||
)
|
||||
)
|
||||
.sort((a, b) => {
|
||||
const c = a.sourceRange[0]
|
||||
|
||||
Reference in New Issue
Block a user