fix display console.log args when navigating logs view

This commit is contained in:
Dmitry Vasilev
2023-06-10 23:03:17 +03:00
parent 1a23d3eefc
commit 05a43b617f
4 changed files with 48 additions and 33 deletions

View File

@@ -713,8 +713,11 @@ const select_return_value = state => {
selection_state: {
node,
initial_is_expand: true,
},
value_explorer: {
index: node.index + node.length,
result: result_node.result,
}
},
},
effects: {type: 'set_focus'}
}
@@ -755,8 +758,11 @@ const select_arguments = (state, with_focus = true) => {
selection_state: {
node,
initial_is_expand: true,
},
value_explorer: {
index: node.index + node.length,
result,
}
},
},
effects: with_focus
? {type: 'set_focus'}

View File

@@ -453,16 +453,18 @@ const get_next_selection_state = (selection_state, frame, is_expand, index) => {
export const selection = (selection_state, frame, is_expand, index) => {
const leaf = find_leaf(frame, index)
if(leaf == null) {
return {
ok: false,
message: 'out of scope',
return {
selection_state: {
ok: false,
message: 'out of scope',
}
}
}
const next_selection_state = get_next_selection_state(selection_state, frame, is_expand, index)
if(!next_selection_state.ok) {
return next_selection_state
return {selection_state: next_selection_state}
}
const {ok, message} = can_evaluate_node(frame, next_selection_state.node)
@@ -470,9 +472,11 @@ export const selection = (selection_state, frame, is_expand, index) => {
const node = find_node(frame, n => is_eq(n, next_selection_state.node))
if(node.result == null) {
return {
...next_selection_state,
ok: false,
message: 'expression was not reached during program execution',
selection_state: {
...next_selection_state,
ok: false,
message: 'expression was not reached during program execution',
}
}
} else {
let result
@@ -482,10 +486,15 @@ export const selection = (selection_state, frame, is_expand, index) => {
const error_node = find_error_origin_node(node)
result = error_node.result
}
return {...next_selection_state, ok: true, result}
return {
selection_state: {...next_selection_state, ok: true},
result
}
}
} else {
return {...next_selection_state, ok: false, message}
return {
selection_state: {...next_selection_state, ok: false, message}
}
}
}
@@ -495,14 +504,22 @@ const eval_selection = (state, index, is_expand) => {
return validate_result
}
const selection_state = selection(
const {selection_state, result} = selection(
state.selection_state,
active_frame(state),
is_expand,
index
)
const nextstate = {...state, selection_state}
const nextstate = {...state,
selection_state,
value_explorer: selection_state.ok
? {
index: selection_state.node.index + selection_state.node.length,
result,
}
: null
}
if(!selection_state.ok) {
return {state: nextstate, effects: {type: 'set_status', args: [selection_state.message]}}

8
src/effects.js vendored
View File

@@ -278,14 +278,6 @@ export const render_common_side_effects = (prev, next, command, ui) => {
}
}
const selresult = next.selection_state?.result
if(selresult != null && prev.selection_state?.result != selresult) {
const node = next.selection_state.node
ui.editor.embed_value_explorer({
index: node.index + node.length,
result: next.selection_state.result,
})
}
// Value explorer
if(prev.value_explorer != next.value_explorer) {

View File

@@ -1952,15 +1952,15 @@ const y = x()`
`
const s0 = test_initial_state(code)
const s1 = COMMANDS.eval_selection(s0, code.indexOf('2'), true).state
assert_equal(s1.selection_state.result.value, 2)
assert_equal(s1.value_explorer.result.value, 2)
// Expand selection
const s2 = COMMANDS.eval_selection(s1, code.indexOf('2'), true).state
assert_equal(s2.selection_state.result.value, 4)
assert_equal(s2.value_explorer.result.value, 4)
const s3 = COMMANDS.eval_selection(s2, code.indexOf('2'), true).state
// Selection is not expanded beyond expression to statement
assert_equal(s3.selection_state.result.value, 4)
assert_equal(s3.value_explorer.result.value, 4)
assert_equal(s3.selection_state.node.index, code.indexOf('2'))
assert_equal(s3.selection_state.node.length, 3)
@@ -2101,7 +2101,7 @@ const y = x()`
const s1 = test_initial_state(code)
const s2 = COMMANDS.calltree.arrow_right(s1)
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
assert_equal(s3.selection_state.result.value, 1)
assert_equal(s3.value_explorer.result.value, 1)
assert_equal(s3.selection_state.node.index, code.indexOf('x()'))
assert_equal(current_cursor_position(s3), code.indexOf('x()'))
assert_equal(effects, {type: 'set_focus'})
@@ -2117,7 +2117,7 @@ const y = x()`
// Expand
const s2 = COMMANDS.calltree.arrow_right(s2_0)
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
assert_equal(s3.selection_state.result.value, 1)
assert_equal(s3.value_explorer.result.value, 1)
assert_equal(s3.selection_state.node.index, code.indexOf('1'))
assert_equal(current_cursor_position(s3), code.indexOf('1'))
assert_equal(effects, {type: 'set_focus'})
@@ -2133,7 +2133,7 @@ const y = x()`
// Expand
const s2 = COMMANDS.calltree.arrow_right(s2_0)
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
assert_equal(s3.selection_state.result.value, 1)
assert_equal(s3.value_explorer.result.value, 1)
assert_equal(s3.selection_state.node.index, code.indexOf('1'))
assert_equal(current_cursor_position(s3), code.indexOf('1'))
assert_equal(effects, {type: 'set_focus'})
@@ -2162,7 +2162,7 @@ const y = x()`
// Select map
const s2 = COMMANDS.calltree.arrow_right(s1)
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
assert_equal(s3.selection_state.result.value, [1, 1, 1])
assert_equal(s3.value_explorer.result.value, [1, 1, 1])
}),
test('select_return_value new call', () => {
@@ -2170,7 +2170,7 @@ const y = x()`
const s1 = test_initial_state(code)
const s2 = COMMANDS.calltree.arrow_right(s1)
const {state: s3, effects} = COMMANDS.calltree.select_return_value(s2)
assert_equal(s3.selection_state.result.value, '1')
assert_equal(s3.value_explorer.result.value, '1')
}),
test('select_arguments not_expanded', () => {
@@ -2182,7 +2182,7 @@ const y = x()`
// focus call
const s2 = COMMANDS.calltree.arrow_right(s1)
const s3 = COMMANDS.calltree.select_arguments(s2)
assert_equal(s3.state.selection_state.result, {ok: true, value: [1]})
assert_equal(s3.state.value_explorer.result, {ok: true, value: [1]})
assert_equal(current_cursor_position(s3.state), code.indexOf('(1)'))
assert_equal(s3.effects, {type: 'set_focus'})
}),
@@ -2198,7 +2198,7 @@ const y = x()`
// expand call
const s2 = COMMANDS.calltree.arrow_right(s2_0)
const s3 = COMMANDS.calltree.select_arguments(s2)
assert_equal(s3.state.selection_state.result, {ok: true, value: {a: 1}})
assert_equal(s3.state.value_explorer.result, {ok: true, value: {a: 1}})
assert_equal(current_cursor_position(s3.state), code.indexOf('(a)'))
assert_equal(s3.effects, {type: 'set_focus'})
}),
@@ -2208,7 +2208,7 @@ const y = x()`
const s1 = test_initial_state(code)
const s2 = COMMANDS.calltree.arrow_right(s1)
const s3 = COMMANDS.calltree.select_arguments(s2).state
assert_equal(s3.selection_state.result, {ok: true, value: ["1"]})
assert_equal(s3.value_explorer.result, {ok: true, value: ["1"]})
}),
test('move_cursor arguments', () => {
@@ -2567,7 +2567,7 @@ const y = x()`
assert_equal(i.logs.logs[0].args, [10])
const state = COMMANDS.calltree.navigate_logs_position(i, 0)
assert_equal(state.logs.log_position, 0)
assert_equal(state.selection_state.result.value, [10])
assert_equal(state.value_explorer.result.value, [10])
assert_equal(current_cursor_position(state), code.indexOf('(x)'))
}),