mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
logs in async calls
This commit is contained in:
@@ -838,9 +838,9 @@ const navigate_logs_increment = (state, increment) => {
|
||||
}
|
||||
|
||||
const navigate_logs_position = (state, log_position) => {
|
||||
const node = find_node(
|
||||
root_calltree_node(state),
|
||||
n => n.id == state.logs.logs[log_position].id
|
||||
const node = find_calltree_node(
|
||||
state,
|
||||
state.logs.logs[log_position].id
|
||||
)
|
||||
const {state: next, effects} = select_arguments(
|
||||
expand_path(jump_calltree_node(state, node).state, node),
|
||||
|
||||
43
src/cmd.js
43
src/cmd.js
@@ -15,29 +15,27 @@ import {
|
||||
find_call, find_call_node, set_active_calltree_node
|
||||
} from './calltree.js'
|
||||
|
||||
const collect_logs = call =>
|
||||
collect_nodes_with_parents(call, n => n.is_log)
|
||||
.map(({parent, node}) => (
|
||||
{
|
||||
id: node.id,
|
||||
toplevel: parent.toplevel,
|
||||
module: parent.toplevel
|
||||
? parent.module
|
||||
: parent.fn.__location.module,
|
||||
parent_name: parent.fn?.name,
|
||||
args: node.args,
|
||||
log_fn_name: node.fn.name,
|
||||
}
|
||||
))
|
||||
|
||||
const apply_eval_result = (state, eval_result) => {
|
||||
// TODO what if console.log called from native fn (like Array::map)?
|
||||
// Currently it is not recorded. Maybe we should patch monkey patch console?
|
||||
const logs = (
|
||||
eval_result.calltree[state.entrypoint] == null
|
||||
? []
|
||||
: collect_nodes_with_parents(
|
||||
eval_result.calltree[state.entrypoint].calls,
|
||||
n => n.is_log,
|
||||
)
|
||||
)
|
||||
.map(({parent, node}) => (
|
||||
{
|
||||
id: node.id,
|
||||
toplevel: parent.toplevel,
|
||||
module: parent.toplevel
|
||||
? parent.module
|
||||
: parent.fn.__location.module,
|
||||
parent_name: parent.fn?.name,
|
||||
args: node.args,
|
||||
log_fn_name: node.fn.name,
|
||||
}
|
||||
))
|
||||
// Currently it is not recorded. Maybe we should monkey patch `console`?
|
||||
const logs = collect_logs(
|
||||
root_calltree_node({...state, calltree: eval_result.calltree})
|
||||
)
|
||||
|
||||
return {
|
||||
...state,
|
||||
@@ -740,7 +738,8 @@ const move_cursor = (s, index) => {
|
||||
|
||||
const on_async_call = (state, call) => {
|
||||
return {...state,
|
||||
async_calls: [...(state.async_calls ?? []), call]
|
||||
async_calls: [...(state.async_calls ?? []), call],
|
||||
logs: {...state.logs, logs: state.logs.logs.concat(collect_logs(call))},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2314,6 +2314,7 @@ const y = x()`
|
||||
}
|
||||
|
||||
const fn2 = () => {
|
||||
console.log(1)
|
||||
}
|
||||
|
||||
// Use Function constructor to exec impure code for testing
|
||||
@@ -2341,6 +2342,8 @@ const y = x()`
|
||||
const state = COMMANDS.on_async_call(i, call)
|
||||
assert_equal(state.async_calls, [call])
|
||||
|
||||
assert_equal(state.logs.logs.length, 1)
|
||||
|
||||
// Expand call
|
||||
const {state: expanded} = COMMANDS.calltree.click(state, call.id)
|
||||
assert_equal(expanded.async_calls[0].children[0].fn.name, 'fn2')
|
||||
|
||||
Reference in New Issue
Block a user