Fix executeAstMock to be more lenient

This commit is contained in:
Jonathan Tran
2024-08-01 13:25:54 -04:00
parent 2ff1d1167f
commit 92b3f6192d

View File

@ -15,7 +15,11 @@ import {
recast, recast,
SourceRange, SourceRange,
} from 'lang/wasm' } from 'lang/wasm'
import { expectNodeOnPath, getLastNodeFromPath } from './queryAst' import {
expectNodeOnPath,
getLastNodeFromPath,
getNodeFromPath,
} from './queryAst'
import { codeManager, editorManager, sceneInfra } from 'lib/singletons' import { codeManager, editorManager, sceneInfra } from 'lib/singletons'
import { Diagnostic } from '@codemirror/lint' import { Diagnostic } from '@codemirror/lint'
@ -315,12 +319,14 @@ export class KclManager {
Object.entries(this.engineCommandManager.artifactMap).forEach( Object.entries(this.engineCommandManager.artifactMap).forEach(
([commandId, artifact]) => { ([commandId, artifact]) => {
if (!artifact.pathToNode) return if (!artifact.pathToNode) return
const node = expectNodeOnPath<CallExpression>( const _node = getNodeFromPath<CallExpression>(
this.ast, this.ast,
artifact.pathToNode, artifact.pathToNode,
'CallExpression' 'CallExpression'
) )
if (err(node)) return if (err(_node)) return
const { node } = _node
if (isArray(node) || node.type !== 'CallExpression') return
const [oldStart, oldEnd] = artifact.range const [oldStart, oldEnd] = artifact.range
if (oldStart === 0 && oldEnd === 0) return if (oldStart === 0 && oldEnd === 0) return
if (oldStart === node.start && oldEnd === node.end) return if (oldStart === node.start && oldEnd === node.end) return