Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tracking of operations for the feature tree #4746

Merged
merged 31 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bd4815c
Add operations tracking for the timeline
jtran Dec 10, 2024
a8db932
Change to only track certain stdlib functions as operations
jtran Dec 11, 2024
1b0a9cb
Update gen files
jtran Dec 11, 2024
da27574
Add operations to simulation snapshot tests
jtran Dec 11, 2024
dcdbd24
Add tracking of positional function calls
jtran Dec 11, 2024
d00f965
Fix generated field names to be camel case in TS
jtran Dec 11, 2024
1f06e89
Fix generated TS field names to match and better docs
jtran Dec 11, 2024
c326079
Fix order of ops with patternTransform
jtran Dec 11, 2024
2643979
Fix sweep to be included
jtran Dec 12, 2024
2c4b972
Add new expected test outputs
jtran Dec 11, 2024
6bcbbce
Add tracking for startSketchOn
jtran Dec 12, 2024
135f0f0
Update ops output to include startSketchOn
jtran Dec 12, 2024
7edee33
Fix serde field name
jtran Dec 12, 2024
e0e439e
Fix output field name
jtran Dec 12, 2024
5774ff3
Add tracking of operations that fail
jtran Dec 12, 2024
64efe8b
Add snapshots of operations even when there's a KCL execution error
jtran Dec 12, 2024
8d1e6a9
Add ops output for error executions
jtran Dec 12, 2024
e1b4d81
Add operations output to executor error
jtran Dec 12, 2024
39e7b6e
Update op source ranges
jtran Dec 12, 2024
5f376cf
Merge branch 'main' into jtran/operations
franknoirot Dec 13, 2024
500d6e1
Remove tracking of circle() and polygon() since they're not needed
jtran Dec 13, 2024
916296d
Update output without circle and polygon
jtran Dec 13, 2024
78fb82d
Fix to track patternCircular3d and patternLinear3d
jtran Dec 13, 2024
542c9a9
Remove tracking for mirror2d
jtran Dec 13, 2024
8719c2a
Update ops output
jtran Dec 13, 2024
787e96a
Fix to track the correct source range of function definitions
jtran Dec 13, 2024
c923d78
Merge branch 'main' into jtran/operations
jtran Dec 13, 2024
be55a2d
Merge branch 'main' into jtran/operations
jtran Dec 13, 2024
80598ce
Merge branch 'main' into jtran/operations
jtran Dec 13, 2024
6aa5b16
Merge branch 'main' into jtran/operations
jtran Dec 13, 2024
a8aa2b7
Merge branch 'main' into jtran/operations
jtran Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lang/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ describe('test kclErrToDiagnostic', () => {
kind: 'semantic',
msg: 'Semantic error',
sourceRange: [0, 1, true],
operations: [],
},
{
name: '',
message: '',
kind: 'type',
msg: 'Type error',
sourceRange: [4, 5, true],
operations: [],
},
]
const diagnostics = kclErrorsToDiagnostics(errors)
Expand Down
58 changes: 34 additions & 24 deletions src/lang/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion src/lang/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ const theExtrude = startSketchOn('XY')
new KCLError(
'undefined_value',
'memory item key `myVarZ` is not defined',
[129, 135, true]
[129, 135, true],
[]
)
)
})
Expand Down
19 changes: 12 additions & 7 deletions src/lang/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Node } from 'wasm-lib/kcl/bindings/Node'
import { CompilationError } from 'wasm-lib/kcl/bindings/CompilationError'
import { SourceRange as RustSourceRange } from 'wasm-lib/kcl/bindings/SourceRange'
import { getAllCurrentSettings } from 'lib/settings/settingsUtils'
import { KclErrorWithOutputs } from 'wasm-lib/kcl/bindings/KclErrorWithOutputs'

export type { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
export type { Program } from '../wasm-lib/kcl/bindings/Program'
Expand Down Expand Up @@ -212,7 +213,8 @@ export const parse = (code: string | Error): ParseResult | Error => {
return new KCLError(
parsed.kind,
parsed.msg,
sourceRangeFromRust(parsed.sourceRanges[0])
sourceRangeFromRust(parsed.sourceRanges[0]),
[]
)
}
}
Expand Down Expand Up @@ -531,11 +533,12 @@ export const _executor = async (
return execStateFromRaw(execState)
} catch (e: any) {
console.log(e)
const parsed: RustKclError = JSON.parse(e.toString())
const parsed: KclErrorWithOutputs = JSON.parse(e.toString())
const kclError = new KCLError(
parsed.kind,
parsed.msg,
sourceRangeFromRust(parsed.sourceRanges[0])
parsed.error.kind,
parsed.error.msg,
sourceRangeFromRust(parsed.error.sourceRanges[0]),
parsed.operations
)

return Promise.reject(kclError)
Expand Down Expand Up @@ -594,7 +597,8 @@ export const modifyAstForSketch = async (
const kclError = new KCLError(
parsed.kind,
parsed.msg,
sourceRangeFromRust(parsed.sourceRanges[0])
sourceRangeFromRust(parsed.sourceRanges[0]),
[]
)

console.log(kclError)
Expand Down Expand Up @@ -662,7 +666,8 @@ export function programMemoryInit(): ProgramMemory | Error {
return new KCLError(
parsed.kind,
parsed.msg,
sourceRangeFromRust(parsed.sourceRanges[0])
sourceRangeFromRust(parsed.sourceRanges[0]),
[]
)
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/wasm-lib/derive-docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ struct StdlibMetadata {
#[serde(default)]
deprecated: bool,

/// Whether the function is displayed in the feature tree.
/// If true, calls to the function will be available for display.
/// If false, calls to the function will never be displayed.
#[serde(default)]
feature_tree_operation: bool,

/// If true, expects keyword arguments.
/// If false, expects positional arguments.
#[serde(default)]
Expand Down Expand Up @@ -238,6 +244,12 @@ fn do_stdlib_inner(
quote! { false }
};

let feature_tree_operation = if metadata.feature_tree_operation {
quote! { true }
} else {
quote! { false }
};

Comment on lines +253 to +258
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way did you wire up automatic documentation for whether a stdlib function will appear in the feature tree??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's a good idea though and probably wouldn't be hard.

This makes it so you can add this to the top of stdlib Rust functions that you want to track.

#[stdlib {
    name = "extrude",
    feature_tree_operation = true,
}]
async fn inner_extrude(
    length: f64,
    sketch_set: SketchSet,
    exec_state: &mut ExecState,
    args: Args,
) -> Result<SolidSet, KclError> {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh right that makes sense. Cool maybe in the future

let uses_keyword_arguments = if metadata.keywords {
quote! { true }
} else {
Expand Down Expand Up @@ -451,6 +463,10 @@ fn do_stdlib_inner(
#deprecated
}

fn feature_tree_operation(&self) -> bool {
#feature_tree_operation
}

fn examples(&self) -> Vec<String> {
#code_blocks
}
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/args_with_lifetime.gen
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ impl crate::docs::StdLibFn for SomeFn {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["someFn()"];
code_blocks
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/args_with_refs.gen
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ impl crate::docs::StdLibFn for SomeFn {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["someFn()"];
code_blocks
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/array.gen
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ impl crate::docs::StdLibFn for Show {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec![
"This is another code block.\nyes sirrr.\nshow",
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/box.gen
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl crate::docs::StdLibFn for Show {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["This is code.\nIt does other shit.\nshow"];
code_blocks
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/doc_comment_with_code.gen
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ impl crate::docs::StdLibFn for MyFunc {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec![
"This is another code block.\nyes sirrr.\nmyFunc",
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/lineTo.gen
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl crate::docs::StdLibFn for LineTo {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec![
"This is another code block.\nyes sirrr.\nlineTo",
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/min.gen
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ impl crate::docs::StdLibFn for Min {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec![
"This is another code block.\nyes sirrr.\nmin",
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/option.gen
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl crate::docs::StdLibFn for Show {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["This is code.\nIt does other shit.\nshow"];
code_blocks
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/option_input_format.gen
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl crate::docs::StdLibFn for Import {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["This is code.\nIt does other shit.\nimport"];
code_blocks
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/return_vec_box_sketch.gen
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl crate::docs::StdLibFn for Import {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["This is code.\nIt does other shit.\nimport"];
code_blocks
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/return_vec_sketch.gen
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl crate::docs::StdLibFn for Import {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["This is code.\nIt does other shit.\nimport"];
code_blocks
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/show.gen
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl crate::docs::StdLibFn for Show {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["This is code.\nIt does other shit.\nshow"];
code_blocks
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/derive-docs/tests/test_args_with_exec_state.gen
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ impl crate::docs::StdLibFn for SomeFunction {
false
}

fn feature_tree_operation(&self) -> bool {
false
}

fn examples(&self) -> Vec<String> {
let code_blocks = vec!["someFunction()"];
code_blocks
Expand Down
Loading
Loading