Rust artifact graph (#5068)
* Start porting artifact graph creation to Rust * Add most of artifact graph creation * Add handling loft command from recent PR * Refactor artifact merge code so that it errors when a new artifact type is added * Add sweep subtype * Finish implementation of build artifact graph * Fix wasm.ts to use new combined generated ts-rs file * Fix Rust lints * Fix lints * Fix up replacement code * Add artifact graph to WASM outcome * Add artifact graph to simulation test output * Add new artifact graph output snapshots * Fix wall field and reduce unreachable code * Change field order for subtype * Change subtype to be determined from the request, like the TS * Fix plane sweep_id * Condense code * Change ID types to be properly optional * Change to favor the new ID, the same as TS * Fix to make error impossible * Rename artifact type tag values to match TS * Fix name of field on Cap * Update outputs * Change to use Rust source range * Update output snapshots * Add conversion to mermaid mind map and add to snapshot tests * Add new mermaid mind map output * Add flowchart * Remove raw artifact graph from tests * Remove JSON artifact graph output * Update output file with header * Update output after adding flowchart * Fix flowchart to not have duplicate edges, one in each direction * Fix not not output duplicate edges in flowcharts * Change flowchart edge style to be more obvious when a direction is missing * Update output after deduplication of edges * Fix not not skip sketch-on-face artifacts * Add docs * Fix edge iteration order to be stable * Update output after fixing order * Port TS artifactGraph.test.ts tests to simulation tests * Add grouping segments and solid2ds with their path * Update output flowcharts since grouping paths * Remove TS artifactGraph tests * Remove unused d3 dependencies * Fix to track loft ID on paths * Add command ID to error messages * Move artifact graph test code to a separate file since it's a large file * Reduce function visibility * Remove TS artifact graph code * Fix spelling error with serde * Add TODO for edge cut consumed ID * Add comment about mermaid edge rank * Fix mermaid flowchart edge cuts to appear as children of their edges * Update output since fixing flowchart order * Fix to always build the artifact graph even when there's a KCL error * Add artifact graph to error output * Change optional ID merge to match TS * Remove redundant SourceRange definition * Remove Rust-flavored default source range function * Add helper for source range creation * Update doc comment for the website * Update docs after doc comment change * Fix to save engine responses in execution cache * Remove unused import * Fix to not call WASM function before beforeAll callback is run * Remove more unused imports
This commit is contained in:
		@ -5,7 +5,13 @@ import { posToOffset } from '@kittycad/codemirror-lsp-client'
 | 
			
		||||
import { Diagnostic as LspDiagnostic } from 'vscode-languageserver-protocol'
 | 
			
		||||
import { Text } from '@codemirror/state'
 | 
			
		||||
import { EditorView } from 'codemirror'
 | 
			
		||||
import { ArtifactCommand, SourceRange } from 'lang/wasm'
 | 
			
		||||
import {
 | 
			
		||||
  ArtifactCommand,
 | 
			
		||||
  ArtifactGraph,
 | 
			
		||||
  defaultArtifactGraph,
 | 
			
		||||
  isTopLevelModule,
 | 
			
		||||
  SourceRange,
 | 
			
		||||
} from 'lang/wasm'
 | 
			
		||||
import { Operation } from 'wasm-lib/kcl/bindings/Operation'
 | 
			
		||||
 | 
			
		||||
type ExtractKind<T> = T extends { kind: infer K } ? K : never
 | 
			
		||||
@ -15,13 +21,15 @@ export class KCLError extends Error {
 | 
			
		||||
  msg: string
 | 
			
		||||
  operations: Operation[]
 | 
			
		||||
  artifactCommands: ArtifactCommand[]
 | 
			
		||||
  artifactGraph: ArtifactGraph
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
    kind: ExtractKind<RustKclError> | 'name',
 | 
			
		||||
    msg: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super()
 | 
			
		||||
    this.kind = kind
 | 
			
		||||
@ -29,6 +37,7 @@ export class KCLError extends Error {
 | 
			
		||||
    this.sourceRange = sourceRange
 | 
			
		||||
    this.operations = operations
 | 
			
		||||
    this.artifactCommands = artifactCommands
 | 
			
		||||
    this.artifactGraph = artifactGraph
 | 
			
		||||
    Object.setPrototypeOf(this, KCLError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -38,9 +47,17 @@ export class KCLLexicalError extends KCLError {
 | 
			
		||||
    msg: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super('lexical', msg, sourceRange, operations, artifactCommands)
 | 
			
		||||
    super(
 | 
			
		||||
      'lexical',
 | 
			
		||||
      msg,
 | 
			
		||||
      sourceRange,
 | 
			
		||||
      operations,
 | 
			
		||||
      artifactCommands,
 | 
			
		||||
      artifactGraph
 | 
			
		||||
    )
 | 
			
		||||
    Object.setPrototypeOf(this, KCLSyntaxError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -50,9 +67,17 @@ export class KCLInternalError extends KCLError {
 | 
			
		||||
    msg: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super('internal', msg, sourceRange, operations, artifactCommands)
 | 
			
		||||
    super(
 | 
			
		||||
      'internal',
 | 
			
		||||
      msg,
 | 
			
		||||
      sourceRange,
 | 
			
		||||
      operations,
 | 
			
		||||
      artifactCommands,
 | 
			
		||||
      artifactGraph
 | 
			
		||||
    )
 | 
			
		||||
    Object.setPrototypeOf(this, KCLSyntaxError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -62,9 +87,17 @@ export class KCLSyntaxError extends KCLError {
 | 
			
		||||
    msg: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super('syntax', msg, sourceRange, operations, artifactCommands)
 | 
			
		||||
    super(
 | 
			
		||||
      'syntax',
 | 
			
		||||
      msg,
 | 
			
		||||
      sourceRange,
 | 
			
		||||
      operations,
 | 
			
		||||
      artifactCommands,
 | 
			
		||||
      artifactGraph
 | 
			
		||||
    )
 | 
			
		||||
    Object.setPrototypeOf(this, KCLSyntaxError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -74,9 +107,17 @@ export class KCLSemanticError extends KCLError {
 | 
			
		||||
    msg: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super('semantic', msg, sourceRange, operations, artifactCommands)
 | 
			
		||||
    super(
 | 
			
		||||
      'semantic',
 | 
			
		||||
      msg,
 | 
			
		||||
      sourceRange,
 | 
			
		||||
      operations,
 | 
			
		||||
      artifactCommands,
 | 
			
		||||
      artifactGraph
 | 
			
		||||
    )
 | 
			
		||||
    Object.setPrototypeOf(this, KCLSemanticError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -86,9 +127,10 @@ export class KCLTypeError extends KCLError {
 | 
			
		||||
    msg: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super('type', msg, sourceRange, operations, artifactCommands)
 | 
			
		||||
    super('type', msg, sourceRange, operations, artifactCommands, artifactGraph)
 | 
			
		||||
    Object.setPrototypeOf(this, KCLTypeError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -98,9 +140,17 @@ export class KCLUnimplementedError extends KCLError {
 | 
			
		||||
    msg: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super('unimplemented', msg, sourceRange, operations, artifactCommands)
 | 
			
		||||
    super(
 | 
			
		||||
      'unimplemented',
 | 
			
		||||
      msg,
 | 
			
		||||
      sourceRange,
 | 
			
		||||
      operations,
 | 
			
		||||
      artifactCommands,
 | 
			
		||||
      artifactGraph
 | 
			
		||||
    )
 | 
			
		||||
    Object.setPrototypeOf(this, KCLUnimplementedError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -110,9 +160,17 @@ export class KCLUnexpectedError extends KCLError {
 | 
			
		||||
    msg: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super('unexpected', msg, sourceRange, operations, artifactCommands)
 | 
			
		||||
    super(
 | 
			
		||||
      'unexpected',
 | 
			
		||||
      msg,
 | 
			
		||||
      sourceRange,
 | 
			
		||||
      operations,
 | 
			
		||||
      artifactCommands,
 | 
			
		||||
      artifactGraph
 | 
			
		||||
    )
 | 
			
		||||
    Object.setPrototypeOf(this, KCLUnexpectedError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -122,14 +180,16 @@ export class KCLValueAlreadyDefined extends KCLError {
 | 
			
		||||
    key: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super(
 | 
			
		||||
      'name',
 | 
			
		||||
      `Key ${key} was already defined elsewhere`,
 | 
			
		||||
      sourceRange,
 | 
			
		||||
      operations,
 | 
			
		||||
      artifactCommands
 | 
			
		||||
      artifactCommands,
 | 
			
		||||
      artifactGraph
 | 
			
		||||
    )
 | 
			
		||||
    Object.setPrototypeOf(this, KCLValueAlreadyDefined.prototype)
 | 
			
		||||
  }
 | 
			
		||||
@ -140,14 +200,16 @@ export class KCLUndefinedValueError extends KCLError {
 | 
			
		||||
    key: string,
 | 
			
		||||
    sourceRange: SourceRange,
 | 
			
		||||
    operations: Operation[],
 | 
			
		||||
    artifactCommands: ArtifactCommand[]
 | 
			
		||||
    artifactCommands: ArtifactCommand[],
 | 
			
		||||
    artifactGraph: ArtifactGraph
 | 
			
		||||
  ) {
 | 
			
		||||
    super(
 | 
			
		||||
      'name',
 | 
			
		||||
      `Key ${key} has not been defined`,
 | 
			
		||||
      sourceRange,
 | 
			
		||||
      operations,
 | 
			
		||||
      artifactCommands
 | 
			
		||||
      artifactCommands,
 | 
			
		||||
      artifactGraph
 | 
			
		||||
    )
 | 
			
		||||
    Object.setPrototypeOf(this, KCLUndefinedValueError.prototype)
 | 
			
		||||
  }
 | 
			
		||||
@ -167,9 +229,10 @@ export function lspDiagnosticsToKclErrors(
 | 
			
		||||
        new KCLError(
 | 
			
		||||
          'unexpected',
 | 
			
		||||
          message,
 | 
			
		||||
          [posToOffset(doc, range.start)!, posToOffset(doc, range.end)!, true],
 | 
			
		||||
          [posToOffset(doc, range.start)!, posToOffset(doc, range.end)!, 0],
 | 
			
		||||
          [],
 | 
			
		||||
          []
 | 
			
		||||
          [],
 | 
			
		||||
          defaultArtifactGraph()
 | 
			
		||||
        )
 | 
			
		||||
    )
 | 
			
		||||
    .sort((a, b) => {
 | 
			
		||||
@ -193,7 +256,7 @@ export function kclErrorsToDiagnostics(
 | 
			
		||||
  errors: KCLError[]
 | 
			
		||||
): CodeMirrorDiagnostic[] {
 | 
			
		||||
  return errors
 | 
			
		||||
    ?.filter((err) => err.sourceRange[2])
 | 
			
		||||
    ?.filter((err) => isTopLevelModule(err.sourceRange))
 | 
			
		||||
    .map((err) => {
 | 
			
		||||
      return {
 | 
			
		||||
        from: err.sourceRange[0],
 | 
			
		||||
@ -208,7 +271,7 @@ export function complilationErrorsToDiagnostics(
 | 
			
		||||
  errors: CompilationError[]
 | 
			
		||||
): CodeMirrorDiagnostic[] {
 | 
			
		||||
  return errors
 | 
			
		||||
    ?.filter((err) => err.sourceRange[2] === 0)
 | 
			
		||||
    ?.filter((err) => isTopLevelModule(err.sourceRange))
 | 
			
		||||
    .map((err) => {
 | 
			
		||||
      let severity: any = 'error'
 | 
			
		||||
      if (err.severity === 'Warning') {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user