refactor async_calls WIP

This commit is contained in:
Dmitry Vasilev
2022-11-16 12:33:32 +08:00
parent 4eeed74c45
commit 4f1f6c2f7e
2 changed files with 20 additions and 19 deletions

View File

@@ -13,18 +13,6 @@ export const pp_calltree = tree => ({
children: tree.children && tree.children.map(pp_calltree) children: tree.children && tree.children.map(pp_calltree)
}) })
const find_calltree_node = (state, id) => {
return find_node(
{
children: [
root_calltree_node(state),
{children: state.async_calls},
]
},
n => n.id == id
)
}
const is_stackoverflow = node => const is_stackoverflow = node =>
// Chrome // Chrome
node.error.message == 'Maximum call stack size exceeded' node.error.message == 'Maximum call stack size exceeded'
@@ -36,6 +24,8 @@ export const calltree_node_loc = node => node.toplevel
? {module: node.module} ? {module: node.module}
: node.fn.__location : node.fn.__location
export const get_async_calls = state => state.calltree.children[1].children
export const root_calltree_node = state => export const root_calltree_node = state =>
// Returns calltree node for toplevel // Returns calltree node for toplevel
// It is either toplevel for entrypoint module, or for module that throw // It is either toplevel for entrypoint module, or for module that throw
@@ -46,6 +36,14 @@ export const root_calltree_node = state =>
export const root_calltree_module = state => export const root_calltree_module = state =>
root_calltree_node(state).module root_calltree_node(state).module
export const make_calltree = (root_calltree_node, async_calls) => ({
id: 'calltree',
children: [
root_calltree_node,
{id: 'async_calls', children: async_calls},
]
})
export const is_native_fn = calltree_node => export const is_native_fn = calltree_node =>
!calltree_node.toplevel && calltree_node.fn.__location == null !calltree_node.toplevel && calltree_node.fn.__location == null
@@ -463,7 +461,7 @@ export const toggle_expanded = (state, is_exp) => {
} }
const click = (state, id) => { const click = (state, id) => {
const node = find_calltree_node(state, id) const node = find_node(state.calltree, n => n.id == id)
const {state: nextstate, effects} = jump_calltree_node(state, node) const {state: nextstate, effects} = jump_calltree_node(state, node)
if(is_expandable(node)) { if(is_expandable(node)) {
// `effects` are intentionally discarded, correct `set_caret_position` will // `effects` are intentionally discarded, correct `set_caret_position` will
@@ -811,9 +809,8 @@ const navigate_logs_increment = (state, increment) => {
} }
const navigate_logs_position = (state, log_position) => { const navigate_logs_position = (state, log_position) => {
const node = find_calltree_node( const node = find_node(state.calltree, n =>
state, n.id == state.logs.logs[log_position].id
state.logs.logs[log_position].id
) )
const {state: next, effects} = select_arguments( const {state: next, effects} = select_arguments(
expand_path(jump_calltree_node(state, node).state, node), expand_path(jump_calltree_node(state, node).state, node),

View File

@@ -9,7 +9,9 @@ import {load_modules} from './parse_js.js'
import {find_export} from './find_definitions.js' import {find_export} from './find_definitions.js'
import {eval_modules} from './eval.js' import {eval_modules} from './eval.js'
import { import {
root_calltree_node, root_calltree_module, calltree_commands, root_calltree_node, root_calltree_module, make_calltree,
get_async_calls,
calltree_commands,
add_frame, calltree_node_loc, expand_path, add_frame, calltree_node_loc, expand_path,
initial_calltree_node, default_expand_path, toggle_expanded, active_frame, initial_calltree_node, default_expand_path, toggle_expanded, active_frame,
find_call, find_call_node, set_active_calltree_node find_call, find_call_node, set_active_calltree_node
@@ -69,7 +71,6 @@ const run_code = (s, index, dirty_files) => {
parse_result, parse_result,
calltree: null, calltree: null,
modules: null, modules: null,
async_calls: null,
// Shows that calltree is brand new and requires entire rerender // Shows that calltree is brand new and requires entire rerender
calltree_changed_token: {}, calltree_changed_token: {},
@@ -736,7 +737,10 @@ const move_cursor = (s, index) => {
const on_async_call = (state, call) => { const on_async_call = (state, call) => {
return {...state, return {...state,
async_calls: [...(state.async_calls ?? []), call], calltree: make_calltree(
root_calltree_node(state),
[...(get_async_calls(state) ?? []), call],
),
logs: {...state.logs, logs: state.logs.logs.concat(collect_logs(call))}, logs: {...state.logs, logs: state.logs.logs.concat(collect_logs(call))},
} }
} }