mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
visually select function call when navigate calltree
This commit is contained in:
@@ -245,9 +245,18 @@ const jump_calltree_node = (_state, _current_calltree_node) => {
|
||||
|
||||
const next = add_frame(state, active_calltree_node, current_calltree_node)
|
||||
|
||||
const loc = show_body
|
||||
? calltree_node_loc(next.active_calltree_node)
|
||||
: find_callsite(next.modules, active_calltree_node, current_calltree_node)
|
||||
let loc, callsite_node
|
||||
|
||||
if(show_body) {
|
||||
loc = calltree_node_loc(next.active_calltree_node)
|
||||
} else {
|
||||
const frame = eval_frame(active_calltree_node, next.modules)
|
||||
callsite_node = find_node(frame, n => n.result?.call == current_calltree_node)
|
||||
loc = {
|
||||
module: calltree_node_loc(active_calltree_node).module,
|
||||
index: callsite_node.index
|
||||
}
|
||||
}
|
||||
|
||||
const with_location = next.current_calltree_node.toplevel
|
||||
? {...next, current_module: loc.module}
|
||||
@@ -272,7 +281,11 @@ const jump_calltree_node = (_state, _current_calltree_node) => {
|
||||
'*throws*': current_calltree_node.error,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
selection_state: show_body
|
||||
? null
|
||||
: {node: callsite_node}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,11 +462,6 @@ const arrow_right = state => {
|
||||
}
|
||||
}
|
||||
|
||||
const find_callsite = (modules, parent, node) => {
|
||||
const frame = eval_frame(parent, modules)
|
||||
const result = find_node(frame, n => n.result?.call == node)
|
||||
return {module: calltree_node_loc(parent).module, index: result.index}
|
||||
}
|
||||
|
||||
export const toggle_expanded = (state, is_exp) => {
|
||||
const node_id = state.current_calltree_node.id
|
||||
@@ -712,7 +720,6 @@ const select_return_value = state => {
|
||||
...set_location(state, {module: loc.module, index: node.index}),
|
||||
selection_state: {
|
||||
node,
|
||||
initial_is_expand: true,
|
||||
},
|
||||
value_explorer: {
|
||||
index: node.index + node.length,
|
||||
@@ -757,7 +764,6 @@ const select_arguments = (state, with_focus = true) => {
|
||||
...set_location(state, {module: loc.module, index: node.index}),
|
||||
selection_state: {
|
||||
node,
|
||||
initial_is_expand: true,
|
||||
},
|
||||
value_explorer: {
|
||||
index: node.index + node.length,
|
||||
|
||||
12
test/test.js
12
test/test.js
@@ -1861,6 +1861,18 @@ const y = x()`
|
||||
|
||||
}),
|
||||
|
||||
test('jump_calltree select callsite', () => {
|
||||
const code = `
|
||||
function x(y) {}
|
||||
x()
|
||||
`
|
||||
const i = test_initial_state(code)
|
||||
const call_selected = COMMANDS.calltree.arrow_right(i)
|
||||
const node = call_selected.selection_state.node
|
||||
assert_equal(node.index, code.indexOf('x()'))
|
||||
assert_equal(node.length, 'x()'.length)
|
||||
}),
|
||||
|
||||
// Test very specific case
|
||||
test('jump_calltree_location after error', () => {
|
||||
const code = `
|
||||
|
||||
Reference in New Issue
Block a user