run with find_call

This commit is contained in:
Dmitry Vasilev
2022-12-29 20:13:15 +08:00
parent cbda099c7f
commit e577301215
2 changed files with 46 additions and 8 deletions

View File

@@ -359,6 +359,33 @@ export const eval_modules = (
}
}
const run_and_find_call = (location) => {
searched_location = location
const run_result = run()
const after_run = ({calltree, modules, logs}) => {
searched_location = null
const call = found_call
found_call = null
return {
calltree,
modules,
logs,
call,
}
}
// Support to paths, one for async 'run', and one for sync, to avoid
// refactoring code (mostly test code) to always async
if(run_result instanceof Promise) {
return run_result.then(after_run)
} else {
return after_run(run_result)
}
}
const find_call = (location, deferred_calls) => {
searched_location = location
let is_found_deferred_call = false
@@ -667,6 +694,7 @@ export const eval_modules = (
return {
run,
run_and_find_call,
expand_calltree_node,
find_call,
}
@@ -725,7 +753,7 @@ export const eval_modules = (
const result = location == null
? actions.run()
: calltree_actions.find_call(location)
: actions.run_and_find_call(location)
const make_result = result => ({
modules: result.modules,

View File

@@ -2858,19 +2858,29 @@ const y = x()`
)
}),
/*
// TODO
test('async/await move_cursor', async () => {
test('async/await edit', async () => {
const code = `
const f = async () => {
console.log('f')
}
}
await f()
`
const i = await test_initial_state_async(code)
const cursor = COMMANDS.move_cursor(i, code.indexOf('console'))
const code2 = `
const f = async () => {
1
}
await f()
`
const {state: after_edit} = COMMANDS.input(i, code2, code2.indexOf('1'))
const result = await after_edit.eval_modules_state.promise
const after_edit_finished = COMMANDS.eval_modules_finished(
after_edit,
result,
after_edit.eval_modules_state.node,
after_edit.eval_modules_state.toplevel
)
assert_equal(after_edit_finished.active_calltree_node.fn.name, 'f')
}),
*/
]