mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
value_explorer state property
This commit is contained in:
@@ -234,31 +234,29 @@ const jump_calltree_node = (_state, _current_calltree_node) => {
|
||||
? calltree_node_loc(next.active_calltree_node)
|
||||
: find_callsite(next.modules, active_calltree_node, current_calltree_node)
|
||||
|
||||
return {
|
||||
state: next.current_calltree_node.toplevel
|
||||
? {...next, current_module: loc.module}
|
||||
// TODO: better jump not start of function (arguments), but start
|
||||
// of body?
|
||||
: set_location(next, loc),
|
||||
effects: next.current_calltree_node.toplevel
|
||||
? {type: 'unembed_value_explorer'}
|
||||
const with_location = next.current_calltree_node.toplevel
|
||||
? {...next, current_module: loc.module}
|
||||
// TODO: better jump not start of function (arguments), but start
|
||||
// of body?
|
||||
: set_location(next, loc)
|
||||
|
||||
return {...with_location,
|
||||
value_explorer: next.current_calltree_node.toplevel
|
||||
? null
|
||||
: {
|
||||
type: 'embed_value_explorer',
|
||||
args: [{
|
||||
index: loc.index,
|
||||
result: {
|
||||
ok: true,
|
||||
value: current_calltree_node.ok
|
||||
? {
|
||||
'*arguments*': current_calltree_node.args,
|
||||
'*return*': current_calltree_node.value,
|
||||
}
|
||||
: {
|
||||
'*arguments*': current_calltree_node.args,
|
||||
'*throws*': current_calltree_node.error,
|
||||
}
|
||||
}
|
||||
}],
|
||||
index: loc.index,
|
||||
result: {
|
||||
ok: true,
|
||||
value: current_calltree_node.ok
|
||||
? {
|
||||
'*arguments*': current_calltree_node.args,
|
||||
'*return*': current_calltree_node.value,
|
||||
}
|
||||
: {
|
||||
'*arguments*': current_calltree_node.args,
|
||||
'*throws*': current_calltree_node.error,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -458,13 +456,11 @@ export const toggle_expanded = (state, is_exp) => {
|
||||
|
||||
const click = (state, id) => {
|
||||
const node = find_node(state.calltree, n => n.id == id)
|
||||
const {state: nextstate, effects} = jump_calltree_node(state, node)
|
||||
const nextstate = jump_calltree_node(state, node)
|
||||
if(is_expandable(node)) {
|
||||
// `effects` are intentionally discarded, correct `set_cursor_position` will
|
||||
// be applied in `toggle_expanded`
|
||||
return toggle_expanded(nextstate)
|
||||
} else {
|
||||
return {state: nextstate, effects}
|
||||
return nextstate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -761,13 +757,13 @@ const navigate_logs_position = (state, log_position) => {
|
||||
n.id == state.logs.logs[log_position].id
|
||||
)
|
||||
const {state: next, effects} = select_arguments(
|
||||
expand_path(jump_calltree_node(state, node).state, node),
|
||||
expand_path(jump_calltree_node(state, node), node),
|
||||
false,
|
||||
)
|
||||
return {
|
||||
state: {...next, logs: {...state.logs, log_position}},
|
||||
effects,
|
||||
if(effects != null) {
|
||||
throw new Error('illegal state')
|
||||
}
|
||||
return {...next, logs: {...state.logs, log_position}}
|
||||
}
|
||||
|
||||
export const calltree_commands = {
|
||||
|
||||
38
src/cmd.js
38
src/cmd.js
@@ -93,6 +93,7 @@ const run_code = (s, dirty_files) => {
|
||||
calltree_node_by_loc: null,
|
||||
selection_state: null,
|
||||
loading_external_imports_state: null,
|
||||
value_explorer: null,
|
||||
}
|
||||
|
||||
if(!state.parse_result.ok) {
|
||||
@@ -284,10 +285,9 @@ const input = (state, code, index) => {
|
||||
if(next.loading_external_imports_state != null) {
|
||||
return {state: next, effects: [effect_save]}
|
||||
}
|
||||
const {state: next2, effects: effects2} = do_move_cursor(next, index)
|
||||
return {
|
||||
state: next2,
|
||||
effects: [effect_save, effects2],
|
||||
state: do_move_cursor(next, index),
|
||||
effects: [effect_save],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,7 +594,15 @@ const filter_calltree = (calltree, pred) => {
|
||||
*/
|
||||
|
||||
const get_value_explorer = (state, index) => {
|
||||
if(state.active_calltree_node == null) {
|
||||
if(
|
||||
state.active_calltree_node == null
|
||||
||
|
||||
(
|
||||
state.current_module
|
||||
!=
|
||||
calltree_node_loc(state.active_calltree_node).module
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -716,22 +724,7 @@ const get_value_explorer = (state, index) => {
|
||||
}
|
||||
|
||||
const do_move_cursor = (state, index) => {
|
||||
const value_exp = get_value_explorer(state, index)
|
||||
if(value_exp == null) {
|
||||
return {
|
||||
state,
|
||||
effects: {type: 'unembed_value_explorer', args: []}
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
state,
|
||||
effects:
|
||||
state.current_module ==
|
||||
calltree_node_loc(state.active_calltree_node).module
|
||||
? {type: 'embed_value_explorer', args: [value_exp]}
|
||||
: null
|
||||
}
|
||||
}
|
||||
return { ...state, value_explorer: get_value_explorer(state, index) }
|
||||
}
|
||||
|
||||
const move_cursor = (s, index) => {
|
||||
@@ -754,10 +747,7 @@ const move_cursor = (s, index) => {
|
||||
|
||||
const validate_result = validate_index_action(state)
|
||||
if(validate_result != null) {
|
||||
return {
|
||||
state,
|
||||
effects: {type: 'unembed_value_explorer', args: []}
|
||||
}
|
||||
return { ...state, value_explorer: null }
|
||||
}
|
||||
|
||||
return do_move_cursor(state, index)
|
||||
|
||||
28
src/effects.js
vendored
28
src/effects.js
vendored
@@ -206,7 +206,6 @@ export const render_common_side_effects = async (prev, next, command, ui) => {
|
||||
// TODO if loading external imports, show loading indicator
|
||||
ui.calltree.clear_calltree()
|
||||
ui.editor.for_each_session((file, session) => clear_coloring(ui, file))
|
||||
ui.editor.unembed_value_explorer()
|
||||
|
||||
} else {
|
||||
|
||||
@@ -220,7 +219,6 @@ export const render_common_side_effects = async (prev, next, command, ui) => {
|
||||
ui.eval.clear_value_or_error()
|
||||
ui.editor.for_each_session(f => clear_coloring(ui, f))
|
||||
render_coloring(ui, next)
|
||||
ui.editor.unembed_value_explorer()
|
||||
ui.logs.rerender_logs(next.logs)
|
||||
} else {
|
||||
|
||||
@@ -287,6 +285,15 @@ export const render_common_side_effects = async (prev, next, command, ui) => {
|
||||
ui.eval.show_value_or_error(next.selection_state.result)
|
||||
}
|
||||
}
|
||||
|
||||
// Value explorer
|
||||
if(prev.value_explorer != next.value_explorer) {
|
||||
if(next.value_explorer == null) {
|
||||
ui.editor.unembed_value_explorer()
|
||||
} else {
|
||||
ui.editor.embed_value_explorer(next.value_explorer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -304,22 +311,5 @@ export const EFFECTS = {
|
||||
},
|
||||
|
||||
write: (state, [name, contents], ui) => write_file(name, contents),
|
||||
|
||||
embed_value_explorer(state, [{index, result}], ui){
|
||||
if(FLAGS.embed_value_explorer) {
|
||||
ui.editor.embed_value_explorer({index, result})
|
||||
} else {
|
||||
ui.eval.show_value_or_error(result)
|
||||
}
|
||||
},
|
||||
|
||||
unembed_value_explorer(state, _, ui){
|
||||
if(FLAGS.embed_value_explorer) {
|
||||
ui.editor.unembed_value_explorer()
|
||||
} else {
|
||||
ui.eval.clear_value_or_error()
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user