mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -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 next = add_frame(state, active_calltree_node, current_calltree_node)
|
||||||
|
|
||||||
const loc = show_body
|
let loc, callsite_node
|
||||||
? calltree_node_loc(next.active_calltree_node)
|
|
||||||
: find_callsite(next.modules, active_calltree_node, current_calltree_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
|
const with_location = next.current_calltree_node.toplevel
|
||||||
? {...next, current_module: loc.module}
|
? {...next, current_module: loc.module}
|
||||||
@@ -272,7 +281,11 @@ const jump_calltree_node = (_state, _current_calltree_node) => {
|
|||||||
'*throws*': current_calltree_node.error,
|
'*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) => {
|
export const toggle_expanded = (state, is_exp) => {
|
||||||
const node_id = state.current_calltree_node.id
|
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}),
|
...set_location(state, {module: loc.module, index: node.index}),
|
||||||
selection_state: {
|
selection_state: {
|
||||||
node,
|
node,
|
||||||
initial_is_expand: true,
|
|
||||||
},
|
},
|
||||||
value_explorer: {
|
value_explorer: {
|
||||||
index: node.index + node.length,
|
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}),
|
...set_location(state, {module: loc.module, index: node.index}),
|
||||||
selection_state: {
|
selection_state: {
|
||||||
node,
|
node,
|
||||||
initial_is_expand: true,
|
|
||||||
},
|
},
|
||||||
value_explorer: {
|
value_explorer: {
|
||||||
index: node.index + node.length,
|
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 very specific case
|
||||||
test('jump_calltree_location after error', () => {
|
test('jump_calltree_location after error', () => {
|
||||||
const code = `
|
const code = `
|
||||||
|
|||||||
Reference in New Issue
Block a user